:root {
    color-scheme: light dark;
    --bg: #f5f4ef;
    --panel: #fff;
    --fg: #22251f;
    --muted: #666b64;
    --line: #dedfd7;
    --gold: #946b17
}

html[data-theme=dark] {
    --bg: #141714;
    --panel: #202520;
    --fg: #f1f2e9;
    --muted: #b3b9ad;
    --line: #3c443b;
    --gold: #e0ba63;
    color-scheme: dark
}

html[data-theme=light] {
    color-scheme: light
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 15px system-ui, sans-serif
}

main {
    max-width: 1000px;
    margin: auto;
    padding: 20px
}

header,
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap
}

h1 {
    font-size: 30px;
    margin: 5px 0 18px
}

h1 em {
    color: var(--gold);
    font-style: normal
}

h2 {
    font-size: 18px;
    margin: 24px 0 12px
}

small,
.muted,
#status {
    color: var(--muted)
}

button,
select {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--fg)
}

button {
    cursor: pointer
}

button:disabled {
    opacity: .5
}

#refresh {
    background: var(--gold);
    color: var(--bg);
    font-weight: 700
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 12px;
    margin: 12px 0
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
    overflow-wrap: anywhere
}

.grid .panel {
    margin: 0
}

.value {
    font-size: clamp(20px, 4vw, 29px);
    font-weight: 700;
    margin: 8px 0;
    font-variant-numeric: tabular-nums
}

.sub {
    font-size: 12px;
    color: var(--muted);
    margin: 5px 0
}

.healthrow {
    padding: 10px 0;
    border-bottom: 1px solid var(--line)
}

canvas {
    width: 100%;
    height: 230px;
    display: block
}

input[type=file] {
    max-width: 100%
}

@media(max-width:400px) {
    main {
        padding: 12px
    }

    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr))
    }

    .panel {
        padding: 12px
    }
}

.fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    gap: 12px;
    margin: 12px 0
}

.fields label {
    display: grid;
    gap: 5px;
    font-size: 13px
}

.fields input {
    width: 100%;
    min-width: 0;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--fg)
}

.chart-wrap {
    position: relative;
    margin-top: 12px
}

#forecastGraph {
    touch-action: pan-y;
    cursor: crosshair
}

#chartCursor {
    position: absolute;
    top: 35px;
    height: 140px;
    border-left: 1px dashed #3985d0;
    pointer-events: none
}

#chartCursor:after {
    content: '';
    position: absolute;
    top: calc(var(--point-y) - 35px);
    left: 0;
    width: 10px;
    height: 10px;
    border: 2px solid var(--panel);
    border-radius: 50%;
    background: #3985d0;
    transform: translate(-50%, -50%)
}

.inspect-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 14px
}

.inspect-toolbar button {
    flex: none;
    font-size: 24px;
    padding: 8px 12px
}

#graphHover {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    background: var(--bg);
    min-height: 92px
}

.inspect-date,
.inspect-detail {
    font-size: 12px;
    color: var(--muted)
}

.inspect-price {
    font-size: clamp(19px, 5vw, 28px);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin: 4px 0
}

.forecast-jumps {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 12px 0
}

.forecast-jumps button {
    flex: 1;
    min-width: 60px;
    padding: 8px;
    font-size: 13px
}

.forecast-jumps button:disabled {
    opacity: .4;
    cursor: default
}

.buy-notice {
    border-left: 3px solid var(--gold);
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 5px
}

#buying .fields select {
    width: 100%;
    min-width: 0
}

#buying h2 {
    margin-top: 0
}

.notes-label {
    display: grid;
    gap: 8px;
    margin: 12px 0
}

.notes-label textarea {
    box-sizing: border-box;
    width: 100%;
    resize: vertical;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
    font: inherit
}

#newsCards article {
    min-width: 0;
    overflow-wrap: anywhere
}

#newsCards a {
    color: var(--fg)
}

/* Phase 6 dashboard */
:root {
    --bg: #f6f5f0;
    --panel: #fff;
    --fg: #202722;
    --muted: #59645d;
    --line: #dce2d9;
    --gold: #8b6214
}

html[data-theme=dark] {
    --bg: #101713;
    --panel: #1b251f;
    --fg: #edf2e9;
    --muted: #b3c0b5;
    --line: #35463b;
    --gold: #e6bf70
}

main {
    max-width: 1200px;
    padding: 24px
}

header {
    border-bottom: 1px solid var(--line);
    margin-bottom: 16px
}

h1 {
    font-size: clamp(26px, 5vw, 38px);
    letter-spacing: -1.3px
}

.header-actions {
    display: flex;
    gap: 8px
}

.panel {
    border-radius: 18px;
    padding: 20px;
    min-width: 0
}

#dashboard>div {
    scroll-margin-top: 76px;
    margin-bottom: 24px
}

#dashboardNav {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    background: var(--bg);
    padding: 12px 0;
    margin: 12px 0;
    border-bottom: 1px solid var(--line)
}

#dashboardNav a {
    white-space: nowrap;
    text-decoration: none;
    color: var(--fg);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 13px
}

.layout-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    padding: 8px 0
}

.layout-row label {
    flex: 1
}

.layout-row button {
    min-width: 44px
}

#layoutControls {
    margin: 12px 0
}

button,
select,
input {
    max-width: 100%
}

button,
select {
    min-height: 44px
}

button:focus-visible,
a:focus-visible,
select:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px
}

[hidden] {
    display: none !important
}

html[data-analysis=simple] #dashboard [data-section=forecast] details {
    display: none
}

html[data-analysis=simple] #ledgerRows,
html[data-analysis=simple] #modelDetails {
    display: none
}

#newsCards {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr))
}

#developerPanel summary {
    cursor: pointer;
    font-weight: 700
}

#developerPanel summary+label {
    display: block;
    margin: 12px 0
}

canvas {
    max-width: 100%
}

@media(max-width:600px) {
    main {
        padding: 12px
    }

    .panel {
        padding: 14px
    }

    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px
    }

    .fields {
        grid-template-columns: repeat(2, minmax(0, 1fr))
    }

    .value {
        font-size: clamp(17px, 4.5vw, 24px)
    }

    #newsCards,
    #forecastCards,
    #buyWindows {
        grid-template-columns: 1fr
    }

    #dashboardNav {
        margin-inline: -12px;
        padding-inline: 12px
    }

    h2 {
        font-size: 18px
    }

    select {
        max-width: 100%;
        white-space: normal
    }

    #forecastSource {
        display: block;
        width: 100%;
        margin-top: 6px
    }
}

@media(max-width:350px) {

    .fields,
    .grid {
        grid-template-columns: 1fr
    }
}

/* Phase 6.1 internal tabs */
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 8px
}

#dashboardNav button {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 88px;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 12px
}

#dashboardNav button[aria-selected=true] {
    color: var(--gold);
    border-color: var(--gold);
    background: var(--panel);
    font-weight: 700
}

#dashboardNav {
    scrollbar-width: thin
}

#dashboard>div {
    margin-top: 16px
}

#settingsTools {
    margin-top: 16px
}

@media(max-width:600px) {
    main {
        padding-bottom: 100px
    }

    #dashboardNav {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--line);
        border-bottom: 0;
        z-index: 20;
        box-shadow: 0 -4px 16px #0002
    }

    #dashboardNav button {
        min-width: 76px;
        padding: 7px;
        font-size: 11px
    }

    header h1 {
        margin-bottom: 8px
    }
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0
}

.brand img {
    flex: none;
    width: 48px;
    height: 48px
}

@media(max-width:600px) {
    .brand img {
        width: 36px;
        height: 36px
    }

    .brand {
        gap: 7px
    }
}
:root { --forecast:#245fa3; --accent-bg:#f6eedb }
html[data-theme=dark] { --forecast:#8abbff; --accent-bg:#302c20 }
body { line-height:1.48 }
main { width:100%; max-width:1280px }
header { padding-block:12px }
h2 { font-size:clamp(21px,2vw,28px); line-height:1.2 }
h3 { font-size:17px; margin:1.4rem 0 .5rem }
.primary .panel { border-top:3px solid var(--gold); background:var(--accent-bg) }
.headline { font-size:clamp(24px,4vw,40px); font-weight:650; font-variant-numeric:tabular-nums; margin:.5rem 0 }
.summary { font-size:1.15rem; font-weight:600 }
#forecastCards { margin-block:18px; grid-template-columns:repeat(auto-fit,minmax(min(230px,100%),1fr)) }
#shortcuts { justify-content:flex-start }
details { padding:.7rem 0; border-top:1px solid var(--line) }
summary { cursor:pointer; font-weight:600; padding:.4rem 0 }
#dashboard select, #dashboard input, textarea { min-width:0 }
#historyPoint { width:min(100%,36rem) }
#goldMini,#fxMini { height:180px }
:focus-visible { outline:2px solid var(--forecast); outline-offset:2px }
#layoutSettings label,#settingsTools label { display:inline-block;margin:.4rem }
@media(max-width:600px){
 main { padding-bottom:calc(112px + env(safe-area-inset-bottom)) }
 #dashboardNav { border-top:2px solid var(--line) }
 #dashboardNav::after { content:'›';position:sticky;right:0;align-self:center;color:var(--gold);background:var(--panel);padding:2px;font-weight:bold;pointer-events:none }
 #dailyRates { grid-template-columns:1fr }
 #dailyRates .panel {display:grid;grid-template-columns:minmax(0,1fr) auto;column-gap:8px}
 #dailyRates .sub {grid-column:1/-1}
 input:not([type=checkbox]),textarea {font-size:16px}
 .panel {padding:14px}
}
@media(prefers-reduced-motion:reduce){* {scroll-behavior:auto!important;transition:none!important}}
