/* ==========================================================================
   DCA Calc — shared design system
   One stylesheet for all three pages. Dark, flat, data-first.
   ========================================================================== */

:root {
    /* Neutral ramp */
    --bg:          #0b0d10;
    --surface:     #14171c;
    --surface-2:   #191d23;
    --line:        #23272e;
    --line-strong: #313742;

    --ink:         #e7e9ec;
    --ink-2:       #9aa4af;
    --ink-3:       #6b7480;

    /* Single accent, used sparingly: focus rings, active nav, BTC series */
    --accent:      #f7931a;
    --accent-dim:  rgba(247, 147, 26, 0.14);

    /* Data series — muted, distinguishable, not neon */
    --c-btc:   #f7931a;
    --c-gold:  #cfa63f;
    --c-land:  #57a97b;
    --c-fund:  #6d8bd0;
    --c-bank:  #7f8b98;
    --c-cash:  #3d97a8;

    /* Semantic */
    --pos:     #46b881;
    --neg:     #e05f6b;
    --warn:    #d99a45;

    --radius:    10px;
    --radius-sm: 6px;

    --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
    --sans: 'IBM Plex Sans Thai', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px 72px; }

/* --------------------------------------------------------------- masthead */

.masthead {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 28px 0 18px;
}

.brand { display: flex; align-items: baseline; gap: 12px; }

.brand-name {
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink);
    text-decoration: none;
}

.brand-page { font-size: 14px; color: var(--ink-3); }

/* Segmented nav */
.nav {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.nav a {
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13.5px;
    color: var(--ink-2);
    text-decoration: none;
    white-space: nowrap;
}

.nav a:hover { color: var(--ink); background: var(--surface-2); }

.nav a[aria-current="page"] {
    color: var(--bg);
    background: var(--ink);
    font-weight: 500;
}

/* ------------------------------------------------------------ page intro */

.intro { margin: 0 0 22px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.intro h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.intro p { margin: 0; max-width: 62ch; color: var(--ink-2); font-size: 14px; }

/* ------------------------------------------------------------------ forms */

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 24px;
}

.panel-title {
    margin: 0 0 14px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
    gap: 14px 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }

.field > label { font-size: 13px; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }

input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 9px 11px;
    font-family: var(--mono);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    appearance: none;
}

select {
    /* room for the caret we draw ourselves */
    padding-right: 30px;
    background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                      linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}

input:focus-visible, select:focus-visible, button:focus-visible, .legend-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.check { display: flex; align-items: flex-start; gap: 9px; }
.check input { width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.check label { font-size: 13.5px; color: var(--ink); cursor: pointer; }

/* Slider-ish inline unit suffix */
.with-unit { position: relative; }
.with-unit .unit {
    position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
    font-family: var(--mono); font-size: 12px; color: var(--ink-3); pointer-events: none;
}
.with-unit input { padding-right: 44px; }

/* ------------------------------------------------------------------ stats */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
}

.stat { background: var(--surface); padding: 15px 16px; min-width: 0; }

.stat-label {
    display: flex; align-items: center; gap: 7px;
    font-size: 12.5px; color: var(--ink-2); margin-bottom: 7px;
}

.stat-value {
    font-family: var(--mono);
    font-size: 21px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.stat-value .cur { font-size: 14px; color: var(--ink-3); margin-left: 3px; }

.stat-meta {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

.stat-meta .sep { color: var(--ink-3); margin: 0 6px; }

/* Feature stat — the single answer a page exists to give */
.headline {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 24px;
}
.headline .k { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.headline .v {
    font-family: var(--mono); font-size: clamp(28px, 6vw, 40px);
    font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.headline .v .cur { font-size: 0.5em; color: var(--ink-3); font-weight: 400; }
.headline .facts {
    display: flex; flex-wrap: wrap; gap: 8px 26px;
    margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
    font-size: 13px; color: var(--ink-2);
}
.headline .facts b { color: var(--ink); font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Series swatch */
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }

/* ----------------------------------------------------------------- deltas */

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.tag {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 7px; border-radius: 4px;
    font-size: 11.5px; letter-spacing: 0.01em;
    border: 1px solid var(--line-strong); color: var(--ink-2);
}
.tag-est { border-color: rgba(217, 154, 69, 0.35); color: var(--warn); }
.tag-real { border-color: rgba(70, 184, 129, 0.3); color: var(--pos); }

/* ----------------------------------------------------------------- charts */

.section { margin-bottom: 28px; }

.section-head {
    display: flex; align-items: baseline; justify-content: space-between;
    flex-wrap: wrap; gap: 8px; margin-bottom: 12px;
}
.section-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.section-head p { margin: 0; font-size: 13px; color: var(--ink-3); max-width: 60ch; }

.chart-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}

.chart-tools {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 10px; margin-bottom: 12px;
}

.legend { display: flex; flex-wrap: wrap; gap: 6px; }

.legend-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 4px 9px;
    font-family: inherit; font-size: 12.5px;
    color: var(--ink-2);
    background: transparent;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    cursor: pointer;
}
.legend-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.legend-btn[aria-pressed="false"] { opacity: 0.42; }

.scale-toggle { display: flex; gap: 2px; padding: 2px; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 5px; }
.scale-toggle button {
    padding: 3px 10px; font-family: var(--mono); font-size: 11.5px;
    color: var(--ink-3); background: transparent; border: 0; border-radius: 3px; cursor: pointer;
}
.scale-toggle button[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); }

.canvas-holder { position: relative; height: 340px; }
.canvas-holder.tall { height: 400px; }

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

.table-scroll {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: auto;
    max-height: 460px;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th, td {
    padding: 9px 14px;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1px solid var(--line);
}

th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }

thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--surface-2);
    color: var(--ink-2);
    font-weight: 500;
    font-size: 12.5px;
}
thead th:first-child { z-index: 3; background: var(--surface-2); }

tbody td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
tbody td:first-child { font-family: var(--sans); color: var(--ink-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:hover td:first-child { background: var(--surface-2); }

tr.is-terminal td, tr.is-terminal td:first-child { background: rgba(224, 95, 107, 0.09); }
tr.is-note td { text-align: center; color: var(--ink-2); font-family: var(--sans); white-space: normal; }

/* -------------------------------------------------------------- callouts */

.note {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    font-size: 13.5px;
    color: var(--ink-2);
}
.note h3 { margin: 0 0 9px; font-size: 13px; font-weight: 600; color: var(--ink); }
.note ul { margin: 0; padding-left: 18px; }
.note li { margin-bottom: 5px; }
.note li:last-child { margin-bottom: 0; }
.note b { color: var(--ink); font-weight: 500; }
.note code { font-family: var(--mono); font-size: 12.5px; color: var(--ink); }

.note-warn { border-color: rgba(217, 154, 69, 0.3); }
.note-warn h3 { color: var(--warn); }

.disclaimer {
    margin-top: 28px; padding-top: 18px;
    border-top: 1px solid var(--line);
    font-size: 12.5px; line-height: 1.7; color: var(--ink-3);
}
.disclaimer b { color: var(--ink-2); font-weight: 500; }

.footer-meta {
    margin-top: 18px;
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--ink-3);
    display: flex; flex-wrap: wrap; gap: 6px 18px;
}

/* ------------------------------------------------------------ data status */

.status { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }

.chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 4px 10px;
    font-size: 12px;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
}
.chip .num { color: var(--ink); }
.chip-warn { border-color: rgba(217, 154, 69, 0.35); color: var(--warn); }
.chip-warn .num { color: var(--warn); }

/* ------------------------------------------------------------------ state */

.loading { padding: 64px 20px; text-align: center; color: var(--ink-3); font-size: 14px; }
.failed {
    padding: 20px;
    border: 1px solid rgba(224, 95, 107, 0.35);
    border-radius: var(--radius);
    background: rgba(224, 95, 107, 0.07);
    color: var(--ink);
    font-size: 14px;
}
[hidden] { display: none !important; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 720px) {
    body { font-size: 14.5px; }
    .wrap { padding: 0 14px 56px; }
    .masthead { padding: 18px 0 14px; }
    .nav { width: 100%; }
    .nav a { flex: 1; text-align: center; padding: 7px 4px; font-size: 13px; }
    .stat-value { font-size: 19px; }
    th, td { padding: 8px 10px; font-size: 12.5px; }
    .canvas-holder { height: 290px; }
    .canvas-holder.tall { height: 320px; }
    .headline { padding: 17px 18px; }
    .headline .facts { gap: 6px 18px; }
}

@media (prefers-reduced-motion: no-preference) {
    .legend-btn, .nav a, input, select { transition: color .12s, background-color .12s, border-color .12s, opacity .12s; }
}
