/* ==========================================================================
   AsasHub Finanzen: Ergänzungen zum Design-System (app.css)
   ========================================================================== */

:root {
  --c-blue: #6d8dff;
  --c-violet: #a78bfa;
  --c-emerald: #3ddc97;
  --c-amber: #f5b942;
  --c-rose: #ff7a90;
  --c-slate: #94a3b8;
  --page: 1040px;
}

.page-wide { padding-bottom: 72px; }
.sk-block { height: 120px; border-radius: 16px; }

/* ---------- Navigation ---------- */
.top-nav { display: none; align-items: center; gap: 4px; margin-right: auto; margin-left: 20px; }
.top-nav a, .tab-bar a {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  color: var(--text-2); font-size: 14px; font-weight: 600;
  transition: color 0.15s, background-color 0.15s;
}
.top-nav a { height: 36px; padding: 0 12px; border-radius: 10px; }
.top-nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.top-nav a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); }
.top-nav a.active .icon { color: var(--brand); }

.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(10, 13, 21, 0.82);
  -webkit-backdrop-filter: blur(16px) saturate(160%); backdrop-filter: blur(16px) saturate(160%);
  border-top: 1px solid var(--line);
}
.tab-bar a { flex-direction: column; justify-content: center; gap: 3px; height: 52px; border-radius: 12px; font-size: 11px; }
.tab-bar a .icon { width: 22px; height: 22px; }
.tab-bar a.active { color: var(--brand-soft); }
.tab-bar a:active { background: rgba(255, 255, 255, 0.06); }

@media (max-width: 719px) {
  .page-wide { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@media (min-width: 720px) {
  .top-nav { display: flex; }
  .tab-bar { display: none; }
}

/* ---------- Seitenkopf ---------- */
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 10px; }
.view { display: grid; gap: 20px; }
.hint-line { color: var(--text-3); font-size: 13px; line-height: 1.5; max-width: 70ch; }

/* ---------- Kennzahlen ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.kpis-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--text-3); font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }
.kpi-value { margin-top: 4px; font-size: 22px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.kpi-value.neg { color: var(--danger); }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -0.01em; }
.amount.pos { color: var(--ok); }
.amount.neg { color: var(--text); }
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis .kpi:first-child:nth-last-child(3) { grid-column: 1 / -1; }
  .kpi-value { font-size: 19px; }
}

/* ---------- Konto-Karten (Übersicht) ---------- */
.account-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .account-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.account-card { padding: 18px 18px 6px; display: grid; gap: 16px; align-content: start; }
.account-head { display: flex; align-items: center; gap: 12px; }
.account-figures { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.figure-wide { grid-column: 1 / -1; padding-top: 10px; border-top: 1px solid var(--border, rgba(255,255,255,.08)); }
.figure-label { color: var(--text-3); font-size: 12px; font-weight: 600; }
.figure-value { margin-top: 2px; font-size: 26px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.figure-value.figure-sub { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-2); margin-top: 7px; }
.due-list { list-style: none; margin: 0 -18px; padding: 0; border-top: 1px solid var(--line); }
.due-row { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: 14px; }
.due-row:last-of-type { border-bottom: 0; }
.due-date { color: var(--text-3); font-size: 13px; }
.due-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-more { padding: 4px 18px 14px; color: var(--text-3); font-size: 13px; }
.due-empty { margin: 0 -18px; padding: 14px 18px 18px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 14px; }

/* ---------- Farben ---------- */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c-blue); }
.dot-blue { background: var(--c-blue); } .dot-violet { background: var(--c-violet); } .dot-emerald { background: var(--c-emerald); }
.dot-amber { background: var(--c-amber); } .dot-rose { background: var(--c-rose); } .dot-slate { background: var(--c-slate); }
.row-icon.tone-blue { color: var(--c-blue); background: rgba(109, 141, 255, 0.13); border-color: rgba(109, 141, 255, 0.3); }
.row-icon.tone-violet { color: var(--c-violet); background: rgba(167, 139, 250, 0.13); border-color: rgba(167, 139, 250, 0.3); }
.row-icon.tone-emerald { color: var(--c-emerald); background: rgba(61, 220, 151, 0.12); border-color: rgba(61, 220, 151, 0.28); }
.row-icon.tone-amber { color: var(--c-amber); background: rgba(245, 185, 66, 0.12); border-color: rgba(245, 185, 66, 0.3); }
.row-icon.tone-rose { color: var(--c-rose); background: rgba(255, 122, 144, 0.12); border-color: rgba(255, 122, 144, 0.3); }
.row-icon.tone-slate { color: var(--c-slate); background: rgba(148, 163, 184, 0.12); border-color: rgba(148, 163, 184, 0.28); }
.chip-account { gap: 6px; }

/* ---------- Filter, Monatsleiste ---------- */
.filter-row { display: flex; gap: 8px; overflow-x: auto; margin: 0 -20px; padding: 2px 20px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 8px; flex: none; height: 36px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 999px;
  color: var(--text-2); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.active { color: var(--text); background: var(--surface-3); border-color: rgba(109, 141, 255, 0.55); }
@media (max-width: 560px) { .filter-row { margin: 0 -16px; padding: 2px 16px; } }

.month-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-title { font-size: 18px; font-weight: 650; letter-spacing: -0.02em; text-transform: capitalize; }
.segmented-sm span { height: 32px; padding: 0 12px; font-size: 13px; }

/* ---------- Listen ---------- */
.list-flush { border-top: 0; }
.group-head { padding: 10px 20px 6px; background: rgba(255, 255, 255, 0.025); border-bottom: 1px solid var(--line); color: var(--text-3); font-size: 12px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; list-style: none; }
.row-click { cursor: pointer; border-radius: 8px; }
.row-click:focus-visible { outline-offset: 4px; }
.row-dim { opacity: 0.55; }
.row-end { gap: 4px; }
.row-end .amount { margin-right: 4px; }
.card-foot-link { display: flex; justify-content: center; padding-top: 4px; }
.empty-card { padding: 48px 20px; gap: 8px; }
.empty-card .btn { margin-top: 10px; }
@media (max-width: 560px) { .group-head { padding-left: 16px; padding-right: 16px; } }

/* ---------- Formulare ---------- */
dialog.dialog-form { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
dialog.dialog-form form { display: flex; flex-direction: column; max-height: inherit; }
.dialog-scroll { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 12px; }
.form-grid { display: grid; gap: 18px; margin-top: 8px; }
.field-hint { color: var(--text-3); font-size: 12.5px; line-height: 1.4; }
.field-hint:empty, .field-error:empty { display: none; }
.field-error { color: var(--danger); font-size: 12.5px; font-weight: 600; }
.field.invalid .input { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.14); }
.input-wrap-right .input { padding-right: 40px; text-align: right; font-variant-numeric: tabular-nums; }
.input-suffix { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
input[type="date"].input { min-height: 48px; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.choice span {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 999px;
  color: var(--text-2); font-size: 14px; font-weight: 600;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.choice:hover span { color: var(--text); }
.choice input:checked + span { color: var(--text); background: rgba(109, 141, 255, 0.16); border-color: rgba(109, 141, 255, 0.6); }
.choice input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.segmented span { gap: 8px; }

@media (max-width: 560px) {
  /* Sheet am unteren Rand; mit Tastatur setzt common.js Unterkante und Höhe passend zum sichtbaren Bereich */
  dialog.dialog.dialog-form { width: calc(100% - 24px); max-width: none; margin: auto auto 12px; border-radius: 24px; border-bottom: 1px solid var(--line); max-height: calc(100dvh - 24px); animation: dialog-in 0.22s var(--ease); }
}

/* Vorschau und Szenario */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fc-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.fc-table th, .fc-table td { padding: 11px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.fc-table thead th { color: var(--text-3); font-size: 12px; font-weight: 600; }
.fc-table th:first-child, .fc-table td:first-child { text-align: left; }
.fc-table tbody th { font-weight: 600; }
.fc-table tr:last-child th, .fc-table tr:last-child td { border-bottom: 0; }
.fc-table .dot { margin-right: 6px; }
.fc-peak { background: rgba(245, 185, 66, 0.07); }
.fc-in { font-size: 12px; margin-top: 2px; }
.faint { color: var(--text-3); }
.row-check { display: flex; align-items: center; padding: 0 4px; }
.row-check input { width: 20px; height: 20px; accent-color: var(--brand, #6d8dff); }
.export-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.card > .hint-line { padding: 12px 20px 16px; margin: 0; }

/* Grid-Kinder dürfen schrumpfen: breite Tabellen scrollen in ihrer Karte, die Seite wird nicht breiter als der Bildschirm. */
.page, .view { grid-template-columns: minmax(0, 1fr); }
.page > *, .view > * { min-width: 0; }
.row-plan { flex-wrap: wrap; }
.row-plan .row-end { flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
@media (max-width: 560px) {
  .fc-table { font-size: 13px; }
  .fc-table th, .fc-table td { padding: 10px 8px; }
  .fc-table th:first-child, .fc-table td:first-child { padding-left: 14px; }
  .fc-table th:last-child, .fc-table td:last-child { padding-right: 14px; }
  .fc-table thead th { font-size: 11px; }
}
.fc-table thead th { white-space: normal; vertical-align: bottom; line-height: 1.3; }
@media (max-width: 560px) { .fc-table thead th { max-width: 96px; overflow-wrap: break-word; hyphens: auto; } .fc-table thead .dot { display: none; } }

/* Vorschau: nur die Tabelle scrollt (Kopfzeile und Monatsspalte bleiben stehen), die Seite bleibt ruhig. */
.table-scroll-tall { max-height: calc(100dvh - 330px); min-height: 260px; overflow: auto; overscroll-behavior: contain; }
.table-scroll-tall thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); box-shadow: 0 1px 0 var(--line); }
.table-scroll-tall tbody th { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.table-scroll-tall thead th:first-child { left: 0; z-index: 3; }
.table-scroll-tall .fc-peak th { background: #1b1a18; }

/* Seitwärts scrollt nur die Tabelle in ihrer Karte, nie die Seite. */
html, body { overflow-x: clip; max-width: 100%; }
.card:has(> .table-scroll) { overflow: hidden; }
.table-scroll { max-width: 100%; overscroll-behavior-x: contain; }

/* Schwebender Hinzufügen-Button (nur Handy, am Desktop reicht der Button im Seitenkopf) */
.fab { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 25; width: 56px; height: 56px; padding: 0; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }
.fab .icon { width: 26px; height: 26px; }
@media (min-width: 720px) { .fab { display: none; } }

.filter-label { align-self: center; flex: none; color: var(--text-3); font-size: 12px; font-weight: 600; padding-right: 2px; }
.sort-arrow { margin-left: 6px; color: var(--brand-soft); font-weight: 700; }
.filters { display: grid; gap: 8px; min-width: 0; }
.segmented-sm { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented-sm::-webkit-scrollbar { display: none; }
.segmented-sm span { white-space: nowrap; }
@media (max-width: 560px) { .segmented-sm span { padding-left: 11px; padding-right: 11px; } }
.head-actions { min-width: 0; max-width: 100%; }
.page-head-row > div:first-child { min-width: 0; }
