/* Early Signal | AI Portfolio Styles */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e2a45;
    --bg-sidebar: #0f1629;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent: #4ecdc4;
    --accent-dim: #3a9b90;
    --positive: #4ecdc4;
    --negative: #ff6b6b;
    --warning: #ffd93d;
    --info: #6bcfff;
    --border: #2a3a5e;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
}

/* Layout */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
}

.top-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.top-nav a {
    display: block;
    padding: 0.45rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    transition: all 0.15s;
}

.top-nav a:hover,
.top-nav a.active {
    color: var(--text-primary);
    background: rgba(78, 205, 196, 0.08);
    border-bottom-color: var(--accent);
}

.auth-modal-backdrop {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    width: 100vw;
    height: 100vh;
    min-height: 100dvh;
    z-index: 1000;
    background: rgba(6, 10, 20, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
}

.auth-modal-card {
    width: min(440px, 100%);
    max-height: calc(100dvh - 2rem);
    overflow: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Page Header */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1,
.page-header h2 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}

.page-header p {
    color: var(--text-secondary);
    margin: 0;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card h4 {
    margin: 0 0 1rem;
    font-size: 1rem;
    color: var(--accent);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1rem;
}

/* Grids */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.grid-sidebar {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1rem;
}

/* Badges */
.badge-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-green { background: #1a472a; color: #4ecdc4; }
.badge-red { background: #4a1a1a; color: #ff6b6b; }
.badge-yellow { background: #4a3a00; color: #ffd93d; }
.badge-blue { background: #1a2a4a; color: #6bcfff; }
.badge-gray { background: #2a2a3a; color: #a0a0a0; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-warning { background: #3a2a00; border: 1px solid #ffd93d40; color: #ffd93d; }
.alert-danger { background: #3a0a0a; border: 1px solid #ff6b6b40; color: #ff6b6b; }
.alert-info { background: #0a2a3a; border: 1px solid #6bcfff40; color: #6bcfff; }
.alert-success { background: #0a3a2a; border: 1px solid #4ecdc440; color: #4ecdc4; }

/* Recommendation Cards */
.rec-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.rec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
}

.rec-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    border-left: 3px solid transparent;
}

.rec-card.rec-buy { border-left-color: var(--positive); }
.rec-card.rec-sell { border-left-color: var(--negative); }

.rec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.rec-ticker {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    text-decoration: none;
}

.rec-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.rec-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.rec-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
    font-size: 0.8rem;
    margin: 0.5rem 0;
}

.rec-thesis {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0.5rem;
}

.rec-risk {
    font-size: 0.78rem;
    color: var(--warning);
    margin-top: 0.25rem;
}

/* Conviction Dots */
.conviction-dots {
    display: flex;
    gap: 3px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #444;
}

.dot.filled { background: var(--accent); }

/* Tables */
.table-compact {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.table-compact th {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
}

.table-compact td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.table-compact tbody tr:hover {
    background: rgba(78, 205, 196, 0.04);
}

.num { font-variant-numeric: tabular-nums; text-align: right; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.tab {
    padding: 0.6rem 1.25rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 1rem;
    font-size: 0.85rem;
}

.detail-grid dt {
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-grid dd {
    margin: 0;
    font-weight: 600;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-grid input[type="number"],
.form-grid input[type="text"],
.form-grid select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.form-grid input[type="checkbox"] {
    width: auto;
    margin-right: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 1rem;
}

.form-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
}

.btn-primary { background: var(--accent); color: #111; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-secondary { background: #2a3a5e; color: var(--text-primary); }
.btn-secondary:hover { background: #3a4a6e; }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: rgba(78, 205, 196, 0.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.trigger-buttons {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}

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

/* Layer Cards */
.layer-card details summary {
    cursor: pointer;
    padding: 0.5rem 0;
}

.layer-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.layer-id {
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 700;
    min-width: 60px;
}

.layer-name {
    font-weight: 600;
}

.layer-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0.5rem 0;
}

.layer-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Bottleneck Cards */
.bottleneck-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bottleneck-tickers {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.bottleneck-notes {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0.5rem;
}

/* Gauge Card */
.gauge-card {
    text-align: center;
    padding: 1rem;
}

.gauge-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.gauge-value.danger { color: var(--negative); }
.gauge-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.85rem;
}

.pagination a {
    color: var(--accent);
    text-decoration: none;
}

/* Markdown output */
.markdown-output {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 6px;
    font-size: 0.83rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
}

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filter-bar select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Empty state */
.empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
    font-size: 0.9rem;
}

/* Scrollable table wrapper */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Nav toggle — hidden on desktop */
.nav-toggle { display: none; }

/* ── Tablet (≤ 900px) ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .topbar-inner {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.6rem 1rem;
        gap: 0.4rem;
    }
    .top-nav {
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 0.25rem;
        scrollbar-width: none;
    }
    .top-nav::-webkit-scrollbar { display: none; }
    .top-nav a { flex: 0 0 auto; }
    .content { padding: 1rem; }
    .grid-2col { grid-template-columns: 1fr; }
    .grid-sidebar { grid-template-columns: 1fr; }
    .trigger-buttons { flex-wrap: wrap; }
}

/* ── Mobile (≤ 640px) ──────────────────────────────────────────── */
@media (max-width: 640px) {
    /* Topbar: brand + hamburger on one line, nav as dropdown */
    .topbar-inner {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0 0.85rem;
        min-height: 48px;
        gap: 0;
    }

    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        background: none;
        border: 1px solid var(--border);
        border-radius: 6px;
        color: var(--text-primary);
        font-size: 1.1rem;
        cursor: pointer;
        flex-shrink: 0;
        line-height: 1;
    }

    .top-nav {
        display: none;
        position: fixed;
        top: 48px;
        left: 0;
        right: 0;
        z-index: 200;
        background: var(--bg-sidebar);
        border-bottom: 2px solid var(--border);
        flex-direction: column;
        gap: 0;
        padding: 0;
        overflow-x: visible;
        white-space: normal;
    }

    .top-nav.open {
        display: flex;
    }

    .top-nav a {
        padding: 0.8rem 1.25rem;
        font-size: 0.9rem;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        border-bottom-color: var(--border);
    }

    .top-nav a:last-child { border-bottom: none; }

    .top-nav a.active {
        border-bottom-color: var(--border);
        border-left: 3px solid var(--accent);
        padding-left: calc(1.25rem - 3px);
    }

    /* Content */
    .content {
        padding: 0.75rem;
    }

    /* Cards */
    .card {
        padding: 0.9rem;
        border-radius: 6px;
    }

    .card h4 {
        font-size: 0.9rem;
        margin-bottom: 0.75rem;
    }

    /* Page header */
    .page-header {
        margin-bottom: 0.85rem;
    }

    .page-header h1,
    .page-header h2 {
        font-size: 1.2rem;
    }

    .page-header p {
        font-size: 0.82rem;
    }

    /* Grids */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

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

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

    .layer-meta-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Buttons */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.82rem;
    }

    .trigger-buttons {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Tabs — scroll horizontally */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { flex: 0 0 auto; font-size: 0.8rem; padding: 0.5rem 0.85rem; }

    /* Badges row */
    .badge-row { gap: 0.35rem; }
    .badge { font-size: 0.7rem; padding: 0.18rem 0.5rem; }

    /* Detail grid */
    .detail-grid { font-size: 0.8rem; gap: 0.2rem 0.75rem; }

    /* Filter bars */
    .filter-bar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Gauge cards */
    .gauge-value { font-size: 1.5rem; }
}

/* Links */
a { color: var(--accent); }
a:hover { color: var(--accent-dim); }

/* ── Typography hierarchy ──────────────────────────────────────── */
/* Card titles: neutral white, not cyan (cyan = interactive only) */
.card h4 {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* Section head row: title + optional action */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.section-head h4 { margin: 0; }
.section-head-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ── Tooltip system ────────────────────────────────────────────── */
/* Usage: <span data-tooltip="Definition here">Term</span> */
[data-tooltip] {
    position: relative;
    cursor: help;
    border-bottom: 1px dashed rgba(160,160,160,0.35);
    text-decoration: none;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 9px);
    left: 50%;
    transform: translateX(-50%);
    background: #0b1220;
    color: #e0e0e0;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.45;
    white-space: normal;
    min-width: 170px;
    max-width: 270px;
    text-align: left;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 9000;
    border: 1px solid var(--border);
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--border);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 9001;
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before { opacity: 1; }
/* Tooltip below when near top of viewport */
[data-tooltip].tip-below::after {
    bottom: auto;
    top: calc(100% + 9px);
}
[data-tooltip].tip-below::before {
    bottom: auto;
    top: calc(100% + 3px);
    border-top-color: transparent;
    border-bottom-color: var(--border);
}

/* ── Status / Stat Pills ───────────────────────────────────────── */
.status-bar {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.stat-pill {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 1rem;
    min-width: 90px;
    flex: 1;
    max-width: 200px;
}
.stat-pill-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 0.15rem;
}
.stat-pill-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}
.stat-pill-sub {
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

/* ── Legend bar ────────────────────────────────────────────────── */
.legend-bar {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.45rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}
.legend-swatch {
    width: 20px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
    display: inline-block;
}
.legend-title {
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 0.25rem;
}

/* ── Empty states ──────────────────────────────────────────────── */
.empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 2.5rem 1rem;
    font-size: 0.88rem;
    line-height: 1.6;
}
.empty-icon {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 0.6rem;
    opacity: 0.35;
}
.empty-state strong { color: var(--text-primary); display: block; margin-bottom: 0.3rem; }

/* ── All-clear alert ───────────────────────────────────────────── */
.alert-clear {
    background: rgba(78,205,196,0.07);
    border: 1px solid rgba(78,205,196,0.2);
    color: var(--positive);
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Trigger card ──────────────────────────────────────────────── */
.run-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}
.run-option {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
}
.run-option:hover:not(:disabled) {
    border-color: var(--accent);
    background: rgba(78,205,196,0.05);
}
.run-option:disabled { opacity: 0.45; cursor: not-allowed; }
.run-option-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}
.run-option-desc {
    font-size: 0.74rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.run-feedback {
    margin-top: 0.75rem;
    font-size: 0.84rem;
    min-height: 1.2em;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
@media (max-width: 640px) {
    .run-options { grid-template-columns: 1fr; }
    .stat-pill { max-width: none; }
}

/* ── Card hover (subtle) ───────────────────────────────────────── */
.card { transition: border-color 0.15s; }

/* ── Help icon inline ──────────────────────────────────────────── */
.help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: rgba(160,160,160,0.15);
    color: var(--text-secondary);
    font-size: 0.6rem;
    font-weight: 700;
    cursor: help;
    vertical-align: middle;
    margin-left: 0.2rem;
    border-bottom: none;  /* override tooltip border */
}

/* Card header for details/summary */
.card-header {
    cursor: pointer;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-weight: 600;
}
