/* Everest rebalance review — restrained professional styling. */

:root {
    --ink: #1a1d21;
    --muted: #5c636e;
    --line: #e2e5ea;
    --line-strong: #cdd2da;
    --bg: #f4f5f7;
    --panel: #ffffff;
    --accent: #2f5b8f;
    --accent-hover: #274d79;
    --accent-active: #1f3f64;
    --accent-ink: #ffffff;
    --accent-tint: rgba(47, 91, 143, 0.06);
    --accent-tint-strong: rgba(47, 91, 143, 0.11);
    --focus-ring: 0 0 0 3px rgba(47, 91, 143, 0.22);

    /* Semantic action colors — soft, tasteful tints for the Holdings table. */
    --buy-ink: #1f6d47;
    --buy-bg: #e6f4ec;
    --sell-ink: #a83a3a;
    --sell-bg: #f7e9e9;
    --hold-ink: #5c636e;
    --hold-bg: #eef0f3;
    --up-ink: #1e5f8f;
    --up-bg: #e7f0f8;
    --down-ink: #92602a;
    --down-bg: #f6eede;
    --danger: #b23b3b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

.shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.page {
    flex: 1;
    max-width: 760px;
    margin: 0 auto;
    padding: 40px 24px 64px;
}

/* ── Sidebars ────────────────────────────────────────────────────────────
   Both columns share one layout: a fixed-width, full-height panel with a
   sticky section header, a scrollable list, and a pinned footer for actions.
   Left = Uploads, right = Models. */
.sidebar {
    width: 248px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    max-height: 100vh;
    position: sticky;
    top: 0;
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 28px 18px;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--line);
}

.sidebar-title {
    display: block;
    flex-shrink: 0;
    margin: 0 0 14px;
    padding: 0 2px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

/* Scrollable list region: grows to fill, scrolls within the sidebar so a
   long list never pushes the page or the footer button. */
.sidebar-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin: 0 -6px;
    padding: 0 6px;
}

/* Shared selectable-card styling for both sidebars. Each card is a clickable
   button reset from native chrome and styled as a full-width list card — a
   bordered white surface matching the app's panel language. The active one
   gets an accent left-border and tint. */
.card {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid transparent;
    border-radius: 6px;
    background: var(--panel);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    color: var(--ink);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.card:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.upload-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.card:hover {
    background: var(--bg);
    border-color: var(--line-strong);
}

/* Selected card: accent left-border + subtle tint + accent text — clear but
   understated, consistent with the app's restrained accent use. */
.card.selected {
    color: var(--accent);
    font-weight: 600;
    background: var(--accent-tint);
    border-color: var(--accent);
    border-left-color: var(--accent);
    border-left-width: 3px;
    box-shadow: 0 1px 3px rgba(47, 91, 143, 0.1);
}

.card.selected:hover {
    background: var(--accent-tint-strong);
    border-color: var(--accent);
    border-left-color: var(--accent);
}

/* Right sidebar model rows: card + aligned delete affordance. The card fills
   the row; the × overlays at the right so cards line up with the upload cards. */
.model-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.model-row {
    position: relative;
    display: flex;
    align-items: center;
    border-radius: 6px;
}

.model-card {
    flex: 1;
    min-width: 0;
    /* Room for the × so a long name never runs under it. */
    padding-right: 34px;
}

.model-spacer {
    display: none;
}

/* Per-model ⋮ kebab menu: a native <details> disclosure. The summary is the
   ⋮ trigger overlaid at the right of the row; opening reveals a small popover
   of actions (Rename / Clone / Delete). No callback drives open/close. */
.model-menu {
    position: static;
}

.model-menu-summary {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    list-style: none;
    opacity: 0;
    transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
    z-index: 4;
}

.model-menu-summary::-webkit-details-marker { display: none; }

/* Reveal the ⋮ on row hover, when the card is selected, or when the menu is
   open — and keep it visible while open. */
.model-row:hover .model-menu-summary,
.model-row:has(.card.selected) .model-menu-summary,
.model-menu[open] .model-menu-summary {
    opacity: 1;
}

.model-menu-summary:hover {
    background: var(--line);
    color: var(--ink);
}

/* The action popover, anchored to the row's right edge below the ⋮. */
.model-menu-panel {
    position: absolute;
    right: 4px;
    top: calc(50% + 16px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 168px;
    padding: 6px;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(26, 29, 33, 0.14);
}

.model-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 9px;
    border: none;
    border-radius: 4px;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    color: var(--ink);
    cursor: pointer;
}

.model-menu-btn:hover {
    background: var(--bg);
}

.model-menu-icon {
    width: 14px;
    flex-shrink: 0;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

.model-menu-danger { color: var(--danger); }
.model-menu-danger .model-menu-icon { color: var(--danger); }
.model-menu-danger:hover { background: rgba(178, 59, 59, 0.08); }

.model-rename-item { cursor: default; }

.model-rename-input {
    flex: 1;
    min-width: 0;
}

.model-rename-input input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 7px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ink);
}

.model-rename-input input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

/* ConfirmDialogProvider wraps its child button; keep it laid out as a plain
   menu row so the Delete action matches the others. */
.model-menu-panel > div { display: block; }

/* Footer action, pinned below the scrollable list. */
.sidebar-footer {
    flex-shrink: 0;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.new-model-btn {
    width: 100%;
    text-align: center;
}

/* Full-width, horizontally centered product title at the top of the page. */
.app-title-wrap {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    margin: 0 0 20px;
}

.app-title {
    margin: 0;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.app-version {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.02em;
}

.page-header {
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.page-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.page-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

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

.panel-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink);
}

/* Small accent tick before each panel header — a quiet anchor for hierarchy. */
.panel-label::before {
    content: "";
    width: 3px;
    height: 12px;
    border-radius: 2px;
    background: var(--accent);
}

.rationale-input {
    width: 100%;
    box-sizing: border-box;
    min-height: 96px;
    resize: vertical;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    line-height: 1.5;
}

.rationale-input {
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.rationale-input:hover:not(:disabled) {
    border-color: var(--line-strong);
}

.rationale-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.rationale-input:disabled {
    background: var(--bg);
    color: var(--muted);
    border-style: dashed;
}

/* Holdings panel header: title on the left, Undo/Reset on the right. */
.holdings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.holdings-head .panel-label {
    margin: 0;
}

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

.control-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 24px;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.cash-input {
    width: 72px;
    padding: 6px 8px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    font-size: 14px;
    color: var(--ink);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.cash-input:hover:not(:disabled) {
    border-color: var(--accent);
}

.cash-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

/* Info / instructions box */
.info-lead {
    margin: 0 0 10px;
    color: var(--ink);
    font-size: 13px;
}

.info-list {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
    font-size: 13px;
}

.info-list li {
    margin: 2px 0;
}

/* dcc.RadioItems / dcc.Checklist inline layout */
.toggle-group label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
    font-size: 14px;
    cursor: pointer;
}

.toggle-group input {
    accent-color: var(--accent);
}

/* Controls + summary on one row: two side-by-side columns that wrap to stacked
   on narrow widths. The controls panel takes the larger share. */
.controls-summary-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 20px;
    margin-bottom: 20px;
}

.controls-summary-row .panel {
    flex: 2 1 320px;
    min-width: 0;
    margin-bottom: 0;
}

.controls-summary-row .summary {
    flex: 1 1 260px;
    min-width: 0;
    margin-bottom: 0;
    align-items: center;
}

/* Summary bar */
.summary {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 28px;
    padding: 16px 20px;
    background: linear-gradient(180deg, var(--accent-tint) 0%, var(--panel) 60%);
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: 20px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.summary-key {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.summary-value {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--accent-active);
    border-radius: 6px;
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-active) 100%);
    color: var(--accent-ink);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(31, 63, 100, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);
    transition: background 0.12s ease, border-color 0.12s ease,
        box-shadow 0.12s ease, transform 0.04s ease;
}

.btn:hover {
    background: linear-gradient(180deg, var(--accent-hover) 0%, var(--accent-active) 100%);
    border-color: var(--accent-active);
    box-shadow: 0 3px 8px rgba(47, 91, 143, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn:active {
    background: var(--accent-active);
    border-color: var(--accent-active);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

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

/* Secondary actions (Import / Undo / Reset / + New model): raised light chips
   with a soft gradient and shadow so they read clearly as buttons, not links. */
.btn-secondary {
    border: 1px solid var(--line-strong);
    background: linear-gradient(180deg, #ffffff 0%, #e9edf3 100%);
    color: #33404f;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(26, 29, 33, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.btn-secondary:hover {
    background: linear-gradient(180deg, var(--accent-tint) 0%, var(--accent-tint-strong) 100%);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 2px 6px rgba(47, 91, 143, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.btn-secondary:active {
    background: var(--accent-tint-strong);
    border-color: var(--accent);
    box-shadow: inset 0 1px 2px rgba(47, 91, 143, 0.18);
    transform: translateY(1px);
}

.btn-secondary:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

/* Disabled actions (e.g. Undo/Reset on the read-only Original) sit flat and
   muted so they don't read as pressable. */
.btn:disabled,
.btn-secondary:disabled {
    background: var(--bg);
    border-color: var(--line);
    color: var(--muted);
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

/* Fixed-height scroll so a long holdings list stays in a bounded panel while
   still showing every row. The header stays pinned to the top on scroll. */
.holdings-scroll {
    max-height: 560px;
    overflow-y: auto;
    margin: 0 -20px -20px;
    padding: 0 20px;
}

.holdings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

/* Sticky header: pin the whole header row to the top of the scroll region with
   an opaque background and a z-index above the row inputs, so the Target Weight
   inputs scroll cleanly UNDER the column headers instead of over them. */
.holdings-table thead {
    position: sticky;
    top: 0;
    z-index: 3;
}

.holdings-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

/* Row inputs sit below the header on the stacking order. */
.holdings-table td { position: relative; z-index: 0; }
.weight-input, .row-select { position: relative; z-index: 0; }

.holdings-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    color: #5c636e;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: #f4f5f7;
    border-bottom: 1px solid #cdd2da;
}

.holdings-table td {
    padding: 8px 14px;
    border-bottom: 1px solid #eef0f3;
    vertical-align: middle;
}

.holdings-table tbody tr {
    transition: background 0.1s ease;
}

.holdings-table tbody tr:hover {
    background: var(--accent-tint);
}

.col-position { font-weight: 500; }
.col-action { color: var(--muted); }

/* Semantic action pills: soft tinted chips so the Action column scans fast.
   Muted and rounded — informative, not loud. */
.action-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.5;
    white-space: nowrap;
}

.action-buy     { color: var(--buy-ink);  background: var(--buy-bg); }
.action-sell    { color: var(--sell-ink); background: var(--sell-bg); }
.action-hold    { color: var(--hold-ink); background: var(--hold-bg); }
.action-up      { color: var(--up-ink);   background: var(--up-bg); }
.action-down    { color: var(--down-ink); background: var(--down-bg); }
.action-neutral { color: var(--muted);    background: var(--hold-bg); }

/* Deselected / excluded rows read as set aside: dimmed and desaturated so the
   active holdings stand out. Driven off the live checkbox state so toggling a
   holding updates the shading immediately (no re-render needed). */
.holding-row:has(.row-select input:not(:checked)) .col-position,
.holding-row:has(.row-select input:not(:checked)) .col-num { opacity: 0.5; }
.holding-row:has(.row-select input:not(:checked)) .action-pill { opacity: 0.55; }
.col-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.col-select { width: 28px; }

.holdings-table th.col-num { text-align: right; }

.row-select label { margin: 0; }

.weight-input input {
    width: 90px;
    padding: 5px 8px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: #ffffff;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.weight-input input:hover:not(:disabled) {
    border-color: var(--accent);
}

.weight-input input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

/* Read-only / excluded weight fields: a dashed border reads as "not editable"
   at a glance, distinct from an empty editable field. */
.weight-input input:disabled {
    background: var(--bg);
    color: #aab0b8;
    border-style: dashed;
    border-color: var(--line-strong);
}

/* DataTable padding refinements handed off from Python style dicts */