:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1b1f1c;
  --muted: #6b7370;
  --line: #e2e5e0;
  --accent: #1f6f4a;
  --accent-ink: #ffffff;
  --up: #1c7c47;
  --down: #b7332b;
  --warn: #b7791f;
  --info: #3b6fa3;
  --up-bg: #e6f3ea;
  --down-bg: #f9e7e5;
  --warn-bg: #fbf0dc;
  --info-bg: #e6eef7;
  --hold-bg: #eef0ec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131614; --card: #1c201d; --ink: #e8ebe6; --muted: #98a09b; --line: #2b302c;
    --accent: #3f9b6c; --up: #4fc17f; --down: #ef6b5f; --warn: #e0a43c; --info: #7aa7d9;
    --up-bg: #1b2f23; --down-bg: #35201e; --warn-bg: #332a18; --info-bg: #1c2836; --hold-bg: #232824;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 40px;
}
a { color: var(--accent); }
code { font-size: .9em; background: var(--hold-bg); padding: 1px 5px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mt { margin-top: 14px; }
.up { color: var(--up); }
.down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  /* Im PWA-Standalone-Modus nicht unter die Notch/Statusleiste rutschen */
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
@media (max-width: 600px) {
  .topbar { gap: 8px 10px; padding-left: 12px; padding-right: 12px; }
  .topbar-right { margin-left: auto; }
  .topbar .tabs { order: 3; flex: 0 0 100%; margin: 0 -12px; padding: 0 12px; width: calc(100% + 24px); }  /* eigene Zeile, seitlich scrollbar */
}
.update-bar { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 20; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.2); border-radius: 10px; padding: 8px 8px 8px 14px; display: flex; gap: 10px; align-items: center; font-size: .9rem; }
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.logo { width: 24px; height: 24px; background: url("/static/icons/icon.svg") center/contain no-repeat; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs button {
  border: 0; background: none; color: var(--muted); padding: 8px 12px; border-radius: 8px;
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.tabs button.active { background: var(--hold-bg); color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.depot-pick { font-weight: 600; max-width: 180px; text-overflow: ellipsis; }
@media (max-width: 1400px) { #lastRefresh { display: none; } }  /* the time is in the button's tooltip */
@media (max-width: 600px) { .depot-pick { order: 2; flex: 0 0 100%; max-width: none; } }  /* own row above the tabs */

/* ---------- setup wizard ---------- */
dialog.setup-dialog { width: min(760px, 96vw); }
.style-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
@media (max-width: 600px) { .style-pick { grid-template-columns: 1fr; } }
.style-pick label { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; color: var(--ink); font-size: .85rem; }
.style-pick label b { display: block; margin-bottom: 4px; font-size: .95rem; }
.style-pick label input { display: none; }
.style-pick label:has(input:checked) { border-color: var(--accent); background: var(--up-bg); }
.style-pick label span { color: var(--muted); }

main { max-width: 1240px; margin: 0 auto; padding: 18px 16px; }
[hidden] { display: none !important; }  /* the attribute must win over display rules like .form label */

/* ---------- cards & layout ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
.grid-2.rev { grid-template-columns: 1fr 1.3fr; }
.grid-2 > * { min-width: 0; }  /* sonst sprengt eine breite Tabelle die Spalte statt zu scrollen */
@media (max-width: 860px) { .grid-2, .grid-2.rev { grid-template-columns: 1fr; } }
main, .card { min-width: 0; max-width: 100%; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.35rem; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.danger { color: var(--down); border-color: var(--down); }
.btn:disabled { opacity: .5; cursor: wait; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; color: var(--muted); padding: 4px 10px; font: inherit; font-size: .8rem; cursor: pointer; }
.seg button.active { background: var(--hold-bg); color: var(--ink); }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); flex: 1; min-width: 0; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); flex-wrap: wrap; }
.form label.check input { width: auto; margin: 0; accent-color: var(--accent); }
.form input, .form select, .form textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form .row { display: flex; gap: 10px; flex-wrap: wrap; }
.form .row > label { flex: 1 1 140px; }
.form .row.end { justify-content: flex-end; }
.form .row.between { justify-content: space-between; }
.hint { font-size: .78rem; color: var(--muted); }
.trade-total { font-size: .9rem; color: var(--muted); }
.trade-total strong { color: var(--ink); font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.search-wrap { position: relative; }
.search-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 4; background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
.search-results div { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; color: var(--ink); }
.search-results div:hover { background: var(--hold-bg); }
.search-results .sym { font-weight: 600; white-space: nowrap; }
.search-results .ex { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.search-results .group { margin: 0; padding: 6px 10px 2px; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.search-results div.own .ex { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 600px) {
  table { font-size: .82rem; }
  th, td { padding: 7px 5px; }
  td .name { max-width: 130px; }
  .col-note { display: none; }
  .card { padding: 14px 12px; }
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.num, td.num { text-align: right; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--hold-bg); }
td .name { color: var(--muted); font-size: .8rem; display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spark { width: 90px; height: 26px; display: block; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 7px; border-radius: 999px; margin: 1px 2px 1px 0; white-space: nowrap; }
.tag.verkaufen { background: var(--down-bg); color: var(--down); }
.tag.kaufen { background: var(--up-bg); color: var(--up); }
.tag.warnung { background: var(--warn-bg); color: var(--warn); }
.tag.info { background: var(--info-bg); color: var(--info); }
.tag.halten { background: var(--hold-bg); color: var(--muted); }
.tag.etf { background: var(--info-bg); color: var(--info); }
.tag.stock { background: var(--hold-bg); color: var(--muted); }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 2px 6px; }
.icon-btn:hover { color: var(--down); }

/* ---------- actions ---------- */
.actions { display: flex; flex-direction: column; gap: 8px; }
.action { border-left: 4px solid var(--muted); background: var(--hold-bg); border-radius: 8px; padding: 10px 12px; }
.action.verkaufen { border-color: var(--down); background: var(--down-bg); }
.action.kaufen { border-color: var(--up); background: var(--up-bg); }
.action.warnung { border-color: var(--warn); background: var(--warn-bg); }
.action.info { border-color: var(--info); background: var(--info-bg); }
.action .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.action .head b { font-size: .95rem; }
.action .who { color: var(--muted); font-size: .82rem; }
.action .who a { color: inherit; text-decoration: none; font-weight: 600; cursor: pointer; }
.action p { margin: 4px 0 0; font-size: .88rem; }
.actions.compact .action { padding: 8px 10px; }
.actions.compact .action p { font-size: .84rem; }
.empty { color: var(--muted); font-size: .9rem; padding: 14px 4px; }

/* ---------- allocation ---------- */
.alloc { display: flex; flex-direction: column; gap: 6px; }
.alloc .row { display: grid; grid-template-columns: 90px 1fr 58px 58px; gap: 8px; align-items: center; font-size: .85rem; }
.alloc .bar { height: 10px; background: var(--hold-bg); border-radius: 6px; position: relative; overflow: visible; }
.alloc .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 6px; }
.alloc .bar b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .55; }

/* ---------- charts ---------- */
.chart { width: 100%; min-height: 160px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 10px; }

/* ---------- watchlist ---------- */
.watchlist { display: flex; flex-direction: column; gap: 10px; }
.witem { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.witem .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(860px, 96vw); max-height: 92vh; background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 18px 8px; gap: 10px; }
.dialog-body { padding: 0 18px 18px; overflow: auto; max-height: calc(92vh - 70px); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.stat .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-weight: 600; font-variant-numeric: tabular-nums; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--hold-bg); color: var(--muted); }
.badge.on { background: var(--up-bg); color: var(--up); }
.legend { padding-left: 18px; margin: 0; }
.legend li { margin-bottom: 4px; }

.prose { font-size: .92rem; }
.prose h1, .prose h2, .prose h3 { font-size: 1rem; margin: 14px 0 6px; }
.prose p { margin: 6px 0; }
.prose ul, .prose ol { padding-left: 20px; margin: 6px 0; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 92vw; }
.toast.err { background: var(--down); color: #fff; }

/* ---------- briefing chat ---------- */
.quota { background: var(--info-bg); border-radius: 9px; padding: 10px 12px; margin: 4px 0 12px; font-size: .85rem; }
.quota p { margin: 0 0 6px; }
.quota ul { margin: 0; padding-left: 18px; }
.quota li { margin: 2px 0; }
.quota .left { font-weight: 600; }
.quota .left.none { color: var(--down); }
.chat { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 4px; }
.chat-thread { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: .9rem; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--hold-bg); border-bottom-left-radius: 4px; }
.msg.assistant p:first-child { margin-top: 0; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg.pending { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; min-width: 0; }
.chat-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
@media (max-width: 600px) { .msg { max-width: 95%; } }

/* ---------- target price suggestion ---------- */
.suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; line-height: 1.6; }
.suggest[hidden] { display: none; }
.suggest .chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  padding: 1px 9px; font: inherit; font-size: .78rem; cursor: pointer; }
.suggest .chip:hover { border-color: var(--accent); color: var(--accent); }
.suggest .chip.main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- watchlist tools ---------- */
.wtools { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.wtools input { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; width: 100%; }
.wtools input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .chip { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: .8rem; cursor: pointer; }
.chips .chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.small-select { font: inherit; font-size: .82rem; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; max-width: 100%; }
.witem .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }
th.sortable.on { color: var(--accent); }

dialog.small-dialog { width: min(560px, 96vw); }
.icon-btn.edit:hover { color: var(--accent); }

dialog.confirm-dialog { width: min(420px, 92vw); }
dialog.confirm-dialog .dialog-body { padding: 20px 20px 16px; }
dialog.confirm-dialog h2 { margin-bottom: 6px; }
dialog.confirm-dialog p { margin: 0; font-size: .92rem; }
.btn.danger.primary { background: var(--down); border-color: var(--down); color: #fff; }

/* ---------- journal & tax ---------- */
.journal { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.journal h3 { margin-top: 0; }
.journal .bar-wrap { height: 8px; background: var(--hold-bg); border-radius: 999px; overflow: hidden; margin: 6px 0 4px; }
.journal .bar-wrap i { display: block; height: 100%; background: var(--accent); }
.journal table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.journal td, .journal th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.journal td.num, .journal th.num { text-align: right; }
.tag.journal-ok { background: var(--up-bg); color: var(--up); font-weight: 500; }
.tag.journal-none { background: var(--warn-bg); color: var(--warn); font-weight: 500; }

/* ---------- Trading-Modus ---------- */
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 8px; }
.tr-banner { border-left: 4px solid var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }
.tr-banner.down { border-color: var(--down); background: var(--down-bg); }
.tr-news { border-top: 1px solid var(--line); padding: 8px 0; }
.tr-news:first-child { border-top: 0; }
.tr-report h3 { margin: 14px 0 6px; font-size: .95rem; }
.tr-report ul { margin: 0; padding-left: 18px; }
tr.clickable { cursor: pointer; }
.journal-wide { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 12px; }
