/* ==========================================================================
   PolyHopefully — monochrome design system
   One ink colour on one paper colour, a scale of greys between them.
   No gradients, no shadows, no accent hues, no animation.
   Light by default; follows the OS dark preference.
   ========================================================================== */

:root {
    --paper: #ffffff;
    --paper-2: #f6f6f6;      /* subtle panel / table header fill */
    --paper-3: #ececec;      /* hover fill */
    --ink: #111111;
    --ink-2: #555555;        /* secondary text */
    --ink-3: #8a8a8a;        /* muted text / labels */
    --line: #e2e2e2;
    --line-2: #bdbdbd;       /* stronger rule / input border */
    --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --radius: 3px;
    --w: 1200px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #121212;
        --paper-2: #1a1a1a;
        --paper-3: #242424;
        --ink: #ededed;
        --ink-2: #b0b0b0;
        --ink-3: #7a7a7a;
        --line: #2a2a2a;
        --line-2: #4a4a4a;
    }
}

/* --------------------------------------------------------------------------
   Reset / base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0 0 0.75em; }
p:last-child { margin-bottom: 0; }
img, canvas { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
code, .mono { font-family: var(--mono); font-size: 0.95em; }
strong { font-weight: 600; }

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */
.muted { color: var(--ink-3); }
.secondary { color: var(--ink-2); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.mt { margin-top: 24px; }
.mb { margin-bottom: 24px; }
.hidden { display: none !important; }
.label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-3);
}
/* Gains and losses are told apart by their sign, not by colour. */
.positive, .negative { font-variant-numeric: tabular-nums; }
.positive { color: var(--ink); }
.negative { color: var(--ink); }

/* --------------------------------------------------------------------------
   Shell: top bar, section tabs, container
   -------------------------------------------------------------------------- */
.topbar {
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}
.topbar-inner {
    max-width: var(--w);
    margin: 0 auto;
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 28px;
}
.brand {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
    padding: 6px 10px;
    color: var(--ink-2);
    border-radius: var(--radius);
    white-space: nowrap;
}
.nav a:hover { color: var(--ink); background: var(--paper-2); text-decoration: none; }
.nav a.active { color: var(--ink); font-weight: 600; }
.nav-right { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: 13px; }
.nav-right a:hover { color: var(--ink); }
.count {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    margin-left: 6px;
    border-radius: 9px;
    background: var(--ink);
    color: var(--paper);
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    vertical-align: 1px;
}

.subnav {
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}
.subnav-inner {
    max-width: var(--w);
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 4px;
    overflow-x: auto;
}
.subnav a {
    padding: 10px 10px 9px;
    color: var(--ink-2);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    font-size: 13px;
}
.subnav a:hover { color: var(--ink); text-decoration: none; }
.subnav a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

.container {
    max-width: var(--w);
    margin: 0 auto;
    padding: 28px 24px 64px;
}

/* --------------------------------------------------------------------------
   Page header and sections
   -------------------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}
.page-title { font-size: 22px; font-weight: 600; }
.page-desc { margin-top: 4px; color: var(--ink-2); max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.page-actions form { display: inline; }

.section { margin-bottom: 36px; }
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--line);
}
.section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.section-head .actions { display: flex; gap: 8px; }
.section-head .actions form { display: inline; }

/* --------------------------------------------------------------------------
   Layout grids
   -------------------------------------------------------------------------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.layout-main-side { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.layout-side-main { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .layout-main-side, .layout-side-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .topbar-inner { gap: 12px; height: auto; flex-wrap: wrap; padding: 8px 16px; }
    .container, .subnav-inner { padding-left: 16px; padding-right: 16px; }
    .page-header { flex-direction: column; }
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
}
.card-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.card-body { padding: 16px; }
.card-body + .card-body { border-top: 1px solid var(--line); }
.card-foot {
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    color: var(--ink-3);
    font-size: 12px;
}
.card.flat { border: 0; }
.card.filled { background: var(--paper-2); }

/* --------------------------------------------------------------------------
   Stats (KPI tiles)
   -------------------------------------------------------------------------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 28px;
}
.stat {
    padding: 14px 16px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin-right: -1px;
    margin-bottom: -1px;
    min-width: 0;
}
.stat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-bottom: 6px;
}
.stat-value {
    font-family: var(--mono);
    font-size: 22px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-sub { margin-top: 5px; font-size: 12px; color: var(--ink-3); }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th, .table td {
    padding: 9px 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--line);
}
.table th {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-3);
    background: var(--paper-2);
    white-space: nowrap;
}
.table th.num, .table td.num { text-align: right; }
.table tbody tr:hover { background: var(--paper-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .primary { font-weight: 500; }
.table .actions { white-space: nowrap; text-align: right; }
.table .actions form { display: inline; }
.table.compact th, .table.compact td { padding: 6px 10px; }

/* Two-column key/value list */
.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { background: var(--paper-2); border-color: var(--ink); text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary, .btn-success { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover, .btn-success:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-danger { border-color: var(--ink); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-group .btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); position: relative; }
.link-btn {
    background: none; border: 0; padding: 0; margin: 0;
    font: inherit; color: var(--ink-2); cursor: pointer; text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 1px 7px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.5;
    color: var(--ink-2);
    white-space: nowrap;
    vertical-align: middle;
}
.badge-solid, .badge-buy-yes, .badge-high { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.badge-buy-no, .badge-med { color: var(--ink); border-color: var(--ink); }
.badge-low, .badge-hold, .badge-muted { color: var(--ink-3); border-color: var(--line); }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input[type="text"], input[type="number"], input[type="password"], input[type="search"],
input[type="url"], input[type="email"], select, textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
input[type="number"], .input-mono { font-family: var(--mono); }
input::placeholder { color: var(--ink-3); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.field .help { margin-top: 4px; font-size: 12px; color: var(--ink-3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 20px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); font-size: 13px; }
.check input { width: auto; margin: 0; }
.search { display: flex; gap: 8px; }
.search input { flex: 1; }

/* --------------------------------------------------------------------------
   Flash messages
   -------------------------------------------------------------------------- */
.flash-messages { margin-bottom: 24px; display: flex; flex-direction: column; gap: 6px; }
.flash {
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--ink);
    border-radius: var(--radius);
    background: var(--paper-2);
    font-size: 13px;
    cursor: pointer;
}
.flash-error, .flash-danger { border-left-color: var(--ink); font-weight: 500; }
.flash-warning { border-left-color: var(--ink-2); }
.flash-info, .flash-success { border-left-color: var(--line-2); }

/* --------------------------------------------------------------------------
   Misc components
   -------------------------------------------------------------------------- */
.empty {
    padding: 36px 16px;
    text-align: center;
    color: var(--ink-3);
    border: 1px dashed var(--line-2);
    border-radius: var(--radius);
}
.empty-state { padding: 36px 16px; text-align: center; color: var(--ink-3); }
.empty-state-icon { display: none; }

.notice {
    padding: 10px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    font-size: 13px;
}

.prose { max-width: 75ch; color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.prose p { margin-bottom: 0.7em; }

/* horizontal meter, e.g. confidence or probability */
.bar { height: 6px; background: var(--paper-3); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ink); }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.bar-row .bar { flex: 1; }

/* price pair, used on market rows */
.price-pair { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-family: var(--mono); font-size: 12px; }
.price-pair span { padding: 2px 8px; }
.price-pair span + span { border-left: 1px solid var(--line); }
.price-pair .yes { background: var(--ink); color: var(--paper); }

/* charts */
.chart { position: relative; height: 240px; }
.chart.tall { height: 320px; }
.chart.short { height: 160px; }

/* bordered list of rows (e.g. positions, articles) */
.list { border: 1px solid var(--line); border-radius: var(--radius); }
.list-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--paper-2); }
.list-title { font-weight: 500; }
.list-meta { margin-top: 3px; font-size: 12px; color: var(--ink-3); }

/* narrow inline inputs (amounts, quantities) */
.input-narrow { width: 90px; }

/* login */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; }

/* modal (plain) */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.4); z-index: 100; }
.modal.open { display: flex; }
.modal-card { width: 100%; max-width: 420px; background: var(--paper); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 20px; }

/* status dot */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); vertical-align: middle; margin-right: 6px; }
.dot.off { background: var(--line-2); }

/* --------------------------------------------------------------------------
   Motion. Short and quiet. Deliberately ignores the OS reduce-motion setting.
   -------------------------------------------------------------------------- */
:root {
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --t-fast: 120ms;
    --t-base: 220ms;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}
@keyframes fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes slide-down {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: none; }
}
@keyframes grow-x {
    from { transform: scaleX(0); }
    to   { transform: none; }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.35; }
}

/* Page content rises in once; children marked by base.html stagger after it. */
.container > .page-header { animation: rise var(--t-base) var(--ease) both; }
.anim { animation: rise 320ms var(--ease) both; animation-delay: var(--d, 0ms); }

/* Interactive surfaces ease between states instead of snapping. */
.btn, .nav a, .subnav a, .badge, .table tbody tr, .list-item, .card, input, select, textarea, .link-btn {
    transition: background-color var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease),
                opacity var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary:hover, .btn-success:hover { transform: translateY(-1px); }
.subnav a { position: relative; }
.subnav a::after {
    content: "";
    position: absolute; left: 10px; right: 10px; bottom: -1px;
    height: 2px; background: var(--ink);
    transform: scaleX(0); transform-origin: left;
    transition: transform var(--t-base) var(--ease);
}
.subnav a.active { border-bottom-color: transparent; }
.subnav a.active::after { transform: scaleX(1); }
.subnav a:hover::after { transform: scaleX(1); opacity: 0.35; }
.subnav a.active:hover::after { opacity: 1; }

/* Meters fill from the left. */
.bar > span { transform-origin: left; animation: grow-x 600ms var(--ease) both; animation-delay: 150ms; }

/* Flash messages drop in, then fade out on their own (see base.html). */
.flash { animation: slide-down var(--t-base) var(--ease) both; }
.flash.leaving { opacity: 0; transform: translateY(-4px); transition: opacity var(--t-base), transform var(--t-base); }

/* A quiet pulse for "working" states, e.g. the scan banner. */
.working { animation: pulse 1.6s ease-in-out infinite; }

/* Stat values are counted up by base.html; keep the width stable meanwhile. */
.stat-value { font-variant-numeric: tabular-nums; }

