/* ============================================================================
   MatterOfStocks design system (issue #240)
   One shared sheet for the research surface: tokens, base typography, and
   components. Pages link this and keep only page-specific rules inline.
   landing.html deliberately does NOT use this (hybrid decision: marketing
   surface keeps its own look).

   Direction: modern financial-data product - layered surfaces with soft
   elevation instead of boxy 1px borders, ONE accent family, real typographic
   hierarchy, tabular numerals everywhere data appears, restrained
   micro-interactions.

   DUAL THEME (owner directive 2026-07-09: modern for the 20s-30s crowd,
   simple/legible for older users): every rule below consumes only semantic
   tokens; the two [data-theme] blocks are the entire theme surface. Default
   follows the OS via prefers-color-scheme; an explicit user choice is stamped
   on <html data-theme=...> by static/js/mos-theme.js (localStorage-persisted)
   and wins over the OS. Legibility floor for all ages: 16px root, no text
   below ~11.5px, AA contrast in both themes.
   ========================================================================== */

/* ── Tokens: dark (default when OS prefers dark, or data-theme="dark") ──── */
:root {
    /* Surfaces - layered depth, not flat panels */
    --bg: #0d1117;
    --bg-raised: #131922;
    --surface: #161d27;
    --surface-2: #1b2330;
    --surface-hover: #202a39;
    --topbar-bg: rgba(13, 17, 23, 0.85);
    --bg-tint: rgba(76, 141, 255, 0.05);

    /* Hairlines + elevation */
    --border: rgba(255, 255, 255, 0.055);
    --border-strong: rgba(255, 255, 255, 0.10);
    --border-accent: rgba(76, 141, 255, 0.35);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 0 1px rgba(76, 141, 255, 0.18), 0 6px 20px -6px rgba(0, 0, 0, 0.5);

    /* One accent family */
    --accent: #4c8dff;
    --accent-bright: #6ea3ff;
    --accent-soft: rgba(76, 141, 255, 0.12);
    --accent-text: #9ec3ff;
    --on-accent: #ffffff;

    /* Text ramp */
    --text: #e6ebf2;
    --text-2: #99a5b5;
    --text-3: #6a7688;

    /* Semantic signals (the ONLY other hues) */
    --up: #22c07a;
    --up-soft: rgba(34, 192, 122, 0.10);
    --hold: #d9a441;
    --hold-soft: rgba(217, 164, 65, 0.10);
    --down: #e5566d;
    --down-soft: rgba(229, 86, 109, 0.10);

    /* Geometry + motion */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 5px;
    --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
    --fast: 140ms;

    color-scheme: dark;
}

/* ── Tokens: light ────────────────────────────────────────────────────────
   Values chosen for AA contrast on white and familiarity for the
   Yahoo/Morningstar-accustomed reader: soft off-white canvas (not stark
   white), same accent family darkened for contrast, deeper signal hues. */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f7f8fa;
        --bg-raised: #ffffff;
        --surface: #ffffff;
        --surface-2: #eef1f5;
        --surface-hover: #e6ebf2;
        --topbar-bg: rgba(255, 255, 255, 0.85);
        --bg-tint: rgba(31, 95, 214, 0.04);

        --border: rgba(20, 28, 40, 0.09);
        --border-strong: rgba(20, 28, 40, 0.17);
        --border-accent: rgba(31, 95, 214, 0.40);
        --shadow-1: 0 1px 2px rgba(20, 28, 40, 0.06);
        --shadow-2: 0 8px 24px -8px rgba(20, 28, 40, 0.14);
        --shadow-glow: 0 0 0 1px rgba(31, 95, 214, 0.18), 0 6px 20px -6px rgba(20, 28, 40, 0.16);

        --accent: #1f5fd6;
        --accent-bright: #1a4fb5;
        --accent-soft: rgba(31, 95, 214, 0.09);
        --accent-text: #174ea8;
        --on-accent: #ffffff;

        --text: #1a2330;
        --text-2: #4a5768;
        --text-3: #7b8797;

        --up: #0c8a58;
        --up-soft: rgba(12, 138, 88, 0.09);
        --hold: #8f6a10;
        --hold-soft: rgba(143, 106, 16, 0.09);
        --down: #c73a52;
        --down-soft: rgba(199, 58, 82, 0.09);

        color-scheme: light;
    }
}

:root[data-theme="light"] {
    --bg: #f7f8fa;
    --bg-raised: #ffffff;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --surface-hover: #e6ebf2;
    --topbar-bg: rgba(255, 255, 255, 0.85);
    --bg-tint: rgba(31, 95, 214, 0.04);

    --border: rgba(20, 28, 40, 0.09);
    --border-strong: rgba(20, 28, 40, 0.17);
    --border-accent: rgba(31, 95, 214, 0.40);
    --shadow-1: 0 1px 2px rgba(20, 28, 40, 0.06);
    --shadow-2: 0 8px 24px -8px rgba(20, 28, 40, 0.14);
    --shadow-glow: 0 0 0 1px rgba(31, 95, 214, 0.18), 0 6px 20px -6px rgba(20, 28, 40, 0.16);

    --accent: #1f5fd6;
    --accent-bright: #1a4fb5;
    --accent-soft: rgba(31, 95, 214, 0.09);
    --accent-text: #174ea8;
    --on-accent: #ffffff;

    --text: #1a2330;
    --text-2: #4a5768;
    --text-3: #7b8797;

    --up: #0c8a58;
    --up-soft: rgba(12, 138, 88, 0.09);
    --hold: #8f6a10;
    --hold-soft: rgba(143, 106, 16, 0.09);
    --down: #c73a52;
    --down-soft: rgba(199, 58, 82, 0.09);

    color-scheme: light;
}

/* ── Base ─────────────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }

body {
    /* System stack, deliberately no webfont: performance-first direction
       (owner 2026-07-09) - zero render-blocking third-party requests. */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    background:
        radial-gradient(1200px 500px at 70% -10%, var(--bg-tint), transparent 60%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 1rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background 200ms var(--ease), color 200ms var(--ease);
}

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.02em; color: var(--text); }

/* Every number in a data product should be tabular */
.num, td, .pick-price, .pick-score, .stat-value, .mos-table td { font-variant-numeric: tabular-nums; }

a { color: var(--accent-text); }

::selection { background: var(--accent-soft); }

/* ── Topbar ───────────────────────────────────────────────────────────── */
.mos-topbar {
    position: sticky; top: 0; z-index: 200;
    background: var(--topbar-bg);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
}
.mos-topbar-inner {
    max-width: 1600px; margin: 0 auto; padding: 0.8rem 1.25rem;
    display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
}
.mos-brand { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.03em; color: var(--text); text-decoration: none; white-space: nowrap; }
.mos-brand em { font-style: normal; color: var(--accent-bright); }
.mos-brand-sub { display: block; font-size: 0.72rem; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin-top: 0.05rem; }

.mos-nav { display: flex; align-items: center; gap: 0.2rem; flex-wrap: wrap; }
.mos-nav a {
    font-size: 0.86rem; font-weight: 500; color: var(--text-2); text-decoration: none;
    padding: 0.42rem 0.7rem; border-radius: var(--radius-xs);
    transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.mos-nav a:hover { color: var(--text); background: var(--surface-2); }
.mos-nav a.active { color: var(--accent-text); background: var(--accent-soft); }
.mos-nav a.quiet { color: var(--text-3); }

/* ── Topbar: compact phone treatment (#54) ────────────────────────────────
   The authenticated topbar carries ~9 primary links; at phone widths they
   wrap into an ugly multi-line block. Instead of a JS hamburger (no new JS,
   performance-first), the nav becomes a one-line horizontal scroll strip
   with the scrollbar hidden and a fade-out right edge hinting at overflow.
   Shared component: applies everywhere .mos-nav / .mos-topbar-inner are
   used. Token-only, so both themes work automatically. Layout under 700px:
   row 1 = brand (sub-line dropped) + theme/bell/account controls,
   row 2 = search full-width (dashboard's .search-wrapper),
   row 3 = nav scroll strip. */
@media (max-width: 700px) {
    .mos-topbar-inner { gap: 0.5rem 0.75rem; padding: 0.55rem 1rem; }
    .mos-brand-sub { display: none; }
    .mos-topbar-inner .search-wrapper { flex-basis: 100%; max-width: none; order: 9; }
    .mos-nav {
        flex-basis: 100%; order: 10;
        flex-wrap: nowrap; overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* cheap "more to the right" hint: fade the strip's last 28px */
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
        mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    }
    .mos-nav::-webkit-scrollbar { display: none; }
    .mos-nav a { white-space: nowrap; flex-shrink: 0; }

    /* Touch targets >=44px (#54) on the shared interactive components.
       Anchors/summaries become inline-flex so min-height actually applies. */
    .mos-nav a {
        display: inline-flex; align-items: center;
        min-height: 44px; padding: 0.42rem 0.85rem;
    }
    .mos-theme-toggle { width: 2.75rem; height: 2.75rem; }
    .mos-btn { min-height: 44px; }
    .mos-account > summary, .mos-bell > summary {
        min-height: 44px; min-width: 44px; justify-content: center;
    }
}

/* Theme toggle (mos-theme.js wires the click) */
.mos-theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.1rem; height: 2.1rem; border-radius: var(--radius-xs);
    background: transparent; border: 1px solid var(--border-strong);
    color: var(--text-2); cursor: pointer; font-size: 0.95rem;
    transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.mos-theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.mos-theme-toggle .when-dark { display: none; }
.mos-theme-toggle .when-light { display: inline; }
:root[data-theme="dark"] .mos-theme-toggle .when-dark { display: inline; }
:root[data-theme="dark"] .mos-theme-toggle .when-light { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .mos-theme-toggle .when-dark { display: inline; }
    :root:not([data-theme="light"]) .mos-theme-toggle .when-light { display: none; }
}


/* ── Account menu (topbar, right side) ─────────────────────────────────
   <details class="mos-account"> based: works without JS (CSP-safe);
   mos-theme.js adds close-on-outside-click as an enhancement. */
.mos-account { position: relative; }
.mos-account > summary {
    list-style: none; cursor: pointer;
    display: inline-flex; align-items: center; gap: 0.45rem;
    font-size: 0.84rem; font-weight: 600; color: var(--text-2);
    padding: 0.4rem 0.7rem; border-radius: var(--radius-xs);
    border: 1px solid var(--border-strong);
    transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
    max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mos-account > summary::-webkit-details-marker { display: none; }
.mos-account > summary:hover { color: var(--text); background: var(--surface-2); }
.mos-account[open] > summary { color: var(--accent-text); background: var(--accent-soft); border-color: var(--border-accent); }
.mos-account-menu {
    position: absolute; right: 0; top: calc(100% + 0.5rem); z-index: 300;
    min-width: 240px; background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-2); overflow: hidden;
}
.mos-account-menu .acct-head { padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.mos-account-menu .acct-email { font-size: 0.86rem; font-weight: 600; color: var(--text); word-break: break-all; }
.mos-account-menu .acct-tier { margin-top: 0.35rem; }
.mos-account-menu a.acct-item {
    display: block; padding: 0.6rem 1rem; font-size: 0.85rem; font-weight: 500;
    color: var(--text-2); text-decoration: none;
}
.mos-account-menu a.acct-item:hover { background: var(--surface-2); color: var(--text); }
.mos-account-menu .acct-signout {
    display: block; padding: 0.6rem 1rem; font-size: 0.85rem; font-weight: 600;
    color: var(--down); text-decoration: none; border-top: 1px solid var(--border);
}
.mos-account-menu .acct-signout:hover { background: var(--down-soft); }

/* ── Notification bell (topbar, left of the account menu - #419) ───────
   Same details.mos-account base as above; .mos-bell only adjusts the
   summary to an icon button and widens the dropdown into a list panel. */
.mos-bell > summary {
    padding: 0.4rem 0.55rem;
    max-width: none; overflow: visible;   /* badge sits outside the box */
    position: relative;
}
.mos-bell-icon { display: block; }
.mos-bell-badge {
    position: absolute; top: -0.4rem; right: -0.4rem;
    min-width: 1.1rem; height: 1.1rem; padding: 0 0.28rem;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 999px;
    font-size: 0.66rem; font-weight: 700; line-height: 1;
    background: var(--accent-text); color: var(--surface);
    border: 1px solid var(--surface);
}
/* author display beats the UA [hidden] rule - restate it */
.mos-bell-badge[hidden] { display: none; }
.mos-bell-panel { width: 320px; max-width: 86vw; }
.mos-bell-panel .bell-head {
    display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
    padding: 0.7rem 1rem; border-bottom: 1px solid var(--border);
}
.mos-bell-panel .bell-head-title { font-size: 0.86rem; font-weight: 700; color: var(--text); }
.mos-bell-panel .bell-mark-read {
    font-size: 0.74rem; font-weight: 600; color: var(--accent-text);
    background: none; border: none; cursor: pointer; padding: 0.2rem 0.3rem;
    border-radius: var(--radius-xs);
}
.mos-bell-panel .bell-mark-read:hover { background: var(--accent-soft); }
.mos-bell-panel .bell-list { max-height: 360px; overflow-y: auto; }
.mos-bell-panel .bell-empty { padding: 1.1rem 1rem; font-size: 0.82rem; color: var(--text-3); }
.mos-bell-panel .bell-item {
    display: block; padding: 0.6rem 1rem; text-decoration: none;
    border-bottom: 1px solid var(--border);
}
.mos-bell-panel .bell-item:last-child { border-bottom: none; }
.mos-bell-panel a.bell-item:hover { background: var(--surface-2); }
.mos-bell-panel .bell-item.unread { background: var(--accent-soft); }
.mos-bell-panel .bell-item-title { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.mos-bell-panel .bell-item-body {
    margin-top: 0.15rem; font-size: 0.78rem; color: var(--text-2);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mos-bell-panel .bell-item-meta { margin-top: 0.2rem; font-size: 0.72rem; color: var(--text-3); }

/* ── Cards ────────────────────────────────────────────────────────────── */
.mos-card {
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
}
.mos-card.pad { padding: 1.4rem 1.5rem; }
.mos-card.hoverable { transition: transform var(--fast) var(--ease), border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
.mos-card.hoverable:hover { transform: translateY(-2px); border-color: var(--border-accent); box-shadow: var(--shadow-glow); }

/* Section headers */
.mos-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.mos-section-title { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.025em; }
.mos-kicker { font-size: 0.74rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); }

/* Stat chips (replaces heavy count pills) */
.mos-stat { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; font-weight: 600; color: var(--text-2); }
.mos-stat .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.mos-stat.up .dot { background: var(--up); box-shadow: 0 0 8px var(--up); }
.mos-stat.hold .dot { background: var(--hold); }
.mos-stat.down .dot { background: var(--down); }

/* Tags (subtle, squared - replaces pill badges) */
.mos-tag {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
    padding: 0.18rem 0.5rem; border-radius: var(--radius-xs);
}
.mos-tag.up { background: var(--up-soft); color: var(--up); }
.mos-tag.hold { background: var(--hold-soft); color: var(--hold); }
.mos-tag.down { background: var(--down-soft); color: var(--down); }
.mos-tag.accent { background: var(--accent-soft); color: var(--accent-text); }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.mos-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
    font-family: inherit; font-size: 0.88rem; font-weight: 600;
    padding: 0.55rem 1.1rem; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer; text-decoration: none;
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background var(--fast) var(--ease);
}
.mos-btn.primary { background: linear-gradient(180deg, var(--accent-bright), var(--accent)); color: var(--on-accent); box-shadow: 0 2px 12px -2px var(--accent-soft); }
.mos-btn.primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }
.mos-btn.ghost { background: transparent; color: var(--text-2); border-color: var(--border-strong); }
.mos-btn.ghost:hover { color: var(--text); background: var(--surface-2); }

/* ── Inputs ───────────────────────────────────────────────────────────── */
.mos-input {
    font-family: inherit; font-size: 0.88rem; color: var(--text);
    background: var(--bg-raised); border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); padding: 0.55rem 0.85rem;
    transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.mos-input::placeholder { color: var(--text-3); }
.mos-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Tables ───────────────────────────────────────────────────────────── */
.mos-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.mos-table th {
    text-align: left; font-size: 0.74rem; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-3);
    padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--border-strong);
}
.mos-table td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); color: var(--text-2); }
.mos-table tr:hover td { background: var(--surface-2); }
.mos-table tr:last-child td { border-bottom: none; }

/* Semantic value colors */
.val-up { color: var(--up); }
.val-down { color: var(--down); }
.val-hold { color: var(--hold); }


/* ── Stock pick card (_stock_pick_card.html, shared by dashboard + sector
   drill-down) ─────────────────────────────────────────────────────────── */
.pick-card {
    display: block; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; text-decoration: none;
    color: var(--text); box-shadow: var(--shadow-1);
    transition: transform var(--fast) var(--ease), border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.pick-card:hover { transform: translateY(-2px); border-color: var(--border-accent); box-shadow: var(--shadow-glow); }
.pick-card-top { display: flex; justify-content: space-between; align-items: center; }
.pick-symbol { font-weight: 700; color: var(--text); font-size: 0.95rem; }
.pick-score { font-size: 0.82rem; font-weight: 700; color: var(--accent-text); }
.pick-name { font-size: 0.75rem; color: var(--text-3); margin-top: 0.1rem; }
.pick-price { font-size: 0.82rem; color: var(--text-2); margin-top: 0.35rem; }
.pick-up { color: var(--up); margin-left: 0.3rem; }
.pick-down { color: var(--down); margin-left: 0.3rem; }
.pick-buffett { font-size: 0.75rem; color: var(--text-2); margin-top: 0.25rem; }
.pick-stats { font-size: 0.75rem; color: var(--text-2); margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
/* Sparkline (#416 item 2): server-rendered 30-day trailing close line, no JS/library */
.pick-spark { display: block; width: 60px; height: 20px; margin-top: 0.4rem; }
.pick-spark polyline { stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.pick-spark.spark-up polyline { stroke: var(--up); }
.pick-spark.spark-down polyline { stroke: var(--down); }
.pick-verdict {
    display: inline-block; margin-top: 0.45rem; padding: 0.16rem 0.5rem;
    border-radius: var(--radius-xs); font-size: 0.72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.verdict-strong-buy, .verdict-buy, .verdict-accumulate { background: var(--up-soft); color: var(--up); }
.verdict-hold { background: var(--hold-soft); color: var(--hold); }
.verdict-reduce, .verdict-sell { background: var(--down-soft); color: var(--down); }

/* ── Utility ──────────────────────────────────────────────────────────── */
.mos-container { max-width: 1600px; margin: 0 auto; padding: 2rem 1.25rem; }
.mos-muted { color: var(--text-2); }
.mos-faint { color: var(--text-3); }
.mos-divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

@keyframes mos-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.mos-live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--up); box-shadow: 0 0 8px var(--up); animation: mos-pulse 2.4s infinite; display: inline-block; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
