/* ETF Tracker - one stylesheet, no framework. */

:root {
  color-scheme: light;
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --grid:         #e1e0d9;
  --axis:         #c3c2b7;
  --border:       rgba(11, 11, 11, .10);
  --series-1:     #2a78d6;
  --series-wash:  rgba(42, 120, 214, .10);
  --good:         #006300;
  --bad:          #d03b3b;
  --shadow:       0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .04);
  --radius:       14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane:       #0d0d0d;
    --surface:     #1a1a19;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --grid:        #2c2c2a;
    --axis:        #383835;
    --border:      rgba(255, 255, 255, .10);
    --series-1:    #3987e5;
    --series-wash: rgba(57, 135, 229, .12);
    --good:        #0ca30c;
    --bad:         #e66767;
    --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: .01em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ------------------------------------------------------------------ login */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login-card p { margin: 0; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.fund { font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
/* Kurs und Tagesveränderung stehen in der Zeile unter dem Fondsnamen. */
.fund-line { white-space: normal; }
.sub-price { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Benutzerauswahl des Admins - nur fuer ihn sichtbar. */
.user-switch {
  width: auto; font-size: 13px; padding: 7px 30px 7px 11px;
  background-position: right 9px center;
}
/* Fremde Daten deutlich markieren, damit man nicht im falschen Depot tippt. */
.user-switch.foreign { border-color: var(--series-1); color: var(--series-1); font-weight: 600; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}

/* ------------------------------------------------------------ hero + tiles */
.hero-card { display: grid; gap: 22px; }
.hero-row {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
/* Prognoserechner rechts neben der grossen Zahl. */
.plan { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.plan label { width: 122px; }
@media (max-width: 620px) {
  .plan { width: 100%; }
  .plan label { flex: 1; width: auto; }
}
.label { color: var(--muted); font-size: 13px; }
.hero-figure {
  font-size: clamp(40px, 7vw, 56px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -.02em;
  margin-top: 2px;
}
.hero-delta { margin-top: 6px; font-size: 15px; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta { font-variant-numeric: tabular-nums; }

.tiles, .result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
/* Die 6 Ergebnisfelder der Entnahme sollen 3 × 2 stehen, nicht 5 + 1. */
.result-grid { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .result-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .result-grid { grid-template-columns: 1fr; } }

.tile, .res { background: var(--surface); padding: 14px 16px; }
.tile .value, .res .value {
  font-size: 21px; font-weight: 600; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.tile .sub, .res .sub { font-size: 12px; margin-top: 2px; }

/* ------------------------------------------------------------------ chart */
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 14px;
}
.card-head p { margin: 2px 0 0; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }

.seg {
  display: inline-flex;
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
}
.seg button {
  border: 0; background: none; color: var(--ink-2);
  font: inherit; font-size: 13px; padding: 5px 11px;
  border-radius: 7px; cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chart-host { position: relative; width: 100%; }
.chart-host svg { display: block; width: 100%; height: auto; touch-action: none; }

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  z-index: 3;
}
.tip .t-date { color: var(--muted); }
.tip .t-val { font-weight: 600; font-variant-numeric: tabular-nums; }

.breakdown { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.breakdown h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 8px; }
.breakdown td:first-child { color: var(--ink-2); }
.breakdown .step td { padding-left: 26px; }      /* Zwischenschritte einrücken */
.breakdown .sum td { font-weight: 600; color: var(--ink); }
.breakdown .total td { font-weight: 600; color: var(--ink); border-top: 1px solid var(--axis); }
.breakdown tr:last-child td { border-bottom: 0; }

.table-view { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.table-view summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.table-scroll { overflow-x: auto; max-height: 320px; overflow-y: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--surface); }

/* ------------------------------------------------------------------ forms */
/* Position links schmal, Steuereinstellungen rechts breit. Jede Karte behält
   ihre eigene Höhe, damit unter der schmalen keine Leerfläche entsteht. */
.two-col {
  display: grid;
  grid-template-columns: 1fr 2fr;
  align-items: start;
  gap: 20px;
}
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

label { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 4px; }
.field-grid.stacked { grid-template-columns: 1fr; }
.field-grid .span-2 { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }

input, select {
  font: inherit;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
input:focus, select:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }

/* Eigener Pfeil statt des System-Pfeils: der native lässt sich nicht einfärben.
   Farbe ist der Muted-Ton der Einheiten (€, Stk) - in hell und dunkel derselbe
   Wert #898781 - und er sitzt mit 11px genauso weit vom Rand wie diese. */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='M1 1.25 5.5 5.75 10 1.25' fill='none' stroke='%23898781' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 11px 7px;
}

/* Ja/Nein-Schalter. Sitzt in derselben Hülle wie ein Eingabefeld, damit er in
   der Feldreihe nicht wie ein Fremdkörper wirkt. */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--plane); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; cursor: pointer;
  transition: border-color .12s ease;
}
.switch-row:hover { border-color: var(--axis); }
.switch-text { font-size: 15px; color: var(--ink); user-select: none; }

input.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 38px; height: 22px; margin: 0; padding: 0;
  border: 0; border-radius: 999px; background: var(--axis);
  position: relative; cursor: pointer;
  transition: background .15s ease;
}
input.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform .15s ease;
}
input.switch:checked { background: var(--series-1); }
input.switch:checked::after { transform: translateX(16px); }
input.switch:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .switch-row, input.switch, input.switch::after { transition: none; }
}
/* Feld mit Plus-Knopf: der Wert wird ergänzt statt überschrieben. */
.field-with-add { display: flex; gap: 8px; align-items: stretch; }
.field-with-add .input-unit { flex: 1; min-width: 0; }
.icon-btn {
  flex: none; width: 42px;
  font: inherit; font-size: 18px; line-height: 1;
  color: var(--ink-2); background: var(--plane);
  border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--axis); }
.icon-btn svg { display: block; margin: 0 auto; }

/* Modal fuer den Verlauf der Vorabpauschalen */
.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 20px;
  background: rgba(11, 11, 11, .45);
}
.modal-card {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px; width: 100%; max-width: 440px;
  max-height: 80vh; overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 12px;
}
.modal-head h2 { font-size: 15px; }
.modal-card .table-scroll { margin-top: 0; }
.modal-card td { vertical-align: middle; }
.row-del {
  border: 0; background: none; cursor: pointer; padding: 2px 6px;
  color: var(--muted); font: inherit; font-size: 16px; line-height: 1; border-radius: 6px;
}
.row-del:hover { color: var(--bad); background: rgba(208, 59, 59, .10); }
.modal-card .empty { color: var(--muted); text-align: left; }
.icon-btn.confirm { color: #fff; background: var(--series-1); border-color: var(--series-1); }
input[readonly] { cursor: default; }

.input-unit { position: relative; }
.input-unit input { padding-right: 40px; }
.unit {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 13px; pointer-events: none;
}

button.primary {
  font: inherit; font-weight: 600;
  background: var(--series-1); color: #fff;
  border: 0; border-radius: 9px; padding: 10px 18px; cursor: pointer;
}
button.primary:hover { filter: brightness(1.07); }
button.primary:disabled { opacity: .4; cursor: default; filter: none; }

.book-row {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 14px; margin-top: 16px; flex-wrap: wrap;
}
.book-row span { text-align: right; }
button.ghost {
  font: inherit; font-size: 13px;
  background: var(--plane); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 12px; cursor: pointer;
}
button.ghost:hover { color: var(--ink); }

/* Rückmeldung des Auto-Speicherns. Blendet sich ein und wieder aus, ohne die
   Kopfzeile umbrechen zu lassen. */
.save-note {
  font-size: 13px; color: var(--muted); white-space: nowrap;
  opacity: 0; transition: opacity .2s ease;
}
.save-note:not(:empty) { opacity: 1; }
.save-note.failed { color: var(--bad); }
@media (prefers-reduced-motion: reduce) { .save-note { transition: none; } }
/* Zusatz in einer Überschrift - leichter gesetzt als der Titel selbst. */
.head-note { font-weight: 400; color: var(--muted); }
.head-note #rate-out { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- withdrawal */
.withdraw-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 14px;
  margin: 16px 0;
}
.big-field input { font-size: 19px; padding: 12px 40px 12px 13px; font-weight: 600; }
.arrows { color: var(--muted); font-size: 20px; padding-bottom: 12px; }

.error, .warn {
  margin: 0; font-size: 13px; padding: 9px 12px; border-radius: 9px;
  background: rgba(208, 59, 59, .10); color: var(--bad);
}
.warn { margin-bottom: 14px; }

.footnote { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0 0 8px; }

@media (max-width: 620px) {
  .wrap, .topbar { padding: 16px; }
  .field-grid { grid-template-columns: 1fr; }
  .withdraw-grid { grid-template-columns: 1fr; }
  .arrows { display: none; }
}
