/* ==========================================================================
   OwnThesis — Three-Panel Dashboard
   ========================================================================== */

/* ---------- CSS Variables ---------- */
:root {
    --color-buy: #22c55e;
    --color-wait: #f59e0b;
    --color-avoid: #ef4444;
    /* TODOS #10 headroom tiers — placeholder hex pending DESIGN.md (TODO #4).
       Values chosen so tier=green is visually indistinguishable from current
       BUY banner (no regression); yellow/orange shift toward caution. */
    --headroom-green:  #22c55e;  /* matches --color-buy so BUY-tier=green looks unchanged */
    --headroom-yellow: #f59e0b;  /* matches --color-wait */
    --headroom-orange: #ea580c;  /* new — between wait amber and avoid red */
    --sidebar-width: 260px;
    --header-height: 56px;

    --color-bg: #f5f7fa;
    --color-surface: #fff;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-dark: #0f172a;
    --color-dark-bg: #1e293b;
    --home-banner-height: 40px;

    /* Reframe T1 — v3 semantic palette（reframe spec §5 / v3 §2.1） */
    --conf-high:    #10b981;
    --conf-mid:     #f59e0b;
    --conf-low:     #94a3b8;

    --rr-green:     #10b981;
    --rr-yellow:    #fbbf24;
    --rr-orange:    #f97316;

    --semantic-info:      #3b82f6;
    --semantic-caution:   #f97316;
    --semantic-risk:      #ef4444;
    --semantic-positive:  #10b981;
    --semantic-neutral:   #f59e0b;

    --slate-900: #0f172a;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-50:  #f8fafc;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
}

/* ---------- Top Bar ---------- */
.top-bar {
    height: var(--header-height);
    background: #f7f7fa;
    color: var(--color-text);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.top-bar-left {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-bar-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text, #0f172a);
    text-decoration: none;
}

.top-bar-brand:hover {
    opacity: 0.85;
}

.top-bar-logo {
    flex: 0 0 auto;
}

.top-bar-brand-text {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.top-bar-center {
    flex: 1;
    max-width: 480px;
    margin: 0 auto;
}

.top-bar-input-group {
    display: flex;
    gap: 8px;
}

.ticker-input {
    flex: 1;
    padding: 7px 12px;
    font-size: 0.9rem;
    border: 2px solid rgba(15, 23, 42, 0.14);
    border-radius: 6px;
    outline: none;
    background: #fff;
    color: var(--color-text);
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.04em;
    transition: border-color 0.2s, background 0.2s;
}

.ticker-input::placeholder {
    color: rgba(30, 41, 59, 0.45);
}

.ticker-input:focus {
    border-color: var(--color-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.analyze-btn {
    padding: 7px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    background: var(--color-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}

.analyze-btn:hover {
    background: var(--color-primary-hover);
}

.analyze-btn:active {
    transform: scale(0.97);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.auto-refresh-badge {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.freshness-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: var(--color-text-muted);
}

.freshness-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    background: var(--color-text-muted);
}

.freshness-dot.freshness-fresh   { background: var(--color-buy); }
.freshness-dot.freshness-delayed { background: var(--color-wait); }
.freshness-dot.freshness-stale   { background: var(--color-avoid); }
.freshness-dot.freshness-unknown { background: var(--color-text-muted); }

.settings-btn {
    background: none;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 6px;
    padding: 5px 14px;
    font-size: 0.78rem;
    color: rgba(15, 23, 42, 0.72);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.settings-btn:hover {
    background: rgba(15, 23, 42, 0.06);
    color: var(--color-text);
    border-color: rgba(15, 23, 42, 0.24);
}

.sidebar-open-btn {
    background: none;
    border: none;
    color: rgba(15, 23, 42, 0.72);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
    line-height: 1;
}

.sidebar-open-btn:hover {
    color: var(--color-text);
    background: rgba(15, 23, 42, 0.06);
}

.calibration-link {
    color: rgba(15, 23, 42, 0.78);
    text-decoration: none;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 12px;
    letter-spacing: 0.03em;
    transition: all 0.15s;
    white-space: nowrap;
}
.calibration-link:hover {
    background: rgba(15, 23, 42, 0.06);
    color: var(--color-text);
    border-color: rgba(15, 23, 42, 0.24);
}

.lang-btn {
    background: none;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(15, 23, 42, 0.72);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    letter-spacing: 0.03em;
}

.lang-btn:hover {
    background: rgba(15, 23, 42, 0.06);
    color: var(--color-text);
    border-color: rgba(15, 23, 42, 0.24);
}

/* ---------- App Layout (sidebar + main) ---------- */
.app-layout {
    display: flex;
    position: fixed;
    top: calc(var(--header-height) + var(--home-banner-height));
    left: 0;
    right: 0;
    bottom: 0;
}

body.home-banner-hidden .app-layout {
    top: var(--header-height);
}

.home-hero-banner {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: var(--home-banner-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    z-index: 180;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.home-hero-banner.is-dismissing {
    opacity: 0;
    transform: translateY(-4px);
}

.home-hero-banner-msg {
    font-size: 0.9rem;
    font-weight: 600;
}

.home-hero-banner-close {
    position: absolute;
    right: 16px;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}

.home-hero-banner-close:hover {
    background: var(--color-border-light);
    color: var(--color-text);
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.25s ease, opacity 0.25s ease;
    z-index: 50;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 8px;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-dark);
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.sidebar-toggle-btn:hover {
    background: var(--color-border-light);
    color: var(--color-text-secondary);
}

.sidebar-filter {
    padding: 0 16px 8px;
    flex-shrink: 0;
}

.sidebar-filter-input {
    width: 100%;
    padding: 6px 10px;
    font-size: 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    outline: none;
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.15s;
}

.sidebar-filter-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.sidebar-scan-status {
    padding: 0 16px 6px;
    font-size: 0.72rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.sidebar-scan-btn {
    margin: 0 16px 10px;
    padding: 6px 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-primary);
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.sidebar-scan-btn:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--color-primary);
}

.sidebar-scan-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sidebar-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px 10px;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.spinner-small {
    width: 14px;
    height: 14px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.sidebar-stock-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 16px;
}

.sidebar-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    line-height: 1.5;
}

/* Sidebar groups */
.sidebar-group {
    margin-bottom: 4px;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s;
}

.sidebar-group-header:hover {
    background: var(--color-border-light);
}

.sidebar-group-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-group-label.group-buy  { color: var(--color-buy); }
.sidebar-group-label.group-wait { color: var(--color-wait); }
.sidebar-group-label.group-avoid { color: var(--color-avoid); }

.sidebar-group-chevron {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    transition: transform 0.2s;
}

.sidebar-group-chevron.collapsed {
    transform: rotate(-90deg);
}

.sidebar-group-items {
    overflow: hidden;
}

.sidebar-group-items.collapsed {
    display: none;
}

/* Sidebar stock item */
.sidebar-stock-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.1s;
    gap: 8px;
    border-left: 3px solid transparent;
}

.sidebar-stock-item:hover {
    background: var(--color-border-light);
}

.sidebar-stock-item.active {
    background: rgba(59, 130, 246, 0.06);
    border-left-color: var(--color-primary);
}

.sidebar-stock-info {
    flex: 1;
    min-width: 0;
}

.sidebar-stock-ticker {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-dark);
    letter-spacing: 0.02em;
}

.sidebar-stock-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums;
}

.sidebar-stock-price {
    font-weight: 600;
}

.sidebar-stock-change {
    font-weight: 600;
}

.sidebar-stock-change.positive { color: var(--color-buy); }
.sidebar-stock-change.negative { color: var(--color-avoid); }

.sidebar-stock-edge {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.sidebar-stock-arrow {
    font-size: 0.85rem;
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

.sidebar-stock-arrow.bullish { color: var(--color-buy); }
.sidebar-stock-arrow.bearish { color: var(--color-avoid); }
.sidebar-stock-arrow.neutral { color: var(--color-text-muted); }

/* Shared sizing + shape for the sidebar "+" / "−" quick-action buttons.
   Both render as a small round pill that is always visible; the row hover
   simply nudges the contrast up a notch so the affordance is discoverable
   but not loud. */
.sidebar-add-btn,
.sidebar-remove-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    line-height: 18px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #94a3b8;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    pointer-events: auto;
    /* visible by default; row hover / focus elevates the contrast */
}

.sidebar-stock-item:hover .sidebar-add-btn,
.sidebar-stock-item:hover .sidebar-remove-btn {
    border-color: #cbd5e1;
    color: var(--color-text-secondary);
}

.sidebar-add-btn:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.sidebar-remove-btn:hover {
    background: var(--color-avoid);
    color: #fff;
    border-color: var(--color-avoid);
}

.sidebar-add-btn:disabled,
.sidebar-remove-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ---------- Sidebar Overlay (mobile) ---------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0,0,0,0.3);
    z-index: 40;
}

.sidebar-overlay.visible {
    display: block;
}

/* ---------- Main Content ---------- */
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px 40px;
    min-width: 0;
}

.right-rail {
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    flex-shrink: 0;
    overflow-y: auto;
    padding: 16px;
    width: 320px;
}

.rr-module {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 14px;
}

.rr-module-title {
    color: var(--color-text);
    font-size: 0.98rem;
    font-weight: 700;
    margin: 0 0 12px;
}

.rr-methodology-cards {
    display: grid;
    gap: 10px;
}

.rr-highlight-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    display: grid;
    grid-template-columns: 30px 1fr;
    gap: 10px;
    padding: 10px;
}

.rr-highlight-icon {
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    display: flex;
    font-size: 1rem;
    height: 30px;
    justify-content: center;
    width: 30px;
}

.rr-highlight-copy h4 {
    color: var(--color-text);
    font-size: 0.9rem;
    margin: 0 0 4px;
}

.rr-highlight-copy p {
    color: var(--color-text-secondary);
    font-size: 0.78rem;
    line-height: 1.45;
    margin: 0;
}

.rr-glossary-preview {
    display: grid;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.rr-glossary-item a {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    display: block;
    padding: 9px 10px;
    text-decoration: none;
}

.rr-glossary-item strong {
    color: var(--color-text);
    display: block;
    font-size: 0.84rem;
    margin-bottom: 3px;
}

.rr-glossary-item span {
    color: var(--color-text-secondary);
    display: -webkit-box;
    font-size: 0.76rem;
    line-height: 1.4;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.rr-module-link {
    color: var(--semantic-info);
    display: inline-flex;
    font-size: 0.84rem;
    font-weight: 700;
    margin-top: 12px;
    text-decoration: none;
}

.rr-module-link:hover {
    text-decoration: underline;
}

.glossary-helper {
    align-items: center;
    background: var(--color-border);
    border-radius: 50%;
    color: var(--color-text-secondary);
    display: inline-flex;
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    height: 14px;
    justify-content: center;
    line-height: 1;
    margin-left: 4px;
    text-decoration: none;
    transition: background 0.12s ease, color 0.12s ease;
    vertical-align: middle;
    width: 14px;
}

.glossary-helper:hover,
.glossary-helper:focus-visible {
    background: var(--semantic-info);
    color: #fff;
    outline: none;
}

/* ---------- Error Alert ---------- */
.error-alert {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

/* ---------- Loading Spinner ---------- */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px 0;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Portfolio Dashboard ---------- */
.portfolio-dashboard {
    /* default view */
}

.section-heading {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-dark);
    margin-bottom: 16px;
}

/* ---------- Home Reframe T1 ---------- */
.home-candidates,
.home-retrospective {
    margin-bottom: 22px;
}

.home-candidates-header,
.home-retrospective-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.home-candidates-subtitle,
.home-retrospective-meta {
    min-height: 20px;
    margin: -10px 0 14px;
    color: var(--color-text-secondary);
    font-size: 0.86rem;
}

.home-candidates-updated {
    display: inline-block;
    margin-left: 12px;
    color: var(--color-text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
}

.home-candidates-see-all {
    align-self: flex-start;
    margin-top: 4px;
    color: var(--semantic-info);
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
}

.home-candidates-see-all:hover {
    text-decoration: underline;
}

.hcc-banner {
    margin: -4px 0 14px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.84rem;
    font-weight: 700;
}

.hcc-banner-info {
    background: color-mix(in srgb, var(--slate-500) 8%, var(--color-surface));
    color: var(--color-text-secondary);
}

.hcc-banner-warn {
    border-color: color-mix(in srgb, var(--semantic-caution) 40%, var(--color-border));
    background: color-mix(in srgb, var(--semantic-caution) 12%, var(--color-surface));
    color: var(--semantic-caution);
}

.home-candidates-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(220px, 1fr));
    gap: 14px;
}

@media (max-width: 1500px) {
    .home-candidates-grid {
        grid-template-columns: repeat(2, minmax(220px, 1fr));
    }
}

@media (max-width: 640px) {
    .home-candidates-grid {
        grid-template-columns: 1fr;
    }
}

.home-candidate-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    min-height: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid transparent;
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 1px 3px color-mix(in srgb, var(--slate-900) 5%, transparent);
}

.home-candidate-card.rr-tier-green { border-left-color: var(--rr-green); }
.home-candidate-card.rr-tier-yellow { border-left-color: var(--rr-yellow); }
.home-candidate-card.rr-tier-orange { border-left-color: var(--rr-orange); }

.hcc-header,
.hcc-price,
.hcc-badges {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.hcc-header {
    justify-content: space-between;
}

.hcc-index {
    color: var(--color-text-muted);
    font-size: 0.74rem;
    font-weight: 700;
}

.hcc-symbol {
    margin-right: auto;
    color: var(--slate-900);
    font-size: 1.05rem;
    font-weight: 800;
}

.hcc-pool-badge,
.hcc-badge {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    border-radius: 999px;
    padding: 3px 7px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.hcc-pool-badge.pool-ndx {
    background: var(--slate-900);
    color: var(--color-surface);
}

.hcc-pool-badge.pool-sp500 {
    background: color-mix(in srgb, var(--semantic-info) 12%, var(--color-surface));
    color: var(--semantic-info);
}

.hcc-price {
    justify-content: space-between;
}

.hcc-price-val {
    font-size: 1.38rem;
    font-weight: 800;
    color: var(--slate-900);
    font-variant-numeric: tabular-nums;
}

.hcc-change-pct {
    font-size: 0.82rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.hcc-change-pct.up,
.retro-positive {
    color: var(--semantic-positive);
}

.hcc-change-pct.down,
.retro-negative {
    color: var(--semantic-risk);
}

.hcc-badges {
    flex-wrap: wrap;
}

.hcc-badge-candidate {
    background: var(--slate-900);
    color: var(--color-surface);
}

.hcc-badge-evaluable {
    border: 1px solid var(--semantic-info);
    color: var(--semantic-info);
}

.hcc-badge-calib-calibrated {
    background: color-mix(in srgb, var(--semantic-positive) 12%, var(--color-surface));
    color: var(--semantic-positive);
}

.hcc-badge-calib-uncalibrated {
    background: color-mix(in srgb, var(--semantic-caution) 12%, var(--color-surface));
    color: var(--semantic-caution);
}

.hcc-badge-status {
    border: 1px solid transparent;
}

.hcc-status-pending,
.hcc-status-pre_entry {
    background: color-mix(in srgb, var(--slate-500) 10%, var(--color-surface));
    color: var(--color-text-secondary);
}

.hcc-status-in_entry_zone {
    background: color-mix(in srgb, var(--semantic-info) 12%, var(--color-surface));
    color: var(--semantic-info);
}

.hcc-status-entered {
    background: color-mix(in srgb, var(--semantic-positive) 12%, var(--color-surface));
    color: var(--semantic-positive);
}

.hcc-status-stop_broken {
    background: color-mix(in srgb, var(--semantic-risk) 12%, var(--color-surface));
    color: var(--semantic-risk);
}

.hcc-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.hcc-stats div {
    min-width: 0;
}

.hcc-stats dt {
    color: var(--color-text-muted);
    font-size: 0.68rem;
    font-weight: 700;
}

.hcc-stats dd {
    margin-top: 2px;
    color: var(--color-text);
    font-size: 0.82rem;
    font-weight: 700;
    word-break: break-word;
}

.conf-high,
.rr-green { color: var(--conf-high); }
.conf-mid { color: var(--conf-mid); }
.conf-low { color: var(--conf-low); }
.rr-yellow { color: var(--rr-yellow); }
.rr-orange { color: var(--rr-orange); }
.rr-unknown { color: var(--color-text-muted); }

.hcc-cta-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    margin-top: auto;
    border-radius: 7px;
    background: var(--color-primary);
    color: var(--color-surface);
    font-size: 0.88rem;
    font-weight: 800;
    text-decoration: none;
}

.hcc-cta-btn:hover {
    background: var(--color-primary-hover);
}

.hcc-sector-badge {
    display: block;
    padding: 8px 10px;
    margin: 8px 0;
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.4;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
}

.hcc-sector-badge strong {
    color: var(--color-text);
    font-weight: 700;
}

.hcc-sector-tier-S {
    background: rgba(16, 185, 129, 0.06);
    border-color: rgba(16, 185, 129, 0.24);
}

.hcc-sector-tier-A {
    background: rgba(59, 130, 246, 0.06);
    border-color: rgba(59, 130, 246, 0.24);
}

.hcc-sector-tier-warn {
    background: rgba(249, 115, 22, 0.08);
    border-color: rgba(249, 115, 22, 0.28);
}

.hcc-secondary-link {
    align-self: flex-start;
    border: 0;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
}

.hcc-reason-panel {
    max-height: 220px;
    overflow: auto;
    border-top: 1px solid var(--color-border-light);
    padding-top: 8px;
    color: var(--color-text-secondary);
    font-size: 0.8rem;
}

.hcc-reason-panel[data-loading="1"] {
    opacity: 0.6;
}

.hcc-reason-panel p {
    margin: 0 0 8px;
}

.hcc-reason-panel h3 {
    margin: 0 0 8px;
    color: var(--color-text);
    font-size: 0.9rem;
}

.hcc-reason-loading {
    color: var(--color-text-muted);
}

.hcc-reason-fallback {
    color: var(--semantic-info);
    font-weight: 700;
    text-decoration: none;
}

.home-candidates-empty,
.home-retrospective-empty {
    padding: 18px;
    border: 1px dashed var(--color-border);
    border-radius: 8px;
    color: var(--color-text-secondary);
    background: var(--color-surface);
}

.home-retrospective-empty.is-error {
    color: var(--semantic-risk);
}

.home-candidates-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-top: 12px;
    color: var(--color-text-secondary);
    font-size: 0.78rem;
}

.rr-bar-demo {
    display: inline-block;
    width: 3px;
    height: 14px;
    margin-right: 5px;
    vertical-align: -2px;
}

.rr-bar-demo.rr-tier-green { background: var(--rr-green); }
.rr-bar-demo.rr-tier-yellow { background: var(--rr-yellow); }
.rr-bar-demo.rr-tier-orange { background: var(--rr-orange); }

.home-retrospective {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 16px;
}

.home-retrospective-alpha-badge {
    border-radius: 999px;
    padding: 5px 10px;
    background: color-mix(in srgb, var(--semantic-positive) 12%, var(--color-surface));
    color: var(--semantic-positive);
    font-size: 0.78rem;
    font-weight: 800;
}

.home-retro-source-badge {
    margin-left: auto;
    border-radius: 999px;
    padding: 5px 10px;
    background: color-mix(in srgb, var(--semantic-info) 12%, var(--color-surface));
    color: var(--semantic-info);
    font-size: 0.78rem;
    font-weight: 800;
}

.home-retrospective-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.home-retrospective-table th,
.home-retrospective-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--color-border-light);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.home-retrospective-table th:first-child,
.home-retrospective-table td:first-child {
    text-align: left;
    font-weight: 800;
}

.home-retrospective-table tr.beat-spy {
    background: color-mix(in srgb, var(--semantic-positive) 4%, var(--color-surface));
}

.home-retrospective-link {
    display: inline-block;
    margin-top: 12px;
    color: var(--semantic-info);
    font-size: 0.84rem;
    font-weight: 700;
    text-decoration: none;
}

.home-retrospective-refresh {
    margin-left: 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--semantic-info);
    padding: 4px 8px;
    cursor: pointer;
}

.portfolio-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.portfolio-card {
    background: var(--color-surface);
    border-radius: 8px;
    border: 2px solid var(--color-border);
    padding: 14px 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.portfolio-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.portfolio-card.border-exit { border-color: var(--color-avoid); }
.portfolio-card.border-trim { border-color: #f97316; }
.portfolio-card.border-add  { border-color: var(--color-buy); }
.portfolio-card.border-hold { border-color: #9ca3af; }

.pf-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

/* "×" remove-from-watchlist button on watch overview cards.
   Anchored to the top-right of the card; muted by default, red on hover.
   Click handler stops propagation so it doesn't trigger the card's analyze. */
.pf-card-remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    line-height: 20px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #94a3b8;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    z-index: 1;
}
.portfolio-card:hover .pf-card-remove-btn {
    border-color: #cbd5e1;
    color: var(--color-text-secondary);
}
.pf-card-remove-btn:hover {
    background: var(--color-avoid);
    color: #fff;
    border-color: var(--color-avoid);
}
.pf-card-remove-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}
@media (hover: none) {
    .pf-card-remove-btn {
        width: 26px;
        height: 26px;
        line-height: 24px;
        font-size: 1.05rem;
    }
}

.pf-card-symbol {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-dark);
    letter-spacing: 0.02em;
}

.pf-card-name {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-left: 6px;
    font-weight: 400;
}

.pf-card-action {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.04em;
}

.pf-card-action.action-exit { background: #fef2f2; color: #dc2626; }
.pf-card-action.action-trim { background: #fff7ed; color: #ea580c; }
.pf-card-action.action-add  { background: #f0fdf4; color: #16a34a; }
.pf-card-action.action-hold { background: #f3f4f6; color: #6b7280; }
.pf-card-action.action-buy  { background: #f0fdf4; color: #16a34a; }
.pf-card-action.action-avoid { background: #fef2f2; color: #dc2626; }
.pf-card-action.action-wait { background: #fffbeb; color: #d97706; }

.pf-card-mid {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-variant-numeric: tabular-nums;
}

.pf-card-price {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text);
}

.pf-card-change {
    font-size: 0.82rem;
    font-weight: 600;
}

.pf-card-change.positive { color: var(--color-buy); }
.pf-card-change.negative { color: var(--color-avoid); }

.pf-card-flag {
    margin-left: auto;
}

.pf-card-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    flex-wrap: wrap;
}

.pf-card-regime-setup {
    font-weight: 500;
}

.pf-card-edge {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.pf-card-pnl {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
}

.pf-card-pnl.pnl-positive { color: var(--color-buy); }
.pf-card-pnl.pnl-negative { color: var(--color-avoid); }

.portfolio-empty {
    text-align: center;
    color: var(--color-text-muted);
    padding: 40px 20px;
    font-size: 0.9rem;
}

.watch-heading {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
}

/* ---------- Detail View ---------- */
.detail-view {
    /* shown when a stock is selected */
}

.back-btn {
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 16px;
    transition: color 0.15s;
}

.back-btn:hover {
    color: var(--color-primary-hover);
}

/* ---------- Analysis Card ---------- */
.analysis-card {
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 0;
    margin-bottom: 20px;
    overflow: hidden;
}

/* Price Header */
.price-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--color-border-light);
}

.price-header-left {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.symbol {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-dark);
    letter-spacing: 0.03em;
}

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

.price-header-right {
    display: flex;
    align-items: baseline;
    gap: 10px;
    text-align: right;
}

.price {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-dark);
    font-variant-numeric: tabular-nums;
}

.change-pct {
    font-size: 0.95rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.change-pct.positive { color: var(--color-buy); }
.change-pct.negative { color: var(--color-avoid); }

/* ---------- Signal Banner ---------- */
.signal-banner {
    padding: 14px 20px;
    color: #fff;
    transition: background 0.3s;
}

.signal-banner.buy {
    background: linear-gradient(135deg, #16a34a, #22c55e);
}

.signal-banner.avoid {
    background: linear-gradient(135deg, #dc2626, #ef4444);
}

.signal-banner.wait {
    background: linear-gradient(135deg, #d97706, #f59e0b);
}

/* Headroom tier overrides on the BUY banner (TODOS #10) */
.signal-banner.buy[data-headroom-tier="green"] {
    background: linear-gradient(135deg, var(--headroom-green), #4ade80);
}
.signal-banner.buy[data-headroom-tier="yellow"] {
    background: linear-gradient(135deg, var(--headroom-yellow), #fbbf24);
}
.signal-banner.buy[data-headroom-tier="orange"] {
    background: linear-gradient(135deg, var(--headroom-orange), #fb923c);
}

/* T2 reframe: setup-tone driven banner recolor. BUY + headroom tier keeps the
   existing TODOS #10 data-headroom-tier gradients above. */
.signal-banner[data-setup-tone="positive"] {
    background: linear-gradient(135deg, var(--semantic-positive), var(--rr-green));
}

.signal-banner[data-setup-tone="neutral"] {
    background: linear-gradient(135deg, var(--color-dark-bg), var(--slate-500));
}

.signal-banner[data-setup-tone="risk"] {
    background: linear-gradient(135deg, var(--semantic-caution), var(--semantic-risk));
}

.hidden-in-reframe {
    display: none !important;
}

.signal-confidence-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.signal-confidence-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.82rem;
    background: rgba(255, 255, 255, 0.14);
    color: var(--color-surface);
    border: 1px solid rgba(255, 255, 255, 0.22);
    font-variant-numeric: tabular-nums;
}

.signal-confidence-pill.conf-high {
    background: rgba(16, 185, 129, 0.22);
    border-color: var(--conf-high);
}

.signal-confidence-pill.conf-mid {
    background: rgba(245, 158, 11, 0.22);
    border-color: var(--conf-mid);
}

.signal-confidence-pill.conf-low {
    background: rgba(148, 163, 184, 0.22);
    border-color: var(--conf-low);
}

.signal-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.signal-row:last-child {
    margin-bottom: 0;
}

.signal-flags {
    margin-top: 2px;
}

.signal-regime,
.signal-setup {
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.signal-divider {
    opacity: 0.5;
    font-size: 0.85rem;
}

.signal-action {
    font-weight: 700;
    font-size: 0.9rem;
}

.signal-metrics {
    font-size: 0.85rem;
    opacity: 0.92;
    margin-top: 2px;
}

.signal-metrics strong {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.detail-status-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 12px;
}

.detail-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.detail-badge-candidate {
    background: var(--slate-900);
    color: var(--color-surface);
}

.detail-badge-pool {
    background: rgba(59, 130, 246, 0.12);
    color: var(--semantic-info);
    border: 1px solid rgba(59, 130, 246, 0.35);
}

.detail-badge-calib {
    background: var(--slate-50);
    color: var(--slate-500);
    border: 1px solid var(--color-border);
}

.detail-badge-calib.calib-calibrated {
    background: rgba(16, 185, 129, 0.1);
    color: var(--semantic-positive);
    border-color: rgba(16, 185, 129, 0.3);
}

.detail-badge-calib.calib-uncalibrated {
    background: rgba(249, 115, 22, 0.1);
    color: var(--semantic-caution);
    border-color: rgba(249, 115, 22, 0.3);
}

.signal-snapshot-panel {
    margin: 16px 20px 0;
    padding: 16px 18px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
}

.signal-snapshot-title {
    margin: 0 0 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--slate-900);
}

.signal-snapshot-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.sss-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    background: var(--slate-50);
    border-radius: 6px;
}

.sss-item-wide {
    grid-column: span 2;
}

.sss-label {
    font-size: 0.72rem;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sss-value {
    font-size: 0.9rem;
    color: var(--slate-900);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.sss-percentile-bar {
    position: relative;
    height: 18px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}

.sss-percentile-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: linear-gradient(90deg, var(--conf-low), var(--semantic-positive));
    transition: width 0.3s ease;
}

.sss-percentile-label {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--slate-900);
}

.calibration-disclosure {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--slate-50);
    border-left: 3px solid var(--slate-400);
    font-size: 0.86rem;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.calibration-disclosure.calib-calibrated {
    background: rgba(16, 185, 129, 0.06);
    border-left-color: var(--semantic-positive);
}

.calibration-disclosure.calib-uncalibrated {
    background: rgba(249, 115, 22, 0.06);
    border-left-color: var(--semantic-caution);
}

.calibration-disclosure-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.calibration-disclosure-text {
    color: var(--slate-900);
}

.detail-footer-ctas {
    display: flex;
    gap: 12px;
    padding: 20px;
    margin-top: 8px;
    border-top: 1px solid var(--color-border);
}

.detail-cta-btn {
    flex: 1;
    padding: 14px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.detail-cta-primary {
    background: var(--color-primary);
    color: var(--color-surface);
}

.detail-cta-primary:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.detail-cta-secondary {
    background: var(--color-surface);
    color: var(--slate-900);
    border-color: var(--color-border);
}

.detail-cta-secondary:hover {
    background: var(--slate-50);
    border-color: var(--slate-400);
}

.signal-flag-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.signal-flag-warn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff7ed;
    border: 1px solid rgba(255, 247, 237, 0.4);
}

.action-buy   { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.action-avoid { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.action-exit  { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.action-trim  { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.action-add   { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.action-hold  { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.action-wait  { text-shadow: 0 1px 2px rgba(0,0,0,0.2); }

/* ---------- Sections within analysis card ---------- */
.reasons-section,
.context-section,
.indicator-section,
.zones-section,
.trading-levels-section,
.sizing-section,
.pnl-section {
    padding: 16px 20px;
    border-top: 1px solid var(--color-border-light);
}

.reasons-section h3,
.context-section h3,
.indicator-section h3,
.zones-section h3,
.trading-levels-section h3,
.sizing-section h3,
.pnl-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}

/* Reasons */
.reasons-section ul {
    list-style: none;
    padding: 0;
}

.reasons-section li {
    padding: 4px 0;
    padding-left: 16px;
    position: relative;
    font-size: 0.9rem;
    color: #334155;
}

.reasons-section li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 12px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-muted);
}

/* ---------- Context Section ---------- */
.context-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.context-card {
    background: #f8fafc;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 10px 12px;
}

.context-card-wide {
    grid-column: span 2;
}

.context-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.context-body {
    font-size: 0.9rem;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.context-adjustments {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--color-border);
}

.context-adjustments h4 {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.context-adjustments ul {
    list-style: none;
}

.context-adjustments li {
    padding: 4px 0 4px 16px;
    position: relative;
    font-size: 0.88rem;
    color: #334155;
}

.context-adjustments li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 11px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
}

/* ---------- Indicator Grid ---------- */
.indicator-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.indicator-card {
    background: #f8fafc;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: border-color 0.2s;
}

.indicator-card:hover {
    border-color: var(--color-border);
}

.indicator-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.indicator-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.indicator-value.ind-overbought { color: var(--color-avoid); }
.indicator-value.ind-oversold   { color: var(--color-buy); }

/* ---------- Zones ---------- */
.zones-row {
    display: flex;
    gap: 24px;
}

.zones-group {
    flex: 1;
}

.zones-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

.zones-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.zone-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 0.82rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: transform 0.15s;
}

.zone-badge:hover {
    transform: translateY(-1px);
}

.zone-badge.support {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

.zone-badge.resistance {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* ---------- Trading Levels (stop + take-profit) ---------- */
.trading-levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.trading-level-item {
    background: #f8fafc;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 8px 12px;
}

.trading-level-item-stop {
    background: #fef2f2;
    border-color: #fecaca;
}

.trading-level-item-primary {
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.trading-level-item-stretch {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.trading-level-item-rr {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.trading-level-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.trading-level-basis {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    color: #94a3b8;
    font-size: 0.7rem;
}

.trading-level-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.trading-level-value.rr-tier-green  { color: var(--headroom-green); }
.trading-level-value.rr-tier-yellow { color: var(--headroom-yellow); }
.trading-level-value.rr-tier-orange { color: var(--headroom-orange); }

/* ---------- Sizing Grid ---------- */
.sizing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.sizing-item {
    background: #f8fafc;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 8px 12px;
}

.sizing-item-emphasis {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.sizing-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.sizing-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.context-warning-banner {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.84rem;
    margin-bottom: 10px;
}

/* ---------- P&L Grid ---------- */
.pnl-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.pnl-item {
    background: #f8fafc;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 8px 12px;
}

.pnl-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.pnl-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.pnl-positive { color: var(--color-buy) !important; }
.pnl-negative { color: var(--color-avoid) !important; }

/* ---------- Options Section ---------- */
.options-section {
    padding: 16px 20px;
    border-top: 1px solid var(--color-border-light);
}

.options-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}

.options-meta {
    display: flex;
    gap: 16px;
    font-size: 0.82rem;
    color: var(--color-text-secondary);
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.options-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.options-meta-label {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
}

.options-candidate {
    background: #f8fafc;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}

.options-candidate:hover {
    border-color: var(--color-border);
}

.options-candidate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.options-candidate-family {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-dark);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.options-candidate-rank {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

.options-candidate-rank.rank-high   { background: #f0fdf4; color: #16a34a; }
.options-candidate-rank.rank-medium { background: #fffbeb; color: #d97706; }
.options-candidate-rank.rank-low    { background: #fef2f2; color: #dc2626; }

.options-candidate-rank {
    cursor: help;
}

.options-legs {
    font-size: 0.82rem;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.options-leg {
    display: flex;
    gap: 12px;
    padding: 2px 0;
}

.options-leg-action {
    font-weight: 700;
    min-width: 36px;
}

.options-leg-action.buy-action  { color: var(--color-buy); }
.options-leg-action.sell-action { color: var(--color-avoid); }

.options-metrics {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums;
}

.options-metric-label {
    font-weight: 600;
    color: var(--color-text-muted);
}

.options-not-eligible {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-style: italic;
    padding: 8px 0;
}

.options-degraded-banner {
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 6px;
    color: #ffc107;
    font-size: 0.82rem;
    padding: 8px 12px;
    margin-bottom: 12px;
}

/* ---------- Chart Section ---------- */
.chart-section {
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 18px 20px;
    margin-bottom: 20px;
}

.chart-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}

.chart-wrapper {
    position: relative;
    width: 100%;
}

/* ---------- Footer ---------- */
.app-footer {
    position: fixed;
    bottom: 0;
    right: 0;
    padding: 8px 16px;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-style: italic;
    pointer-events: none;
    z-index: 10;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 680px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 0;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-dark);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--color-avoid);
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    gap: 0;
    padding: 16px 24px 0;
    border-bottom: 1px solid var(--color-border);
}

.modal-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 20px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.modal-tab:hover {
    color: #475569;
}

.modal-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.modal-tab-content {
    padding: 20px 24px 24px;
}

/* Position Form */
.position-form {
    margin-bottom: 20px;
}

.position-form h4,
.form-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 100px;
}

.form-group.wide {
    min-width: 180px;
}

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group input {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--color-text);
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

.form-group input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input-prefix,
.input-suffix {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-weight: 600;
}

.input-prefix input,
.input-suffix input {
    flex: 1;
}

.form-hint {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.form-submit-btn {
    padding: 8px 22px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    align-self: flex-end;
}

.form-submit-btn:hover {
    background: var(--color-primary-hover);
}

.form-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border-light);
}

.form-section:last-of-type {
    border-bottom: none;
}

/* Position Table */
.position-table-wrap {
    overflow-x: auto;
}

.position-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.position-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 12px;
    border-bottom: 2px solid var(--color-border-light);
}

.position-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f8fafc;
    color: #334155;
    font-variant-numeric: tabular-nums;
}

.position-table tr:hover td {
    background: #f8fafc;
}

.position-table .empty-row {
    text-align: center;
    color: var(--color-text-muted);
    padding: 20px;
}

.delete-btn {
    background: none;
    border: 1px solid #fecaca;
    border-radius: 4px;
    color: var(--color-avoid);
    padding: 3px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s;
}

.delete-btn:hover {
    background: #fef2f2;
    border-color: var(--color-avoid);
}

.edit-btn {
    background: none;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    color: var(--color-primary);
    padding: 3px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    margin-right: 6px;
    transition: all 0.15s;
}

.edit-btn:hover {
    background: #eff6ff;
    border-color: var(--color-primary);
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-dark);
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    z-index: 2000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: toastIn 0.3s ease-out;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(12px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.35s ease-out;
}

/* ---------- Responsive ---------- */

/* Medium screens */
@media (max-width: 1100px) {
    .portfolio-cards {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

/* Small screens: sidebar becomes a drawer */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 50;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.12);
        margin-left: 0;
        opacity: 1;
    }

    .sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width));
        opacity: 0;
        pointer-events: none;
    }

    .top-bar-brand-text {
        font-size: 1rem;
    }

    .top-bar {
        gap: 10px;
        padding: 0 12px;
    }

    .top-bar-center {
        max-width: 320px;
    }

    .price-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .price-header-right {
        text-align: left;
    }

    .indicator-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .context-grid {
        grid-template-columns: 1fr;
    }

    .context-card-wide {
        grid-column: span 1;
    }

    .pnl-grid {
        grid-template-columns: 1fr;
    }

    .signal-snapshot-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sss-item-wide {
        grid-column: span 2;
    }

    .detail-footer-ctas {
        flex-direction: column;
    }

    .zones-row {
        flex-direction: column;
        gap: 12px;
    }

    .portfolio-cards {
        grid-template-columns: 1fr;
    }

    .signal-row {
        flex-wrap: wrap;
    }
}

/* Extra small screens */
@media (max-width: 600px) {
    .top-bar {
        gap: 6px;
        padding: 0 8px;
    }

    .top-bar-brand-text {
        font-size: 0.95rem;
    }

    .top-bar-logo {
        width: 24px;
        height: 24px;
    }

    .top-bar-center {
        max-width: 200px;
    }

    .ticker-input {
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .analyze-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .auto-refresh-badge,
    .freshness-badge {
        display: none;
    }

    .main-content {
        padding: 14px 12px 32px;
    }
}

/* ---------- Edit Position pill (on stock detail header) ---------- */
.edit-position-pill {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: var(--color-primary);
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.15s;
    white-space: nowrap;
}
.edit-position-pill:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

/* ---------- Edit Position modal overrides ---------- */
.modal-content.modal-content-narrow {
    max-width: 520px;
}

.modal-body {
    padding: 14px 24px 22px;
}

.modal-footer-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
    flex-wrap: wrap;
}

.form-cancel-btn {
    background: #fff;
    border: 1px solid var(--color-border-light);
    color: var(--color-text-muted);
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.form-cancel-btn:hover {
    background: #f8fafc;
    color: var(--color-text);
}

.form-delete-btn {
    background: #fff;
    border: 1px solid #fecaca;
    color: var(--color-avoid, #dc2626);
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    margin-right: auto; /* push delete to the left of Cancel + Save */
}
.form-delete-btn:hover {
    background: #fef2f2;
    border-color: var(--color-avoid, #dc2626);
}

#editPosTicker[readonly] {
    background: #f1f5f9;
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* ==========================================================================
   Feature 4 — Mobile / touch polish
   Kept in a single block so the mobile tweaks are easy to audit & revert.
   ========================================================================== */

/* iOS Safari auto-zooms any input whose font-size is < 16px. Bumping inputs
   on phone-sized viewports fixes the jarring zoom-on-focus without affecting
   the desktop layout. */
@media (max-width: 900px) {
    .ticker-input,
    .sidebar-filter-input,
    .form-group input,
    #editPosTicker {
        font-size: 16px;
    }
}

/* Widen the sidebar drawer slightly on phones so the ticker + meta row
   doesn't feel cramped; cap at 85vw so the backdrop overlay stays visible
   as an affordance to close. */
@media (max-width: 900px) {
    .sidebar {
        width: min(300px, 85vw);
        min-width: 0;
    }
    .sidebar.collapsed {
        margin-left: calc(-1 * min(300px, 85vw));
    }
}

/* Devices that can't hover (touch phones/tablets) need permanently-visible
   action buttons and finger-sized hit areas (~36px min). */
@media (hover: none) {
    .sidebar-add-btn,
    .sidebar-remove-btn {
        width: 28px;
        height: 28px;
        line-height: 26px;
        font-size: 1.05rem;
    }
    .edit-btn,
    .delete-btn {
        padding: 6px 12px;
        font-size: 0.82rem;
    }
    .form-cancel-btn,
    .form-delete-btn,
    .form-submit-btn {
        padding: 10px 18px;
        font-size: 0.9rem;
    }
    .modal-close {
        padding: 6px 10px;
        font-size: 1.8rem;
    }
    .sidebar-stock-item {
        padding: 10px 16px;      /* taller row for tap */
    }
}

/* iPhone-class portrait viewports: reclaim horizontal space by collapsing
   the dashboard grids and trimming header chrome. */
@media (max-width: 480px) {
    .top-bar {
        gap: 4px;
        padding: 0 6px;
    }
    .top-bar-brand-text {
        display: none;           /* keep the ☰ button, ditch the wordmark */
    }
    .top-bar-center {
        max-width: none;
        flex: 1;
    }
    .top-bar-right {
        gap: 6px;
    }
    /* Keep the cog icon; drop the "设置 / Settings" label. */
    .settings-btn [data-i18n="settings"] {
        display: none;
    }
    .settings-btn {
        padding: 5px 8px;
    }
    .lang-btn {
        padding: 3px 7px;
    }

    .main-content {
        padding: 12px 10px 28px;
    }

    .section-heading {
        font-size: 0.98rem;
        margin-bottom: 12px;
    }

    .indicator-grid,
    .sizing-grid,
    .trading-levels-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .price-header {
        padding: 14px 14px;
    }
    .symbol { font-size: 1.2rem; }
    .price  { font-size: 1.2rem; }
    .change-pct { font-size: 0.88rem; }
    .company-name { font-size: 0.82rem; }
    .edit-position-pill {
        margin-left: 0;
        padding: 4px 10px;
    }

    /* Section padding inside the analysis card — tighter so content isn't
       dwarfed by chrome on small screens. */
    .reasons-section,
    .context-section,
    .indicator-section,
    .zones-section,
    .trading-levels-section,
    .sizing-section,
    .pnl-section,
    .options-section {
        padding: 14px 14px;
    }

    .chart-section {
        padding: 14px;
    }

    /* Modal takes the full width on tiny screens. Side-gutter = 2.5vw. */
    .modal-content {
        width: 95%;
        max-width: 100%;
        border-radius: 10px;
        max-height: 92vh;
    }
    .modal-header     { padding: 16px 16px 0; }
    .modal-header h2  { font-size: 1.05rem; }
    .modal-body       { padding: 10px 16px 18px; }
    .modal-tab-content { padding: 14px 16px 18px; }
    .modal-tabs        { padding: 12px 16px 0; }
    .modal-tab         { padding: 6px 12px 10px; font-size: 0.82rem; }

    .form-row {
        gap: 8px;
    }
    .form-group {
        min-width: 0;            /* allow shrinking on narrow rows */
    }
    .form-group.wide {
        min-width: 0;
        flex-basis: 100%;        /* stretch wide inputs to full width */
    }

    /* Position table on the modal becomes more breathable. */
    .position-table th,
    .position-table td {
        padding: 8px 8px;
    }
    .position-table {
        font-size: 0.82rem;
    }

    /* Fixed footer credit is noise on a phone — hide it. */
    .app-footer {
        display: none;
    }
}

/* iOS safe-area insets — respect the bottom notch bar & home indicator
   so the fixed footer (desktop) doesn't clip under the system chrome. */
@supports (padding: max(0px)) {
    .app-footer {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    .top-bar {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* ===================================================================
   Newsletter Candidates Panel
   Sits above the portfolio dashboard on the home view. Highlights
   durable, backtest-validated buy signals (uptrend_breakout + gated
   range_rebound) for copy-paste into the newsletter.
   =================================================================== */

.newsletter-panel {
    margin: 12px 0 20px 0;
    background: linear-gradient(135deg, #162238 0%, #1a2b47 100%);
    border: 1px solid rgba(100, 180, 255, 0.25);
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.newsletter-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.newsletter-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.newsletter-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    color: #e8f1ff;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.02em;
}

.newsletter-icon {
    font-size: 16px;
}

.newsletter-count {
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(100, 180, 255, 0.18);
    color: #aecbff;
    letter-spacing: 0.04em;
}

.newsletter-count.zero {
    background: rgba(180, 180, 180, 0.1);
    color: rgba(255, 255, 255, 0.4);
}

.newsletter-actions {
    display: flex;
    gap: 6px;
}

.newsletter-btn {
    background: rgba(100, 180, 255, 0.12);
    color: #cfe3ff;
    border: 1px solid rgba(100, 180, 255, 0.3);
    border-radius: 5px;
    padding: 4px 12px;
    font-size: 12px;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.15s;
}

.newsletter-btn:hover {
    background: rgba(100, 180, 255, 0.22);
    color: #ffffff;
    border-color: rgba(100, 180, 255, 0.5);
}

.newsletter-btn.copied {
    background: rgba(80, 200, 120, 0.25);
    border-color: rgba(80, 200, 120, 0.5);
    color: #d0f4d8;
}

.newsletter-btn-ghost {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.5);
    padding: 4px 10px;
    font-weight: 500;
    text-decoration: none;
}

.newsletter-btn-ghost:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.newsletter-btn-primary {
    background: linear-gradient(135deg,
        rgba(120, 200, 140, 0.28),
        rgba(90, 170, 255, 0.28));
    border-color: rgba(140, 210, 180, 0.55);
    color: #eafff0;
    font-weight: 600;
}

.newsletter-btn-primary:hover {
    background: linear-gradient(135deg,
        rgba(120, 200, 140, 0.42),
        rgba(90, 170, 255, 0.42));
    border-color: rgba(160, 230, 200, 0.8);
    color: #ffffff;
}

.newsletter-btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.newsletter-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.newsletter-draft-status {
    margin-top: 10px;
    padding: 8px 12px;
    font-size: 12px;
    letter-spacing: 0.02em;
    background: rgba(80, 180, 120, 0.08);
    border-left: 3px solid rgba(80, 200, 140, 0.5);
    color: #d8f3e0;
    border-radius: 3px;
    line-height: 1.5;
}

.newsletter-draft-status.error {
    background: rgba(220, 90, 90, 0.08);
    border-left-color: rgba(220, 90, 90, 0.6);
    color: #f4d0d0;
}

.newsletter-filter {
    margin-top: 8px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    letter-spacing: 0.04em;
    font-family: "SF Mono", Monaco, Menlo, monospace;
}

.newsletter-body {
    min-height: 40px;
}

.newsletter-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.newsletter-item {
    display: grid;
    grid-template-columns: 70px 150px 80px 80px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    font-size: 13px;
    color: #e8f1ff;
    transition: background 0.12s;
    cursor: pointer;
}

.newsletter-item:hover {
    background: rgba(100, 180, 255, 0.09);
    border-color: rgba(100, 180, 255, 0.22);
}

.newsletter-item-symbol {
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #ffffff;
}

.newsletter-item-setup {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.03em;
    font-family: "SF Mono", Monaco, Menlo, monospace;
    white-space: nowrap;
    justify-self: start;
}

.newsletter-item-setup.breakout {
    background: rgba(80, 200, 120, 0.15);
    color: #a8e8c0;
    border: 1px solid rgba(80, 200, 120, 0.3);
}

.newsletter-item-setup.rebound {
    background: rgba(255, 180, 100, 0.12);
    color: #ffd4a1;
    border: 1px solid rgba(255, 180, 100, 0.28);
}

.newsletter-item-metric {
    font-size: 12px;
    font-family: "SF Mono", Monaco, Menlo, monospace;
    color: rgba(255, 255, 255, 0.75);
    font-variant-numeric: tabular-nums;
}

.newsletter-item-metric .label {
    color: rgba(255, 255, 255, 0.4);
    margin-right: 4px;
    font-size: 10px;
    text-transform: uppercase;
}

.newsletter-item-price {
    font-size: 12px;
    font-family: "SF Mono", Monaco, Menlo, monospace;
    color: rgba(255, 255, 255, 0.65);
    font-variant-numeric: tabular-nums;
    text-align: left;
}

.newsletter-item-change {
    font-size: 11px;
    font-family: "SF Mono", Monaco, Menlo, monospace;
    font-variant-numeric: tabular-nums;
}

.newsletter-item-change.up { color: #81e4a2; }
.newsletter-item-change.down { color: #ff9a9a; }

.newsletter-item-flag {
    font-size: 14px;
    justify-self: end;
}

.newsletter-empty {
    padding: 14px 10px;
    color: rgba(255, 255, 255, 0.55);
    font-size: 13px;
    text-align: center;
}

.newsletter-empty code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 11px;
    color: #cfe3ff;
}

.newsletter-footer {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    letter-spacing: 0.03em;
}

.newsletter-footer .backing-link {
    color: #aecbff;
    text-decoration: none;
    border-bottom: 1px dotted rgba(174, 203, 255, 0.4);
    transition: color 0.15s;
}

.newsletter-footer .backing-link:hover {
    color: #ffffff;
    border-bottom-color: #ffffff;
}

/* Collapsed state */
.newsletter-panel.collapsed .newsletter-body,
.newsletter-panel.collapsed .newsletter-footer,
.newsletter-panel.collapsed .newsletter-filter {
    display: none;
}

.newsletter-panel.collapsed .newsletter-header {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* Mobile: collapse grid into two lines */
@media (max-width: 640px) {
    .newsletter-item {
        grid-template-columns: 70px 1fr auto;
        grid-template-rows: auto auto;
        gap: 4px 8px;
    }
    .newsletter-item-setup {
        grid-column: 2;
        grid-row: 1;
    }
    .newsletter-item-flag {
        grid-column: 3;
        grid-row: 1;
    }
    .newsletter-item-metric,
    .newsletter-item-price,
    .newsletter-item-change {
        grid-column: 1 / -1;
        grid-row: 2;
        font-size: 11px;
    }
}

/* AI commentary button + expandable blurb area */

.newsletter-item-wrap {
    list-style: none;
    margin: 0;
    padding: 0;
}

.newsletter-item {
    /* Re-spec for use inside .newsletter-item-wrap (li). We used to style
       the <li> directly; now the row is the same grid but nested. */
    margin: 0;
}

.newsletter-item-ai-btn {
    background: rgba(140, 100, 220, 0.15);
    color: #d8c6ff;
    border: 1px solid rgba(140, 100, 220, 0.4);
    border-radius: 4px;
    padding: 3px 9px;
    font-size: 11px;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all 0.12s;
    white-space: nowrap;
    justify-self: end;
}

.newsletter-item-ai-btn:hover:not(:disabled) {
    background: rgba(140, 100, 220, 0.28);
    color: #ffffff;
    border-color: rgba(140, 100, 220, 0.65);
}

.newsletter-item-ai-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* Update grid to include the AI button column */
.newsletter-item {
    grid-template-columns: 70px 150px 80px 80px 1fr auto auto;
}

.newsletter-blurb {
    margin-top: 6px;
    margin-bottom: 10px;
    padding: 14px 18px;
    background: rgba(140, 100, 220, 0.06);
    border: 1px solid rgba(140, 100, 220, 0.22);
    border-radius: 6px;
    color: #dfe7f4;
    font-size: 13px;
    line-height: 1.65;
}

.newsletter-blurb-loading {
    color: rgba(255, 255, 255, 0.55);
    text-align: center;
    padding: 8px;
    font-style: italic;
}

.newsletter-blurb-error {
    background: rgba(255, 120, 120, 0.08);
    color: #ffb0b0;
    padding: 10px 12px;
    border-radius: 4px;
    font-size: 12px;
    border-left: 3px solid rgba(255, 100, 100, 0.5);
}

.newsletter-blurb-meta {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 10px;
    font-family: "SF Mono", Monaco, Menlo, monospace;
}

.newsletter-blurb-warn {
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(255, 180, 80, 0.08);
    color: #ffd694;
    border-left: 3px solid rgba(255, 180, 80, 0.5);
    border-radius: 3px;
    font-size: 11px;
}

.newsletter-blurb-warn code {
    background: rgba(0, 0, 0, 0.25);
    padding: 1px 5px;
    border-radius: 3px;
    color: #fff;
}

.newsletter-blurb-body h3 {
    color: #ffffff;
    font-size: 15px;
    margin: 0 0 10px 0;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.newsletter-blurb-body p {
    margin: 8px 0;
    color: rgba(223, 231, 244, 0.92);
}

.newsletter-blurb-body strong {
    color: #c9d9ff;
    font-weight: 600;
}

.newsletter-blurb-body ul {
    margin: 6px 0 10px 0;
    padding-left: 22px;
}

.newsletter-blurb-body li {
    margin: 2px 0;
    color: rgba(223, 231, 244, 0.88);
}

.newsletter-blurb-body em {
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    font-style: normal;
}

.newsletter-blurb-body hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 10px 0;
}

.newsletter-blurb-actions {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(140, 100, 220, 0.18);
    display: flex;
    gap: 8px;
}

.newsletter-blurb-copy {
    background: rgba(140, 100, 220, 0.15);
    color: #d8c6ff;
    border: 1px solid rgba(140, 100, 220, 0.35);
}

.newsletter-blurb-copy:hover {
    background: rgba(140, 100, 220, 0.28);
    color: #ffffff;
}

/* ===== T3 Mobile tab bar + sticky CTA — visible <=768px ===== */

.mobile-tab-bar {
    align-items: center;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    bottom: 0;
    display: none;
    justify-content: space-around;
    left: 0;
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    z-index: 100;
}

.mtb-item {
    align-items: center;
    color: var(--slate-500);
    display: flex;
    flex-direction: column;
    font-size: 0.7rem;
    gap: 2px;
    min-width: 64px;
    padding: 6px 10px;
    text-decoration: none;
}

.mtb-item.active {
    color: var(--semantic-info);
}

.mtb-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.mtb-label {
    font-weight: 600;
}

.mtb-item-primary {
    background: var(--semantic-info);
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(59, 130, 246, 0.35);
    color: var(--color-surface);
    padding: 10px 16px;
    transform: translateY(-8px);
}

.mtb-item-primary .mtb-icon {
    font-size: 1.35rem;
}

.mtb-item-primary .mtb-label {
    color: var(--color-surface);
}

.mobile-sticky-cta {
    background: transparent;
    bottom: calc(64px + max(6px, env(safe-area-inset-bottom)));
    display: none;
    left: 16px;
    opacity: 0;
    padding: 8px 0;
    position: fixed;
    right: 16px;
    transform: translateY(100%);
    transition: transform 0.25s ease, opacity 0.25s ease;
    z-index: 101;
}

.mobile-sticky-cta.visible {
    opacity: 1;
    transform: translateY(0);
}

.msc-btn {
    background: var(--semantic-info);
    border: none;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
    color: var(--color-surface);
    cursor: pointer;
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 14px 18px;
    width: 100%;
}

.msc-btn:active {
    background: var(--color-primary-hover);
}

.home-candidate-card.hcc-highlight {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
    transition: box-shadow 0.2s ease;
}

@media (max-width: 768px) {
    .mobile-tab-bar {
        display: flex;
    }

    .mobile-sticky-cta {
        display: block;
    }

    body {
        padding-bottom: 76px;
    }
}

@media (max-width: 1100px) {
    .right-rail {
        display: none;
    }
}
