/* TheCreator dashboard — base styles + tab/modal/wallet extensions
   Single CSS file. No framework. */

:root {
    --color-text:        #222;
    --color-text-muted:  #666;
    --color-bg:          #fff;
    --color-bg-alt:      #f7f7f7;
    --color-bg-row-alt:  #fafbfc;
    --color-brand:       #1a5490;
    --color-brand-dark:  #134572;
    --color-live:        #c0392b;
    --color-paper:       #2980b9;
    --color-both:        #8e44ad;
    --color-success:     #27ae60;
    --color-error:       #c0392b;
    --color-warning:     #d97706;
    --color-border:      #ddd;
    --color-border-soft: #eee;
    --radius:            6px;
    --max-width:         1280px;
    --font-stack:        -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Hidden attribute must beat display:grid item rules */
[hidden] { display: none !important; }

body {
    font-family: var(--font-stack);
    color: var(--color-text);
    background: var(--color-bg);
    margin: 0;
    line-height: 1.5;
}
body.modal-open { overflow: hidden; }

a { color: var(--color-brand); text-decoration: none; }
a:hover { text-decoration: underline; }


/* ---- Login page ---- */
.login-page {
    background: var(--color-bg-alt);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: var(--color-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 360px;
}
.login-card h1 { color: var(--color-brand); margin: 0 0 4px 0; }
.login-tagline { color: var(--color-text-muted); margin: 0 0 24px 0; }
.login-card form { display: flex; flex-direction: column; gap: 16px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; }
.login-card label span {
    font-size: 13px;
    color: var(--color-text-muted);
    font-weight: 600;
}
.login-card input[type="password"] {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: inherit;
}
.login-card input[type="password"]:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgba(26, 84, 144, 0.15);
}
.login-card button {
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    background: var(--color-brand);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.login-card button:hover { background: var(--color-brand-dark); }
.login-card .hint {
    margin-top: 12px;
    font-size: 13px;
    color: var(--color-text-muted);
}
.error-msg {
    background: #fff3f0;
    border: 1px solid #ffd0c5;
    color: var(--color-error);
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}


/* ---- Dashboard layout ---- */
.topbar {
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 24px;
}
.brand { color: var(--color-brand); font-weight: 700; font-size: 18px; }
.brand:hover { text-decoration: none; }
.tabs { display: flex; gap: 0; flex: 1; }
.tab {
    padding: 0 16px;
    height: 56px;
    line-height: 56px;
    color: var(--color-text-muted);
    font-weight: 500;
    border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--color-text); text-decoration: none; }
.tab.active {
    color: var(--color-brand);
    border-bottom-color: var(--color-brand);
}
.topbar-actions { margin-left: auto; }
.logout-link { color: var(--color-text-muted); font-size: 14px; }
.content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 24px 20px;
    min-height: calc(100vh - 56px - 60px);
}
.tab-panel h2 { margin: 0 0 16px 0; color: var(--color-text); }
.placeholder {
    color: var(--color-text-muted);
    font-style: italic;
    padding: 40px;
    background: var(--color-bg-alt);
    border-radius: var(--radius);
    text-align: center;
}
.bottombar {
    border-top: 1px solid var(--color-border);
    padding: 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}


/* ---- Flash messages ---- */
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}
.flash-success {
    background: #ecf9f1;
    border: 1px solid #c8ecd6;
    color: #1f7a45;
}
.flash-error {
    background: #fff3f0;
    border: 1px solid #ffd0c5;
    color: var(--color-error);
}


/* ---- Tab header ---- */
.tab-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.summary-stats {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 90px;
}
.stat-label {
    font-size: 11px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.stat-value { font-size: 18px; font-weight: 600; }
.stat-value small {
    font-size: 12px;
    font-weight: 400;
    color: var(--color-text-muted);
    margin-left: 4px;
}


/* ---- Tables (positions + picks) ---- */
.positions-table,
.picks-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 8px;
}
.positions-table thead th,
.picks-table thead th {
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    font-weight: 600;
    text-align: left;
    padding: 10px 8px;
    border-bottom: 2px solid var(--color-border);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.4px;
    white-space: nowrap;
}
.positions-table tbody td,
.picks-table tbody td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--color-border-soft);
    vertical-align: top;
}
.positions-table tbody tr:nth-child(even),
.picks-table tbody tr:nth-child(even) {
    background: var(--color-bg-row-alt);
}
.positions-table .r,
.picks-table .r {
    text-align: right;
    white-space: nowrap;
}
.positions-table small,
.picks-table small {
    color: var(--color-text-muted);
    font-size: 11px;
}
.positions-table .pos,
.picks-table .pos { color: var(--color-success); font-weight: 600; }
.positions-table .neg,
.picks-table .neg { color: var(--color-error);   font-weight: 600; }

.positions-table-closed { margin-top: 12px; opacity: 0.92; }

.price-as-of {
    font-size: 10px;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Subscript under adjusted composite showing the original (pre-warning) value */
.composite-original {
    font-size: 10px;
    color: var(--color-text-muted);
    font-style: italic;
    font-weight: 400;
    display: inline-block;
    margin-top: 1px;
}
.composite-original.pos {
    color: var(--color-success);
}
.composite-original.neg {
    color: var(--color-error);
}

/* Picks tab specifics */
.picks-table .actions-col {
    width: 280px;
    text-align: right;
}
.picks-table .grade-row {
    font-size: 11px;
    color: var(--color-text-muted);
    background: transparent;
    padding: 0;
}
.picks-table tr.top-pick {
    background: #fef9e7 !important;   /* override row-alt */
}
.picks-table tr.top-pick td:first-child {
    border-left: 3px solid #f1c40f;
}


/* ---- Closed-positions toggle ---- */
.closed-section {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
}
.closed-section summary,
.history-day summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--color-text-muted);
    padding: 8px 0;
    user-select: none;
}
.closed-section summary:hover,
.history-day summary:hover { color: var(--color-text); }
.closed-section[open] summary,
.history-day[open] summary { color: var(--color-text); }


/* ---- Picks history ---- */
.picks-history {
    margin-top: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
}
.picks-history h3 {
    margin: 0 0 12px 0;
    color: var(--color-text);
}
.history-day {
    margin-bottom: 4px;
    border-bottom: 1px solid var(--color-border-soft);
}
.history-day-meta {
    color: var(--color-text-muted);
    font-weight: 400;
    margin-left: 12px;
    font-size: 13px;
}
.picks-history-table {
    margin-bottom: 12px;
}


/* ---- Picks-tab top-pick visuals ---- */
.recommendation-callout {
    background: #fef9e7;
    border: 1px solid #f1c40f;
    border-left: 4px solid #f1c40f;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
    color: #7a5d00;
}
.recommendation-callout strong { color: #5a4500; }
.recommendation-callout a { color: var(--color-brand); }

.top-pick-badge {
    display: inline-block;
    margin-left: 4px;
    color: #d4ac0d;
    font-size: 14px;
    cursor: help;
    vertical-align: middle;
}


/* ---- Integrity badges (solid count pills, no animation) ---- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 800;
    margin-left: 6px;
    cursor: help;
    vertical-align: middle;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border: none;
    color: white;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                0 1px 2px rgba(0, 0, 0, 0.08);
}
.badge-warning {
    background: #d97706;   /* burnt orange — neutral/unknown direction */
}
.badge-warning-bad {
    background: #c0392b;   /* strong red — negative direction (EPS down, dilution) */
}
.badge-warning-good {
    background: #16a34a;   /* strong green — positive direction (EPS up, buyback) */
}
.badge-alert {
    background: #c0392b;   /* strong red */
}

/* Gentle pulse for warnings — subtle scale + soft glow */
@keyframes badge-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 0 rgba(217, 119, 6, 0.5);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 6px rgba(217, 119, 6, 0);
    }
}

/* Negative-direction warning — same gentle pulse with red glow */
@keyframes badge-pulse-bad {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 0 rgba(192, 57, 43, 0.5);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 6px rgba(192, 57, 43, 0);
    }
}

/* Positive-direction warning — same gentle pulse with green glow */
@keyframes badge-pulse-good {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 0 rgba(22, 163, 74, 0.5);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 6px rgba(22, 163, 74, 0);
    }
}

/* Stronger, faster pulse for alerts — bigger scale + red glow */
@keyframes badge-pulse-strong {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 0 rgba(192, 57, 43, 0.7);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1),
                    0 1px 2px rgba(0, 0, 0, 0.08),
                    0 0 0 8px rgba(192, 57, 43, 0);
    }
}

/* Respect users who've asked for reduced motion in their OS settings */
@media (prefers-reduced-motion: reduce) {
    .badge, .badge-alert, .badge-warning-bad, .badge-warning-good {
        animation: none;
    }
}


/* ---- Status pills (already-acted candidates) ---- */
.status-pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.status-acted {
    background: #d1f0e0;
    color: #1f7a45;
}
.status-dismissed {
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}


/* ---- Trade-type pill (in modal title) ---- */
.trade-type-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    background: var(--color-text-muted);
    color: white;
    margin-left: 8px;
    vertical-align: middle;
}
.trade-type-pill-paper { background: var(--color-paper); }
.trade-type-pill-live  { background: var(--color-live); }
.trade-type-pill-both  { background: var(--color-both); }


/* ---- Row action buttons ---- */
.action-cluster,
.row-action-cluster {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}
.actions-col-narrow { width: 140px; }

.btn-row-action {
    padding: 4px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: white;
    color: var(--color-text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn-row-action:hover { background: var(--color-bg-alt); }

.btn-danger-outline {
    color: var(--color-error);
    border-color: #fca5a5;
}
.btn-danger-outline:hover { background: #fff3f0; }

.btn-delete-outline {
    color: var(--color-error);
    border-color: #fca5a5;
}
.btn-delete-outline:hover { background: #fff3f0; }

.btn-primary-outline {
    color: var(--color-brand);
    border-color: #b8d1e8;
}
.btn-primary-outline:hover { background: #f0f7fc; }

.btn-undo-outline {
    color: var(--color-text-muted);
    border-color: var(--color-border);
    font-size: 11px;
    padding: 2px 8px;
}
.btn-undo-outline:hover {
    color: var(--color-text);
    background: var(--color-bg-alt);
}

.btn-paper {
    color: white;
    background: var(--color-paper);
    border-color: var(--color-paper);
}
.btn-paper:hover { background: #2271a3; border-color: #2271a3; }
.btn-live {
    color: white;
    background: var(--color-live);
    border-color: var(--color-live);
}
.btn-live:hover { background: #a83226; border-color: #a83226; }
.btn-both {
    color: white;
    background: var(--color-both);
    border-color: var(--color-both);
}
.btn-both:hover { background: #76399a; border-color: #76399a; }
.btn-dismiss {
    color: var(--color-text-muted);
}
.btn-dismiss:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.inline-form {
    display: inline;
    margin: 0;
    padding: 0;
}


/* ---- Modal ---- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}
.modal-card {
    position: relative;
    background: var(--color-bg);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.modal-card-wide   { max-width: 720px; }
.modal-card-narrow { max-width: 460px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border-soft);
}
.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
}
.modal-close:hover { color: var(--color-text); }

.modal-body { padding: 20px; }
.modal-summary {
    margin: 0 0 16px 0;
    padding: 8px 12px;
    background: var(--color-bg-alt);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--color-text-muted);
}
.danger-summary {
    background: #fef3f2;
    border: 1px solid #ffd0c5;
    color: #7c1d12;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.form-grid label,
.modal-body label.full-width {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-grid label.full-width,
.modal-body label.full-width {
    grid-column: 1 / -1;
    margin-top: 12px;
}
.form-grid label span,
.modal-body label.full-width span {
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.modal-body input[type="number"],
.modal-body input[type="date"],
.modal-body input[type="text"],
.modal-body select,
.modal-body textarea {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
}
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgba(26, 84, 144, 0.12);
}
.modal-body small.hint {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* Trade-type sections in entry modal */
.trade-section {
    margin-top: 16px;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.trade-section legend {
    padding: 0 8px;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.paper-section {
    border-color: var(--color-paper);
    background: rgba(41, 128, 185, 0.04);
}
.paper-section legend { color: var(--color-paper); }
.live-section {
    border-color: var(--color-live);
    background: rgba(192, 57, 43, 0.04);
}
.live-section legend { color: var(--color-live); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--color-border-soft);
    background: var(--color-bg-alt);
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}
.btn-secondary,
.btn-danger,
.btn-primary {
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    border: 1px solid var(--color-border);
}
.btn-secondary {
    background: white;
    color: var(--color-text);
}
.btn-secondary:hover { background: var(--color-bg-alt); }
.btn-danger {
    background: var(--color-error);
    color: white;
    border-color: var(--color-error);
}
.btn-danger:hover { background: #a83226; border-color: #a83226; }
.btn-primary {
    background: var(--color-brand);
    color: white;
    border-color: var(--color-brand);
}
.btn-primary:hover { background: var(--color-brand-dark); border-color: var(--color-brand-dark); }


/* ==================================================================== */
/* CAPITAL TAB — wallet cards + ledger (Item 9.4)                       */
/* ==================================================================== */
.wallets-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 8px;
}

.wallet-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    background: var(--color-bg);
}
.wallet-card-paper { border-top: 3px solid var(--color-paper); }
.wallet-card-live  { border-top: 3px solid var(--color-live); }

.wallet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border-soft);
}
.wallet-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}
.wallet-actions {
    display: flex;
    gap: 6px;
}

.wallet-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
.stat-headline .stat-value {
    font-size: 22px;
    font-weight: 700;
}

.wallet-details {
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 20px;
    background: var(--color-bg-alt);
}
.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    font-size: 13px;
}
.detail-label {
    color: var(--color-text-muted);
}
.detail-label small {
    font-size: 11px;
    margin-left: 4px;
}
.detail-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.detail-value small {
    font-size: 11px;
    margin-left: 4px;
    color: var(--color-text-muted);
    font-weight: 400;
}
.detail-row-total {
    border-top: 1px solid var(--color-border);
    margin-top: 6px;
    padding-top: 8px;
    font-size: 14px;
}

.ledger-heading {
    margin: 16px 0 8px 0;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--color-text-muted);
    font-weight: 700;
}

.ledger-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.ledger-table thead th {
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    font-weight: 600;
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.4px;
}
.ledger-table tbody td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border-soft);
    vertical-align: top;
}
.ledger-table .r {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.ledger-table .pos { color: var(--color-success); font-weight: 600; }
.ledger-table .neg { color: var(--color-error);   font-weight: 600; }

.ledger-type-pill {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--color-border-soft);
    color: var(--color-text-muted);
}
.ledger-deposit .ledger-type-pill {
    background: #d1f0e0;
    color: #1f7a45;
}
.ledger-withdrawal .ledger-type-pill {
    background: #fde2e2;
    color: var(--color-error);
}
.ledger-position-open .ledger-type-pill {
    background: #fff3e0;
    color: var(--color-warning);
}
.ledger-position-close .ledger-type-pill {
    background: #e0ebf5;
    color: var(--color-brand);
}

.placeholder-small {
    padding: 16px;
    font-size: 12px;
}


/* ---- Mobile ---- */
@media (max-width: 1000px) {
    .wallets-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
    .topbar-inner {
        height: auto;
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 12px;
    }
    .tabs {
        order: 3;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
    .tab {
        height: 40px;
        line-height: 40px;
        padding: 0 12px;
    }
    .topbar-actions { order: 2; }
    .crash-risk-pill { order: 2; margin-left: auto; }
    .content { padding: 16px; }
    .summary-stats { gap: 16px; }
    .positions-table, .picks-table { font-size: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .picks-table .actions-col { width: auto; }
}


/* ====================================================================
   CRASH-RISK NAVBAR PILL + POPOVER + HELP MODAL
   ==================================================================== */

/* The .tabs flex row should not eat all the space so the pill has room
   on its right. Override flex:1 to flex:0 so it sizes to its content,
   then the pill pushes hard right via its own margin-left: auto. */
.tabs { flex: 0 1 auto; }

/* Sign-out tab is an action, not a destination — sits muted in the row
   and doesn't try to look "active". */
.tab-signout {
    color: var(--color-text-muted);
    font-weight: 400;
}
.tab-signout:hover {
    color: var(--color-text);
    border-bottom-color: transparent;
}


/* ---- Pill (lives in navbar) ---- */
.crash-risk-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 8px 0 4px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    margin-left: auto;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}
.crash-risk-pill:hover {
    background: var(--color-bg-alt);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.crash-risk-pill:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}
.crash-risk-pill-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 28px;
    padding: 0 6px;
    border-radius: 999px;
    color: white;
    font-weight: 700;
    font-size: 13px;
}
.crash-risk-pill-state {
    font-weight: 600;
    color: var(--color-text);
}
.crash-risk-pill-caret {
    color: var(--color-text-muted);
    font-size: 10px;
    margin-left: 2px;
    transition: transform 0.15s;
}
.crash-risk-pill[aria-expanded="true"] .crash-risk-pill-caret {
    transform: rotate(180deg);
}

/* Pulse animation for elevated states — peripheral-vision warning */
@keyframes crash-risk-pill-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.45); }
    50%      { box-shadow: 0 0 0 8px rgba(192, 57, 43, 0); }
}
.crash-risk-pill-pulsing {
    border-color: var(--color-error);
    animation: crash-risk-pill-pulse 1.6s ease-in-out infinite;
}
.crash-risk-pill-state-critical {
    border-color: var(--color-error);
}
.crash-risk-pill-state-critical .crash-risk-pill-state { color: var(--color-error); }


/* ---- Popover (full widget anchored under pill) ---- */
.crash-risk-popover {
    position: absolute;
    z-index: 100;
    width: 720px;
    max-width: calc(100vw - 32px);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
}
.crash-risk-popover::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 24px;
    width: 12px;
    height: 12px;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    border-left: 1px solid var(--color-border);
    transform: rotate(45deg);
}

.crash-risk-top {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 18px;
    align-items: center;
    margin-bottom: 14px;
}

.crash-risk-composite {
    width: 76px;
    height: 76px;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}
.crash-risk-composite-num { font-size: 30px; font-weight: 600; line-height: 1; }
.crash-risk-composite-lab { font-size: 11px; opacity: 0.85; margin-top: 3px; }

.crash-risk-state { min-width: 0; }
.crash-risk-state-name { font-size: 19px; font-weight: 600; line-height: 1.2; }
.crash-risk-state-detail { font-size: 13px; color: var(--color-text-muted); margin-top: 3px; }
.crash-risk-state-asof { font-size: 11px; color: var(--color-text-muted); opacity: 0.7; margin-top: 4px; }

.crash-risk-verdict {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--color-bg-alt);
    color: var(--color-text);
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
}
.crash-risk-verdict-icon { font-weight: 700; }
.crash-risk-state-all_clear  .crash-risk-verdict { background: #ecf9f1; color: #1f7a45; }
.crash-risk-state-watch      .crash-risk-verdict { background: #e0f2fe; color: #075985; }
.crash-risk-state-elevated   .crash-risk-verdict { background: #fef3c7; color: #92400e; }
.crash-risk-state-high_alert .crash-risk-verdict { background: #fef0e6; color: #9a3412; }
.crash-risk-state-critical   .crash-risk-verdict { background: #fee2e2; color: #991b1b; }


/* ---- Sub-score chips (inside popover) ---- */
.crash-risk-chips {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}
.crash-risk-chip {
    border-radius: var(--radius);
    padding: 8px 6px;
    text-align: center;
    border: 1px solid var(--color-border-soft);
    position: relative;
    overflow: hidden;
    background: var(--color-bg);
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
}
.crash-risk-chip:hover,
.crash-risk-verdict:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.crash-risk-chip:active,
.crash-risk-verdict:active { transform: scale(0.98); }
.crash-risk-chip:focus-visible,
.crash-risk-verdict:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}

.crash-risk-chip-name { font-size: 11px; color: var(--color-text-muted); margin-bottom: 4px; font-weight: 600; }
.crash-risk-chip-score { font-size: 18px; font-weight: 600; line-height: 1; }
.crash-risk-chip-bar {
    height: 3px;
    background: var(--color-bg-alt);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}
.crash-risk-chip-bar-fill { height: 100%; border-radius: 2px; }

@keyframes crash-risk-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.55); border-color: var(--color-error); }
    50%      { box-shadow: 0 0 0 5px rgba(192, 57, 43, 0); border-color: #e67165; }
}
.crash-risk-chip-flashing {
    animation: crash-risk-pulse 1.4s ease-in-out infinite;
    border-width: 2px;
}

/* Failed — red corner ribbon */
.crash-risk-chip-status-failed {
    background: var(--color-bg-alt);
    border-color: var(--color-error);
}
.crash-risk-chip-status-failed::before {
    content: 'NO DATA';
    position: absolute;
    top: 7px;
    right: -24px;
    background: var(--color-error);
    color: white;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 26px;
    transform: rotate(45deg);
}
.crash-risk-chip-status-failed .crash-risk-chip-score { color: var(--color-text-muted); }

/* Stale — amber corner ribbon */
.crash-risk-chip-status-stale {
    background: var(--color-bg-alt);
    border-color: var(--color-warning);
}
.crash-risk-chip-status-stale::before {
    content: 'STALE';
    position: absolute;
    top: 6px;
    right: -24px;
    background: var(--color-warning);
    color: white;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 26px;
    transform: rotate(45deg);
}
.crash-risk-chip-status-stale .crash-risk-chip-bar-fill { opacity: 0.6; }

/* Disabled — grey "not wired" corner ribbon */
.crash-risk-chip-status-disabled {
    background: var(--color-bg-alt);
    border-color: var(--color-border);
    border-style: dashed;
    opacity: 0.7;
}
.crash-risk-chip-status-disabled::before {
    content: 'NOT WIRED';
    position: absolute;
    top: 6px;
    right: -28px;
    background: #8a8a8a;
    color: white;
    font-size: 7px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 30px;
    transform: rotate(45deg);
}
.crash-risk-chip-status-disabled .crash-risk-chip-score {
    color: var(--color-text-muted);
    font-size: 14px;
}


/* ---- Lead-time line ---- */
.crash-risk-leadtime {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--color-border-soft);
    font-size: 12px;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.crash-risk-leadtime strong { font-weight: 600; color: var(--color-text); }
.crash-risk-leadtime-icon { font-size: 14px; }


/* ---- "?" help icon (top-right of popover) ---- */
.crash-risk-help-icon {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.crash-risk-help-icon:hover {
    background: var(--color-brand);
    color: white;
    border-color: var(--color-brand);
}
.crash-risk-help-icon:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}


/* ---- Help modal ---- */
.crash-risk-help-card {
    max-width: 760px;
    width: 92vw;
}
.crash-risk-help-body {
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px 24px;
}
.crash-risk-help-body h4 {
    margin: 0 0 6px 0;
    font-size: 15px;
    color: var(--color-text);
}
.crash-risk-help-body h4:not(:first-child) {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--color-border-soft);
}
.crash-risk-help-intro {
    margin: 0 0 12px 0;
    color: var(--color-text-muted);
    font-size: 13px;
    line-height: 1.5;
}
.crash-risk-help-note {
    margin: 12px 0 0 0;
    padding: 10px 14px;
    background: var(--color-bg-alt);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--color-text-muted);
    line-height: 1.5;
}
.crash-risk-help-note strong { color: var(--color-text); }

.crash-risk-help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.5;
}
.crash-risk-help-table th {
    text-align: left;
    padding: 8px 12px;
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--color-border);
}
.crash-risk-help-table td {
    padding: 12px;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border-soft);
}
.crash-risk-help-table tr:last-child td { border-bottom: none; }
.crash-risk-help-table strong { color: var(--color-text); }
.crash-risk-help-range {
    font-size: 11px;
    color: var(--color-text-muted);
    font-weight: 400;
}

.crash-risk-help-cat {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.crash-risk-cat-slow { background: #e0f2fe; color: #075985; }
.crash-risk-cat-mid  { background: #fef3c7; color: #92400e; }
.crash-risk-cat-fast { background: #fee2e2; color: #991b1b; }

.crash-risk-help-stages {
    margin: 0;
    padding-left: 20px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-text-muted);
}
.crash-risk-help-stages strong { color: var(--color-text); }
.crash-risk-help-stages li { margin-bottom: 4px; }

.crash-risk-help-row-active {
    animation: crash-risk-help-flash 1.6s ease-out;
}
@keyframes crash-risk-help-flash {
    0%   { background: rgba(26, 84, 144, 0.18); }
    100% { background: transparent; }
}
.crash-risk-help-row-active td { background: rgba(26, 84, 144, 0.06); }


/* ---- Mobile responsiveness for popover + help ---- */
@media (max-width: 700px) {
    .crash-risk-popover { width: 96vw; }
    .crash-risk-top { grid-template-columns: auto 1fr; }
    .crash-risk-verdict { grid-column: 1 / -1; justify-content: center; }
    .crash-risk-chips {
        grid-template-columns: repeat(4, 1fr);
        row-gap: 6px;
    }
    .crash-risk-help-table th:nth-child(2),
    .crash-risk-help-table th:nth-child(3),
    .crash-risk-help-table td:nth-child(2),
    .crash-risk-help-table td:nth-child(3) {
        display: none;
    }
    .crash-risk-help-card { width: 96vw; }
    .crash-risk-help-body { padding: 16px; }
}


/* ============================================================
   Selloff Watch Indicator — score badge and recommendation
   ============================================================ */

.sw-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    line-height: 1.4;
    white-space: nowrap;
    cursor: default;
}

/* Score colour scale */
.sw-clear    { background: #EAF3DE; color: #27500A; }   /* 1-2 */
.sw-monitor  { background: #C0DD97; color: #27500A; }   /* 3-4 */
.sw-watch    { background: #FAC775; color: #412402; }   /* 5-6 */
.sw-alert    { background: #D85A30; color: #FAECE7; }   /* 7   */
.sw-exit     { background: #A32D2D; color: #FCEBEB; }   /* 8-9 */
.sw-critical { background: #501313; color: #FCEBEB; }   /* 10  */
.sw-none     { background: #F2F2F2; color: #888;    }   /* unscored */

/* Exit triggered — pulsing red border */
.sw-exit-triggered {
    outline: 2px solid #A32D2D;
    outline-offset: 1px;
    animation: sw-pulse 1.8s ease-in-out infinite;
}

@keyframes sw-pulse {
    0%, 100% { outline-color: #A32D2D; }
    50%       { outline-color: #FF6B6B; }
}

.sw-exit-icon {
    font-size: 11px;
    margin-left: 2px;
}

/* Recommendation label below the score badge */
.sw-rec {
    display: block;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.03em;
    margin-top: 2px;
    text-transform: uppercase;
}

.sw-rec-stay  { color: #27500A; }
.sw-rec-watch { color: #7A4A00; }
.sw-rec-alert { color: #C04000; }
.sw-rec-exit  { color: #A32D2D; font-weight: 700; }

/* Row highlight when exit is triggered */
tr:has(.sw-exit-triggered) {
    background: #FFF5F5 !important;
}

tr:has(.sw-exit-triggered) td {
    border-top: 1px solid #FFCCCC;
    border-bottom: 1px solid #FFCCCC;
}