:root {
    --surface-1: #fcfcfb;
    --page-plane: #f9f9f7;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --gridline: #e1e0d9;
    --border-hairline: rgba(11, 11, 11, 0.10);
    --good: #0ca30c;
    --critical: #d03b3b;
    --series-blue: #2a78d6;
    --series-aqua: #1baf7a;
    --series-violet: #4a3aa7;
    --series-blue-wash: rgba(42, 120, 214, 0.10);
    --series-aqua-wash: rgba(27, 175, 122, 0.10);
    --series-violet-wash: rgba(74, 58, 167, 0.10);
    --neutral-wash: rgba(42, 120, 214, 0.08);
}

/* Dark theme: applied automatically when the OS prefers dark (unless the user has
   explicitly picked light via the toggle), and always when the toggle picks dark -
   the explicit [data-theme] attribute (set by theme-toggle.js) wins in both directions. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --surface-1: #1a1a19;
        --page-plane: #0d0d0d;
        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --gridline: #2c2c2a;
        --border-hairline: rgba(255, 255, 255, 0.10);
        --good: #0ca30c;
        --critical: #e66767;
        --series-blue: #3987e5;
        --series-aqua: #199e70;
        --series-violet: #9085e9;
        --series-blue-wash: rgba(57, 135, 229, 0.14);
        --series-aqua-wash: rgba(25, 158, 112, 0.14);
        --series-violet-wash: rgba(144, 133, 233, 0.14);
        --neutral-wash: rgba(57, 135, 229, 0.12);
    }
}

:root[data-theme="dark"] {
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border-hairline: rgba(255, 255, 255, 0.10);
    --good: #0ca30c;
    --critical: #e66767;
    --series-blue: #3987e5;
    --series-aqua: #199e70;
    --series-violet: #9085e9;
    --series-blue-wash: rgba(57, 135, 229, 0.14);
    --series-aqua-wash: rgba(25, 158, 112, 0.14);
    --series-violet-wash: rgba(144, 133, 233, 0.14);
    --neutral-wash: rgba(57, 135, 229, 0.12);
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: var(--page-plane);
    color: var(--text-primary);
}

.navbar {
    background-color: var(--surface-1);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.theme-toggle-btn {
    border: 1px solid var(--border-hairline);
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-btn svg {
    width: 18px;
    height: 18px;
}

.theme-toggle-btn .icon-sun { display: none; }
.theme-toggle-btn .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle-btn .icon-sun { display: block; }
    :root:not([data-theme="light"]) .theme-toggle-btn .icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle-btn .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle-btn .icon-moon { display: none; }

.navbar-brand {
    font-weight: 700;
    color: var(--series-blue);
    font-size: 1.4rem;
}

.navbar-brand span {
    color: var(--text-primary);
}

.quick-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: var(--surface-1);
    border-bottom: 1px solid var(--border-hairline);
    padding: 0.6rem 2rem;
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
}

.quick-nav a {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.quick-nav a:hover {
    color: var(--series-blue);
}

html {
    scroll-behavior: smooth;
}

.section-anchor {
    scroll-margin-top: 4.5rem;
}

.container-narrow {
    max-width: 1180px;
    margin: 0 auto;
    padding: 2rem 1rem 4rem;
}

.card-panel {
    background-color: var(--surface-1);
    border: 1px solid var(--border-hairline);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.hero-upload {
    max-width: 640px;
    margin: 3rem auto 0;
}

.hero-title {
    font-size: 2.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.hero-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.form-label {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
}

.helper-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.btn-primary {
    background-color: var(--series-blue);
    border-color: var(--series-blue);
    font-weight: 600;
}

.btn-primary:hover {
    background-color: #1c5cab;
    border-color: #1c5cab;
}

.btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border-hairline);
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.toolbar-meta {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-tile {
    background-color: var(--surface-1);
    border: 1px solid var(--border-hairline);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.info-hint {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid var(--text-muted);
    color: var(--text-muted);
    font-size: 0.65rem;
    cursor: help;
    margin-left: 0.25rem;
    vertical-align: middle;
}

/* A custom tooltip reading straight from the existing `title` attribute - the
   native browser tooltip these relied on before is inconsistent (a ~1s hover
   delay, and headless/automated testing can't see it at all since it's OS chrome,
   not part of the page), so this renders as normal DOM instead. */
.info-hint::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    max-width: 280px;
    width: max-content;
    background-color: var(--text-primary);
    color: var(--surface-1);
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 50;
}

.info-hint:hover::after {
    opacity: 1;
    visibility: visible;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-delta {
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.2rem;
}

.stat-delta.good { color: var(--good); }
.stat-delta.critical { color: var(--critical); }

.section-title {
    font-weight: 700;
    font-size: 1.15rem;
    margin-bottom: 0.25rem;
}

.section-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.chart-container {
    height: 320px;
    position: relative;
}

.value-good { color: var(--good); font-weight: 600; }
.value-critical { color: var(--critical); font-weight: 600; }

.warning-banner {
    background-color: rgba(250, 178, 25, 0.12);
    border: 1px solid rgba(250, 178, 25, 0.35);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.upload-widget {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.upload-widget input[type="file"] {
    max-width: 320px;
}

.range-presets {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.range-preset-btn {
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--border-hairline);
    background-color: transparent;
    color: var(--text-secondary);
}

.range-preset-btn.active {
    background-color: var(--series-blue);
    border-color: var(--series-blue);
    color: #fff;
}

.chart-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.reset-zoom-btn {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border-hairline);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
}

.reset-zoom-btn.active {
    color: #fff;
    background-color: var(--series-violet);
    border-color: var(--series-violet);
    font-weight: 600;
}

/* Bootstrap's own .form-control/.form-select ship a hardcoded white background,
   so every plain text/select/date input in the app (portfolio creation, capital
   ledger entry) would otherwise stay white-on-dark instead of following the
   theme, unlike the app's own custom-styled inputs (.date-range-input,
   .stop-loss-input) which already do. */
.form-control,
.form-select {
    background-color: var(--surface-1);
    border-color: var(--border-hairline);
    color: var(--text-primary);
    color-scheme: light dark;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--surface-1);
    color: var(--text-primary);
}

/* The placeholder pseudo-element doesn't inherit `color` - browsers give it their
   own low-contrast default (tuned for a white background), which is nearly
   invisible against the dark background just set above. */
.form-control::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.date-range-inputs {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: 0.25rem;
}

.date-range-input {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    border: 1px solid var(--border-hairline);
    background-color: var(--surface-1);
    color: var(--text-primary);
    color-scheme: light dark;
    cursor: pointer;
}

/* The native calendar icon is the whole point of type="date" - a trader should
   never need to type a date out by hand - but at this input's compact size the
   icon can be easy to miss/hard to hit. Make it bigger and obviously clickable. */
.date-range-input::-webkit-calendar-picker-indicator {
    cursor: pointer;
    padding: 2px;
    margin-left: 2px;
    opacity: 0.75;
}

.date-range-input::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.date-range-sep {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.date-range-go-btn {
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--series-blue);
    border: 1px solid var(--series-blue);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
}
