/* ============================================================
   Dashboard design system
   Apple-inspired dark UI: layered surfaces, soft depth, vibrancy
   header, restrained colour (blue accent for navigation, green/red
   reserved for financial semantics). Chart colours unchanged.
   ============================================================ */

:root {
    /* Surfaces — near-black page, progressively lighter elevations */
    --bg: #08080a;
    --bg-grad: #101016;
    --surface: #141419;
    --surface-hover: #1a1a21;
    --surface-2: #1f1f27;
    --border: #26262e;
    --border-strong: #33333d;

    /* Text */
    --text: #f5f5f7;
    --text-secondary: #a6a6b0;
    --text-muted: #76767f;

    /* Accent (Apple system blue, dark) — navigation only */
    --accent: #0a84ff;
    --accent-hover: #3a9bff;
    --accent-tint: rgba(10, 132, 255, 0.14);

    /* Financial semantics — keep in sync with the chart */
    --green: #34d399;
    --red: #f87171;

    /* Shape & depth */
    --radius: 16px;
    --radius-sm: 10px;
    --radius-pill: 999px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --edge: inset 0 1px 0 rgba(255, 255, 255, 0.045);

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
        "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --topbar-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; overflow-x: clip; }

body {
    background: var(--bg);
    background-image: radial-gradient(120% 80% at 50% -10%, var(--bg-grad) 0%, var(--bg) 55%);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    color-scheme: dark;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-x: clip; /* guard: never let a wide child cause horizontal page scroll */
}

::selection { background: var(--accent-tint); color: var(--text); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Subtle, unobtrusive scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
    background: #2c2c35;
    border-radius: var(--radius-pill);
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #3a3a45; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

a { color: inherit; }

/* ---------- Top bar (vibrancy / blur) ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: var(--topbar-h);
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(10, 10, 14, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text);
    letter-spacing: -0.01em;
    text-decoration: none;
    white-space: nowrap;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 1.6rem;
    flex: 1;
}

.topnav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: color 0.15s var(--ease);
}
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--text); }

/* Hamburger (mobile only) */
.nav-toggle { display: none; }
.nav-burger { display: none; }

/* ---------- Layout ---------- */

.content { padding: 2rem 1.5rem 3rem; max-width: 1320px; margin: 0 auto; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.25rem;
}

/* Grid items default to min-width:auto and refuse to shrink below their
   content — a wide SVG or table would then stretch the whole page. Allow
   them to shrink so inner content scrolls/scales instead. */
.grid > * { min-width: 0; }

.overview-grid {
    grid-template-columns: 1fr;
}

/* Cards size to content and align to the top, so none gets stretched. */
.overview-grid { align-items: start; }
@media (min-width: 760px) {
    .overview-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}

/* Quick-access app-launcher tiles on the overview */
.ql-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; }
.ql-grid .ql-tile:last-child { grid-column: 1 / -1; }  /* lone 7th tile spans the row */
.ql-tile {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.55rem 0.65rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    transition: border-color 0.12s var(--ease), background 0.12s var(--ease), transform 0.12s var(--ease);
}
.ql-tile:hover { border-color: var(--border-strong); background: var(--surface-hover); transform: translateY(-1px); }
.ql-icon {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.78rem; font-weight: 700; color: #fff; letter-spacing: -0.02em;
}
.ql-logo { width: 19px; height: 19px; display: block; }
.ql-label { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem 1.5rem;
    box-shadow: var(--shadow-sm), var(--edge);
}

.card h2 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 1rem;
}
/* Secondary note inside a card heading — always smaller than the heading itself */
.card h2 small {
    font-size: 0.66rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
    opacity: 0.8;
}
.card h2 small::before { content: "("; }
.card h2 small::after { content: ")"; }

.muted { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Widgets (overview) ---------- */

.widget-row {
    display: flex;
    gap: 2.5rem;
    margin-bottom: 1rem;
}

.metric { font-size: 1.7rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric.green { color: var(--green); }
.metric.red { color: var(--red); }

.stamp {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 0.5rem;
}

.quotes {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}
.quotes th {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: right;
    padding: 0.35rem 0.65rem;
    white-space: nowrap;
}
.quotes td {
    text-align: right;
    padding: 0.5rem 0.65rem;
    border-top: 1px solid var(--border);
    font-size: 0.92rem;
    white-space: nowrap;
}
.quotes th:first-child, .quotes td:first-child { text-align: left; padding-left: 0; }
.quotes th:last-child, .quotes td:last-child { padding-right: 0; }
.quotes td.sym { font-weight: 600; }
.quotes td.vola { color: var(--text-muted); }
.quotes tbody tr { transition: background 0.12s var(--ease); }
.quotes tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.025); }
.quotes tbody tr:hover { background: rgba(255, 255, 255, 0.05); }

.news-list { list-style: none; }
.news-item { padding: 0.85rem 0; border-top: 1px solid var(--border); }
.news-item:first-child { border-top: none; padding-top: 0; }
.news-head { display: flex; justify-content: space-between; gap: 0.8rem; align-items: baseline; }
.news-head a { color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.95rem; transition: color 0.15s var(--ease); }
.news-head a:hover { color: var(--accent); }
.news-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }
.thumb {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.1rem 0.45rem;
    cursor: pointer;
    font-size: 0.85rem;
    filter: grayscale(1);
    opacity: 0.65;
    transition: opacity 0.15s var(--ease), border-color 0.15s var(--ease);
}
.thumb:hover { filter: none; opacity: 1; }
.thumb.active { filter: none; opacity: 1; border-color: var(--accent); }
.news-summary { color: var(--text-secondary); font-size: 0.88rem; margin: 0.3rem 0 0.2rem; line-height: 1.45; }
.news-source { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }

.list { list-style: none; }
.list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
.list li:last-child { border-bottom: none; }
.list a { color: var(--text); text-decoration: none; }
.list a:hover { color: var(--accent); }

/* ---------- Generic tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }

.table-scroll { overflow-x: auto; margin: 0 -0.4rem; padding: 0 0.4rem; }

/* ---------- Form controls ---------- */

input, select, button {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    height: 40px;
    padding: 0 0.8rem;
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.2;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); outline: none; }
input::placeholder { color: var(--text-muted); opacity: 1; }

select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b90a0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    padding-right: 2.2rem;
}
input[type="date"] { -webkit-appearance: none; appearance: none; }

button {
    background: var(--accent);
    border: 1px solid var(--accent);
    cursor: pointer;
    font-weight: 600;
}
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:active { transform: translateY(0.5px); }

.budget-form { display: flex; flex-direction: column; gap: 0.6rem; }

.chart { width: 100%; max-width: 100%; height: auto; display: block; }
.chart-label { fill: var(--text-muted); font-size: 11px; }

td.green, span.green { color: var(--green); }
td.red, span.red { color: var(--red); }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- Page head ---------- */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.9rem;
    margin-bottom: 1.6rem;
}
.page-head h1 { font-size: 1.7rem; font-weight: 650; letter-spacing: -0.02em; }

.year-switch { display: flex; gap: 0.4rem; }
.year-switch a {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s var(--ease);
}
.year-switch a.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}
.year-switch a:hover:not(.active) { color: var(--text); border-color: var(--border-strong); }

.back-link { color: var(--text-secondary); text-decoration: none; font-size: 0.9rem; }
.back-link:hover { color: var(--text); }

/* ---------- KPI rows ---------- */

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.6rem;
}
.kpi { display: flex; flex-direction: column; gap: 0.4rem; }
.kpi-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: var(--text-muted);
}

/* ---------- Budget charts & bars ---------- */

.budget-grid { margin-bottom: 1.6rem; }
.chart-card { display: flex; flex-direction: column; }
.chart-card .chart { flex: 1; min-height: 0; }
.bar-hit { fill: transparent; pointer-events: all; cursor: pointer; }
/* Dark halo (paint-order: stroke) keeps the value legible over the gridlines. */
.bar-value-label {
    font-size: 14px; font-weight: 700; opacity: 0; pointer-events: none;
    paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round;
    transition: opacity 0.12s var(--ease);
}
.bar-value-label.pos { fill: var(--green); }
.bar-value-label.neg { fill: var(--red); }
.bar-group:hover .bar-value-label { opacity: 1; }
/* Brighten the hovered column's bar so it's clear which month is active. */
.bar-group:hover rect:not(.bar-hit) { filter: brightness(1.15); }

/* "Load more" pager row inside the transaction table (htmx, loads in place) */
td.load-more { text-align: center; padding: 0.9rem 0; }
td.load-more a {
    display: inline-block; padding: 0.5rem 1.3rem; font-size: 0.85rem; font-weight: 600;
    color: var(--text); border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill); cursor: pointer;
    transition: background 0.12s var(--ease), border-color 0.12s var(--ease);
}
td.load-more a:hover { background: var(--surface-hover); border-color: var(--text-muted); }

.bar-row {
    display: grid;
    grid-template-columns: 130px 1fr 90px;
    align-items: center;
    gap: 0.7rem;
    padding: 0.35rem 0;
    font-size: 0.88rem;
}
.bar-label { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--surface-2); border-radius: var(--radius-pill); height: 12px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: var(--radius-pill); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- New-transaction form ---------- */

.form-card { margin-bottom: 1.6rem; position: relative; }
.budget-form-inline { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; }
.budget-form-inline input[name="amount"],
.budget-form-inline select[name="category"],
.budget-form-inline input[type="date"] { flex: 1 1 0; min-width: 140px; }
.budget-form-inline button { flex: 0 0 auto; padding: 0 2rem; }
.last-entry {
    position: absolute;
    right: 0.7rem;
    bottom: 0.3rem;
    font-size: 0.62rem;
    opacity: 0.5;
    white-space: nowrap;
}

/* ---------- Budget matrix ---------- */

.matrix-card { overflow: hidden; margin-bottom: 1.6rem; }
.matrix-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.7rem; }
.matrix-scroll { overflow-x: auto; }

.matrix { font-size: 0.84rem; white-space: nowrap; }
.matrix th, .matrix td { padding: 0.4rem 0.6rem; border-bottom: none; }
.matrix thead th { border-bottom: 1px solid var(--border); }
.matrix td.num, .matrix th.num { text-align: right; font-variant-numeric: tabular-nums; }
.matrix td.num a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--text-muted); }
.matrix td.num a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.matrix .sticky {
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
    min-width: 180px;
}
.matrix .cur { background: var(--accent-tint); }
.matrix .col-total { font-weight: 600; border-left: 1px solid var(--border); }
.matrix .col-avg { color: var(--text-muted); }
.matrix td.neg { color: var(--red); }
.matrix td.pos { color: var(--green); }
.matrix .zero { color: var(--text-muted); opacity: 0.5; }

.section-row td {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    padding-top: 1rem;
}
.group-row { cursor: pointer; }
.group-row td { font-weight: 600; }
.group-row:hover td { background: rgba(255, 255, 255, 0.035); }
.group-row:hover td.sticky { background: var(--surface-hover); }
.group-name::before {
    content: "\25B8";
    display: inline-block;
    margin-right: 0.4rem;
    color: var(--text-muted);
    transition: transform 0.15s var(--ease);
}
.group-row.open .group-name::before { transform: rotate(90deg); }
.share { color: var(--text-muted); font-weight: 400; font-size: 0.78rem; margin-left: 0.4rem; }
.cat-row td.sticky { padding-left: 1.7rem; color: var(--text-secondary); }
.cat-row.hidden { display: none; }
.total-row td { font-weight: 700; border-top: 1px solid var(--border); }
.total-row.grand td { border-top: 2px solid var(--border-strong); }
.total-row.net td { font-size: 0.9rem; }
.matrix-hint { margin-top: 0.8rem; }
.matrix-hint a { color: var(--accent); text-decoration: none; }

/* ---------- Buttons (secondary) ---------- */

button.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-weight: 500;
}
button.ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-hover); }
button.ghost.danger:hover { color: var(--red); border-color: var(--red); background: transparent; }
td button.ghost { height: 28px; padding: 0 0.5rem; font-size: 0.8rem; display: inline-flex; align-items: center; justify-content: center; }
.icon-trash { display: block; }

.filter-form { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; align-items: center; }
.filter-info { margin-bottom: 0.8rem; }
.range-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }

.button-link {
    display: inline-flex;
    align-items: center;
    height: 40px;
    padding: 0 1.3rem;
    margin-top: 0.9rem;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    transition: background 0.15s var(--ease);
}
.button-link:hover { background: var(--accent-hover); }

/* ---------- Login ---------- */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.login-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: 100%;
    max-width: 360px;
    padding: 2.3rem 2rem;
    box-shadow: var(--shadow), var(--edge);
}
.login-card .brand { font-size: 1.35rem; }
.login-card h2 { margin-bottom: 0.3rem; font-weight: 600; font-size: 1.15rem; }
.login-error { color: var(--red); font-size: 0.88rem; }

.logout { margin-left: auto; }
.logout button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    height: 34px;
    padding: 0 0.9rem;
    font-size: 0.85rem;
    font-weight: 500;
}
.logout button:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-hover); }

/* ============================================================
   Trading journal
   ============================================================ */

.trading-header { display: flex; align-items: baseline; gap: 1rem; margin: 0 0 1.4rem; flex-wrap: wrap; }
.trading-header h1 { margin: 0; font-size: 1.7rem; font-weight: 650; letter-spacing: -0.02em; }
.trading-grid { grid-template-columns: repeat(24, 1fr); }
.trading-grid .objectives-card,
.trading-grid .trading-chart, .trading-grid .trades-card,
.trading-grid .ledger-card { grid-column: 1 / -1; }
/* Four stat cards in one row (5+7+7+5 = 24). Trade Quality is as wide as By
   Instrument so its combined rows (streak, long/short) fit comfortably; Daily
   P/L is as narrow as By Weekday. */
.t-daily { grid-column: span 5; }
.t-quality { grid-column: span 7; }
.t-symbol { grid-column: span 7; }
.t-weekday { grid-column: span 5; }

.objectives-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    column-gap: 2.5rem;
    row-gap: 0.3rem;
}
.objective { margin-bottom: 1rem; }
.objective-head { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 0.4rem; gap: 1rem; }
.objective-head span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.objective .bar { background: var(--surface-2); border-radius: var(--radius-pill); height: 8px; overflow: hidden; }
.objective .bar-fill { height: 100%; border-radius: var(--radius-pill); }
.objective .bar-fill.green { background: var(--green); }
.objective .bar-fill.yellow { background: #d4a017; }
.objective .bar-fill.red { background: var(--red); }
.objective-note { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.3rem; font-variant-numeric: tabular-nums; }

/* Stat tables */
.mini-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.mini-table th { text-align: left; color: var(--text-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 0.3rem 0.7rem 0.3rem 0; white-space: nowrap; }
.mini-table td { padding: 0.4rem 0.7rem 0.4rem 0; border-top: 1px solid var(--border); white-space: nowrap; }
.mini-table th:last-child, .mini-table td:last-child { padding-right: 0; }
.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; }
/* Inner scroll wrapper: keeps card padding symmetric while letting a wide
   table (Recent Trades) scroll horizontally on narrow screens. */
.mini-scroll { overflow-x: auto; }
.trades-card .mini-table tbody tr { transition: background 0.12s var(--ease); }
.trades-card .mini-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.025); }
.trades-card .mini-table tbody tr:hover { background: rgba(255, 255, 255, 0.05); }

/* Equity chart — colours intentionally unchanged */
.trading-chart .equity-line { fill: none; stroke-width: 2; stroke-linejoin: miter; stroke-linecap: butt; }
.trading-chart .equity-line.pos { stroke: var(--green); }
.trading-chart .equity-line.neg { stroke: var(--red); }
.trading-chart .equity-fill.pos { fill: var(--green); opacity: 0.16; }
.trading-chart .equity-fill.neg { fill: var(--red); opacity: 0.28; }
.trading-chart .equity-dot { stroke: var(--surface); stroke-width: 1; }
.trading-chart .equity-dot.pos { fill: var(--green); }
.trading-chart .equity-dot.neg { fill: var(--red); }
.trading-chart .chart-grid { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 1 5; stroke-linecap: round; opacity: 0.45; }
.trading-chart .chart-label.x-label { text-anchor: middle; }
/* First/last date sit at the plot edges — anchor them inward so they aren't clipped. */
.trading-chart .chart-label.x-label.x-start { text-anchor: start; }
.trading-chart .chart-label.x-label.x-end { text-anchor: end; }
.trading-chart .chart-zero { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.5; }

/* Hover layer: invisible per-day columns reveal a marker + value tooltip.
   overflow:visible lets tooltips near the edges show without being clipped. */
.trading-chart .chart { overflow: visible; }
.trading-chart .pt-hit { fill: transparent; pointer-events: all; }
.trading-chart .pt-reveal { opacity: 0; pointer-events: none; transition: opacity 0.1s var(--ease); }
.trading-chart .chart-pt:hover .pt-reveal { opacity: 1; }
.trading-chart .pt-dot { stroke: var(--surface); stroke-width: 1.5; }
.trading-chart .pt-dot.pos { fill: var(--green); }
.trading-chart .pt-dot.neg { fill: var(--red); }
.trading-chart .tip-box { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1; }
.trading-chart .tip-date { fill: var(--text-muted); font-size: 10px; }
.trading-chart .tip-val { font-size: 12.5px; font-weight: 700; }
.trading-chart .tip-val.pos { fill: var(--green); }
.trading-chart .tip-val.neg { fill: var(--red); }

/* Account tabs — scrollable strip, scales to any number of accounts */
.trading-tabs {
    display: flex;
    gap: 0.4rem;
    margin-left: auto;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.trading-tabs::-webkit-scrollbar { display: none; }
.trading-tabs a {
    padding: 0.35rem 0.95rem;
    border-radius: var(--radius-pill);
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    flex: 0 0 auto;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.15s var(--ease);
}
.trading-tabs a:hover { color: var(--text); border-color: var(--border-strong); }
.trading-tabs a.active { color: #fff; background: var(--accent); border-color: var(--accent); }

/* Account-Nav: Gesamt | Live ▾ | Archiviert ▾ — Live/Archiviert sind Gruppen,
   deren Konten beim Hovern (oder Fokus, für Touch/Tastatur) darunter aufklappen.
   overflow:visible, damit das Dropdown nicht am Scroll-Container abgeschnitten wird. */
/* Umbruch statt Scroll: die Phasen-Tabs dürfen nie über den Rand ragen
   (overflow:visible bleibt für die Dropdowns). */
.account-tabs { overflow: visible; flex-wrap: wrap; row-gap: 0.4rem; }
.tab-group { position: relative; display: inline-flex; flex: 0 0 auto; }
.tab-group .group-head { display: inline-flex; align-items: center; gap: 0.3rem; }
.tab-group .caret { font-size: 0.66em; opacity: 0.6; transition: transform 0.15s var(--ease); }
.tab-group:hover .caret, .tab-group:focus-within .caret { transform: translateY(1px); opacity: 0.9; }
.tab-group.archived .group-head { color: var(--text-secondary); opacity: 0.7; }
.tab-group.archived .group-head.active { opacity: 1; color: #fff; background: var(--text-secondary); border-color: var(--text-secondary); }
/* Funded = echtes Geld → grün abgesetzt als Leit-Gruppe */
.tab-group.funded .group-head { color: var(--green); border-color: var(--green); }
.tab-group.funded .group-head.active { color: #fff; background: var(--green); border-color: var(--green); }

.tab-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.4rem;
    min-width: 160px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s var(--ease), transform 0.15s var(--ease), visibility 0.15s;
    z-index: 30;
}
.tab-group:hover .tab-dropdown, .tab-group:focus-within .tab-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.tab-dropdown a { border-color: transparent; background: var(--surface-2, transparent); }

/* Time-range strip: its own full-width row below the account tabs */
.range-tabs { flex-basis: 100%; margin-left: 0; margin-top: 0.4rem; }
.range-tabs a { padding: 0.25rem 0.8rem; font-size: 0.8rem; }

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-pill);
    background: var(--accent-tint);
    color: var(--accent-hover);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
/* Abschluss-Badge für archivierte Konten (neutral/rot statt Accent) */
.status-badge.archived { background: var(--neg-tint, rgba(220, 70, 70, 0.14)); color: var(--neg, #d24646); }

.kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.6rem;
}
/* Kacheln dürfen unter ihre Zahlenbreite schrumpfen, sonst sprengt eine lange
   Zahl die Spalte und damit die Seitenbreite. */
.kpi-strip > * { min-width: 0; }
.kpi-tile .kpi-value { overflow-wrap: anywhere; }
.kpi-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    box-shadow: var(--shadow-sm), var(--edge);
}
.kpi-tile .kpi-value { font-size: 1.4rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-tile.primary { box-shadow: var(--shadow-sm), var(--edge), inset 0 0 0 1px var(--accent); border-color: transparent; }

/* ---------- News / alert feed ---------- */
.alert-feed { display: flex; flex-direction: column; gap: 0.85rem; }
.alert-item {
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.alert-feed.compact .alert-item { padding: 0.6rem 0.85rem; background: transparent; }
/* Meta line first (severity always flush-left so it lines up across cards),
   then badges, then headline. */
.alert-meta { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.alert-meta .sev { color: var(--red); letter-spacing: 1px; }
.alert-meta .sev-num { color: var(--text-secondary); font-weight: 600; }
.alert-item .sym-badges { margin-bottom: 0.5rem; }
.sym-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.sym-badge {
    font-size: 0.8rem; font-weight: 600; white-space: nowrap;
    padding: 0.15rem 0.55rem; border-radius: var(--radius-pill);
    background: var(--surface); border: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.sym-badge.up { color: var(--green); border-color: rgba(52, 211, 153, 0.45); }
.sym-badge.down { color: var(--red); border-color: rgba(248, 113, 113, 0.45); }
.alert-headline {
    display: block; color: var(--text); text-decoration: none;
    font-weight: 600; font-size: 0.98rem; line-height: 1.35;
}
.alert-headline:hover { color: var(--accent); }
.alert-headline.sm { font-weight: 500; font-size: 0.92rem; }
.alert-direction { color: var(--text-secondary); font-size: 0.88rem; margin-top: 0.35rem; }
.alert-action {
    margin-top: 0.5rem; font-size: 0.9rem; font-weight: 500;
    background: var(--accent-tint); border-radius: var(--radius-sm);
    padding: 0.45rem 0.65rem;
}

/* ============================================================
   Responsive / mobile
   ============================================================ */

@media (max-width: 760px) {
    .content { padding: 1.25rem 1rem 2.5rem; }

    /* Collapse nav into a blurred dropdown panel toggled by the burger */
    .nav-burger {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 40px;
        height: 40px;
        margin-left: auto;
        cursor: pointer;
        border-radius: var(--radius-sm);
    }
    .nav-burger span {
        display: block;
        height: 2px;
        width: 20px;
        margin: 0 auto;
        background: var(--text);
        border-radius: 2px;
        transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
    }
    .topnav {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0.5rem 1rem 1rem;
        background: rgba(10, 10, 14, 0.92);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        backdrop-filter: saturate(180%) blur(20px);
        border-bottom: 1px solid var(--border);
        transform: translateY(-130%);
        transition: transform 0.25s var(--ease);
        z-index: 40;
    }
    .topnav a { padding: 0.85rem 0.25rem; border-bottom: 1px solid var(--border); font-size: 1rem; }
    .logout { margin: 0.8rem 0 0; }
    .logout button { width: 100%; height: 42px; }

    .nav-toggle:checked ~ .topnav { transform: translateY(0); }
    .nav-toggle:checked ~ .nav-burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .nav-toggle:checked ~ .nav-burger span:nth-child(2) { opacity: 0; }
    .nav-toggle:checked ~ .nav-burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    .page-head h1, .trading-header h1 { font-size: 1.4rem; }
    /* Etwas kompaktere KPI-Kacheln, damit lange Zahlen sicher passen */
    .kpi-strip { gap: 0.7rem; }
    .kpi-tile { padding: 0.85rem 1rem; }
    .kpi-tile .kpi-value { font-size: 1.25rem; }
    .widget-row { gap: 1.5rem; }
    .bar-row { grid-template-columns: 100px 1fr 78px; font-size: 0.82rem; }
    .card { padding: 1.15rem 1.15rem; }

    /* Tabs füllen auf dem Handy eine eigene volle Zeile (kein Rechts-Push,
       Umbruch statt Überlauf) */
    .trading-tabs { margin-left: 0; width: 100%; }

    /* Collapse the 6-column trading grid to a single column */
    .trading-grid { grid-template-columns: 1fr; }
    .trading-grid > * { grid-column: 1 / -1; }

    /* Budget transactions: too wide for phones as a table — render each entry
       as a stacked card (category + amount on top, date below, source hidden). */
    .tx-table, .tx-table tbody { display: block; width: 100%; }
    .tx-table thead { display: none; }
    .tx-table tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        column-gap: 0.6rem;
        row-gap: 0.1rem;
        align-items: start;
        padding: 0.7rem 0;
        border-top: 1px solid var(--border);
    }
    .tx-table td { padding: 0; border: none; white-space: normal; }
    .tx-table td:nth-child(2) { grid-column: 1; grid-row: 1; font-weight: 600; }   /* category */
    .tx-table td:nth-child(4) {                                                    /* amount */
        grid-column: 2; grid-row: 1; text-align: right;
        font-weight: 700; white-space: nowrap;
    }
    .tx-table td:nth-child(1) {                                                    /* date */
        grid-column: 1; grid-row: 2; color: var(--text-muted); font-size: 0.8rem;
    }
    .tx-table td:nth-child(3) {                                                    /* description */
        grid-column: 1; grid-row: 3; color: var(--text-muted); font-size: 0.8rem;
    }
    .tx-table td:nth-child(3):empty { display: none; }
    .tx-table td:nth-child(5) { grid-column: 2; grid-row: 2; text-align: right; } /* delete */
    /* Full-width rows: "load more" button and the empty-state message */
    .tx-table td[colspan] { grid-column: 1 / -1; grid-row: auto; }
}

/* Tablet: two stat cards per row, each spanning half the 24-col grid */
@media (min-width: 761px) and (max-width: 1100px) {
    .t-daily, .t-quality, .t-symbol, .t-weekday { grid-column: span 12; }
}
