/* FamFolio – Stylesheet
   Idee: ein Familien-Ordner. Links der petrolfarbene Ordnerrücken mit Registerkarten
   pro Person, rechts das Blatt mit dem Kontobuch. */

@font-face { font-family: 'Plex'; src: url('fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex'; src: url('fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Plex'; src: url('fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }

:root {
  --paper: #EEF2F1;
  --card: #FFFFFF;
  --ink: #17232B;
  --muted: #5B6970;
  --rule: #D9E0DE;
  --petrol: #0E4A56;
  --petrol-deep: #0A3640;
  --saffron: #D99A1E;
  --slate: #5B74A6;
  --sage: #7F9F7B;
  --plum: #8A5A83;
  --teal: #3B8C8A;
  --sand: #C2AD85;
  --steel: #7B8894;
  --brick: #A9553F;
  --up: #1D7550;
  --down: #B3383A;
  --font-ui: 'Plex', 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 6px;
  --rail-w: 244px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 15px/1.5 var(--font-ui);
  font-variant-numeric: tabular-nums;
}
a { color: var(--petrol); text-underline-offset: 2px; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 16px; line-height: 1.3; margin-bottom: 14px; }
small { color: var(--muted); font-weight: 400; }
code, pre { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; }
:focus-visible { outline: 2px solid var(--saffron); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ Grundgerüst */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; }
.main { padding: 32px 40px 64px; max-width: 1320px; width: 100%; }
.solo { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.rail {
  background: var(--petrol); color: #DCE9EA; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 22px 0 18px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 16px 22px 4px; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: 0.01em; color: #fff; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 4px; flex: none;
  background: linear-gradient(90deg, var(--saffron) 0 30%, transparent 30% 40%, #fff 40% 100%);
  box-shadow: inset 0 0 0 2px var(--petrol-deep);
}
.brand-mark.big { width: 36px; height: 36px; margin-bottom: 18px; box-shadow: none; }
.rail-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
.rail-nav { flex: 1; overflow-y: auto; }

/* Registerkarten: die aktive Karte geht nahtlos ins Blatt über */
.tabs { display: flex; flex-direction: column; gap: 3px; margin-bottom: 26px; }
.tab {
  display: flex; align-items: center; gap: 12px; padding: 9px 14px; color: #DCE9EA; text-decoration: none;
  border-radius: 8px 0 0 8px; position: relative; transition: background-color .15s;
}
.tab:hover { background: rgba(255,255,255,.07); }
.tab-ini {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 12px; font-weight: 600; background: rgba(255,255,255,.12); color: #fff;
}
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.is-active { background: var(--paper); color: var(--ink); font-weight: 500; }
.tab.is-active .tab-ini { background: var(--saffron); color: var(--ink); }
.tab.is-active::before, .tab.is-active::after {
  content: ''; position: absolute; right: 0; width: 12px; height: 12px; background: transparent; pointer-events: none;
}
.tab.is-active::before { top: -12px; border-bottom-right-radius: 8px; box-shadow: 4px 4px 0 4px var(--paper); }
.tab.is-active::after { bottom: -12px; border-top-right-radius: 8px; box-shadow: 4px -4px 0 4px var(--paper); }
.tab-family .tab-ini { font-size: 15px; }

.rail-group { display: flex; flex-direction: column; padding-right: 16px; margin-bottom: 20px; }
.rail-head { font-size: 12px; color: #8FB2B6; padding: 0 14px 6px; }
.rail-link { color: #DCE9EA; text-decoration: none; padding: 7px 14px; border-radius: 5px; font-size: 14px; }
.rail-link:hover { background: rgba(255,255,255,.07); }
.rail-link.is-active { background: rgba(255,255,255,.12); color: #fff; }
.rail-foot { padding: 14px 16px 0 0; border-top: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; gap: 2px; }
.rail-foot .linklike { color: #B9D0D2; padding: 7px 14px; text-align: left; }

/* ------------------------------------------------------------ Seitenkopf */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head .sub { margin: 6px 0 0; color: var(--muted); max-width: 70ch; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.refresh-status { margin-left: 8px; color: var(--petrol); }

/* ------------------------------------------------------------ Hero */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; flex-wrap: wrap; padding: 4px 0 26px; }
.hero-figure { display: flex; flex-direction: column; gap: 4px; }
.hero-label { color: var(--muted); font-size: 14px; }
.hero-value { font-size: clamp(38px, 5.4vw, 60px); font-weight: 500; line-height: 1; letter-spacing: -0.035em; }
.hero-day { font-size: 15px; font-weight: 500; margin-top: 6px; }
.hero-day span { color: var(--muted); font-weight: 400; }
.hero-split { display: flex; gap: 0; margin: 0; }
.hero-split div { padding: 0 22px; border-left: 1px solid var(--rule); }
.hero-split dt { color: var(--muted); font-size: 13px; }
.hero-split dd { margin: 2px 0 0; font-size: 18px; font-weight: 500; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

/* ------------------------------------------------------------ Flächen */
.panel { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 22px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 22px; align-items: start; }
.two-col > .panel { margin-bottom: 0; }
.two-col + .panel, .two-col + .two-col { margin-top: 22px; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* Chart */
.chart-panel { padding-bottom: 16px; }
.chart-bar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--paper); border-radius: 6px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: none; font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 4px; color: var(--muted); cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button.is-on { background: var(--card); color: var(--ink); font-weight: 500; box-shadow: 0 0 0 1px var(--rule); }
.period-kpis { display: flex; gap: 32px; flex-wrap: wrap; margin-bottom: 10px; }
.period-kpis span { display: block; font-size: 13px; color: var(--muted); }
.period-kpis strong { font-size: 20px; font-weight: 500; }
.chart-wrap { position: relative; height: 340px; }
.chart-wrap.small { height: 220px; }
.chart-note { margin-top: 6px; }

/* KPI-Leiste: eine Zeile mit Trennlinien statt einzelner Kacheln */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin: 0 0 26px; }
.kpi { padding: 16px 18px; border-left: 1px solid var(--rule); display: flex; flex-direction: column; }
.kpi:first-child { border-left: 0; padding-left: 0; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi strong { font-size: 18px; font-weight: 500; margin-top: 2px; }
.kpi em { font-style: normal; font-size: 13px; color: var(--muted); }

/* Aufteilungen */
.alloc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 22px; margin-bottom: 22px; }
.alloc-grid .panel { margin: 0; }
.alloc-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.alloc-head h2 { margin: 0; }
.alloc-head select { width: auto; font: inherit; font-weight: 600; font-size: 16px; border: 0; border-bottom: 2px solid var(--saffron); background: none; color: var(--petrol); padding: 0 2px; cursor: pointer; }
.alloc-body { display: flex; gap: 26px; align-items: center; }
.alloc-body canvas { width: 168px !important; height: 168px !important; flex: none; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; }
.legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.legend li:last-child { border-bottom: 0; }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.legend .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .p { font-weight: 500; }
.legend .v { color: var(--muted); min-width: 84px; text-align: right; }
.legend-empty { color: var(--muted); }

/* ------------------------------------------------------------ Kontobuch-Tabellen */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
.ledger th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--ink); white-space: nowrap; }
.ledger td { padding: 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.ledger tbody tr:hover { background: #F6F8F7; }
.ledger .num { text-align: right; white-space: nowrap; }
.ledger .strong { font-weight: 600; }
.ledger.compact td { padding: 7px 10px; }
.ledger th[data-sort] { cursor: pointer; user-select: none; }
.ledger th[aria-sort="ascending"]::after { content: ' ↑'; color: var(--saffron); }
.ledger th[aria-sort="descending"]::after { content: ' ↓'; color: var(--saffron); }
.sec-name { display: block; font-weight: 500; }
.sec-meta { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.ledger td.num .sec-meta { text-align: right; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #E6EEEC; color: var(--petrol); margin: 0 4px 2px 0; white-space: nowrap; }
.warn-dot { color: var(--down); font-weight: 500; }
.bar { display: block; height: 3px; background: var(--rule); margin-bottom: 4px; position: relative; }
.bar::after { content: ''; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--saffron); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; margin-left: 10px; }
.tag { font-size: 12.5px; padding: 1px 8px; border-radius: 3px; background: var(--paper); white-space: nowrap; }
.tag-buy { background: #E2EFE8; color: var(--up); }
.tag-sell { background: #F6E4E2; color: var(--down); }
.tag-dividend { background: #FBF0D8; color: #7A5510; }
tr.is-muted td { color: var(--muted); }
tr.is-alert td { background: #FBEDEC; }
.notes ul { margin: 0; padding-left: 18px; color: var(--muted); }

/* ------------------------------------------------------------ Formulare */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; max-width: 760px; }
.span-2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 500; }
label small { font-size: 12.5px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; padding: 9px 11px; border: 1px solid #BFCACB; border-radius: 5px; background: #fff; color: var(--ink); width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus { outline: 2px solid var(--petrol); outline-offset: -1px; border-color: var(--petrol); }
.code-input { font-size: 22px; letter-spacing: .3em; text-align: center; }
.edit-table input, .edit-table select { padding: 6px 8px; font-size: 14px; min-width: 110px; }
.type-pick { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.type-pick legend { font-size: 14px; font-weight: 500; margin-bottom: 6px; padding: 0; }
.pill { flex-direction: row; }
.pill input { position: absolute; opacity: 0; }
.pill span { padding: 7px 16px; border: 1px solid #BFCACB; border-radius: 20px; cursor: pointer; font-weight: 400; }
.pill input:checked + span { background: var(--petrol); border-color: var(--petrol); color: #fff; }
.pill input:focus-visible + span { outline: 2px solid var(--saffron); outline-offset: 2px; }
.symbol-field { position: relative; }
.suggest {
  position: absolute; z-index: 20; left: 0; right: 0; top: 70px; list-style: none; margin: 0; padding: 4px;
  background: #fff; border: 1px solid var(--rule); border-radius: 6px; box-shadow: 0 10px 30px rgba(14,74,86,.14); max-height: 320px; overflow-y: auto;
}
.suggest button { display: grid; grid-template-columns: 110px 1fr; grid-template-rows: auto auto; column-gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 4px; font: inherit; cursor: pointer; }
.suggest button small { grid-column: 2; }
.suggest button:hover, .suggest button.is-active { background: var(--paper); }
.suggest-msg { padding: 10px; color: var(--muted); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.filters { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.filters label { font-weight: 400; color: var(--muted); }
.filters select { min-width: 160px; }
.switcher label { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); }
.switcher select { width: auto; }
.inline-form { display: inline-block; margin: 0 8px 10px 0; }
.danger-zone { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--rule); }
.danger-title { margin-top: 26px; color: var(--down); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 18px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; font-weight: 500; }
.qr { width: 190px; height: 190px; margin: 10px 0; }
.qr svg { width: 100%; height: 100%; }
.secret { background: var(--paper); padding: 2px 6px; border-radius: 3px; word-break: break-all; }
.code { background: var(--paper); padding: 14px; border-radius: 5px; overflow-x: auto; line-height: 1.6; }
.notice { background: #FBF0D8; padding: 10px 12px; border-radius: 5px; }
.ok-line { color: var(--up); font-weight: 500; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 500;
  padding: 9px 16px; border-radius: 5px; border: 1px solid var(--petrol); background: transparent; color: var(--petrol);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #E3ECEB; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--petrol); color: #fff; }
.btn-primary:hover { background: var(--petrol-deep); }
.btn-ghost { border-color: transparent; }
.btn-danger { border-color: var(--down); color: var(--down); }
.btn-danger:hover { background: #F6E4E2; }
.btn-small { padding: 5px 11px; font-size: 13px; }
.linklike { background: none; border: 0; font: inherit; color: var(--petrol); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.linklike.danger { color: var(--down); }

/* Meldungen */
.flash { padding: 12px 16px; border-radius: 5px; margin-bottom: 20px; border-left: 4px solid; }
.flash ul { margin: 8px 0 0; padding-left: 18px; }
.flash-ok { background: #E4F1EA; border-color: var(--up); }
.flash-info { background: #FBF0D8; border-color: var(--saffron); }
.flash-error { background: #F9E3E2; border-color: var(--down); }

/* Leerer Zustand */
.empty { background: var(--card); border: 1px dashed #B7C4C4; border-radius: var(--radius); padding: 40px; }
.empty h2 { font-size: 22px; margin-bottom: 8px; }
.empty p { max-width: 60ch; color: var(--muted); }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.empty.inline { padding: 24px; border: 0; }

/* Anmeldung */
.auth { width: 100%; max-width: 420px; }
.auth-card { background: var(--card); border: 1px solid var(--rule); border-top: 4px solid var(--petrol); border-radius: var(--radius); padding: 34px 32px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card .sub { color: var(--muted); margin: 0 0 18px; }
.auth-card .form { margin-top: 18px; max-width: none; }
.auth-card .btn { margin-top: 6px; }

/* ------------------------------------------------------------ Mobil */
@media (max-width: 960px) {
  .main { padding: 24px 20px 48px; }
  .alloc-grid { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; height: auto; padding: 12px 0 0 12px; z-index: 30; }
  .brand { padding-bottom: 10px; }
  .rail-toggle { display: block; margin-right: 12px; }
  .rail-nav, .rail-foot { display: none; }
  .rail.is-open .rail-nav, .rail.is-open .rail-foot { display: block; }
  .rail.is-open { max-height: 100vh; overflow-y: auto; padding-bottom: 12px; }
  .tabs { flex-direction: row; overflow-x: auto; margin-bottom: 14px; }
  .tab { border-radius: 8px 8px 0 0; }
  .tab.is-active::before, .tab.is-active::after { display: none; }
  .hero-split div:first-child { padding-left: 0; border-left: 0; }
  .grid-form { grid-template-columns: 1fr; }
  .alloc-body { flex-direction: column; align-items: stretch; }
  .alloc-body canvas { align-self: center; }
  .chart-wrap { height: 260px; }
  .kpi:nth-child(odd) { border-left: 0; padding-left: 0; }
  .panel { padding: 18px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.rail-me { font-size: 12.5px; color: #8FB2B6; padding: 0 14px 4px; }
