/* ── PSX Analyzer – White / Coin Silver / Coin Gold ────────────────────────── */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f7;
    --bg-tertiary: #ebebeb;
    --bg-card: #ffffff;
    --bg-card-hover: #f9f8f5;
    --border: #c0c0c0;
    --border-light: #d4d4d4;

    --text-primary: #1a1a1a;
    --text-secondary: #3a3a3a;
    --text-muted: #6b6b6b;
    --text-dim: #999999;

    --gold: #CFB53B;
    --gold-light: #dcc862;
    --gold-dark: #b89f2e;
    --gold-bg: rgba(207, 181, 59, 0.08);
    --gold-border: rgba(207, 181, 59, 0.35);

    --silver: #c0c0c0;
    --silver-light: #d4d4d4;
    --silver-dark: #a0a0a0;

    --green: #2e7d32;
    --green-bg: rgba(46, 125, 50, 0.07);
    --red: #c62828;
    --red-bg: rgba(198, 40, 40, 0.07);

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --radius-sm: 0px;
    --radius: 0px;
    --radius-lg: 0px;
    --radius-xl: 0px;

    --shadow: 0 1px 3px 0 rgba(0,0,0,0.08), 0 1px 2px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 12px -2px rgba(0,0,0,0.10), 0 2px 4px -2px rgba(0,0,0,0.06);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */

.navbar {
    background: #ffffff;
    backdrop-filter: blur(12px);
    border-bottom: 2px solid var(--silver);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    gap: 0.5rem;
    overflow: hidden;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    flex-shrink: 0;
    white-space: nowrap;
}

.nav-logo {
    width: 32px;
    height: 32px;
}

.data-date-badge {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-dim);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    padding: 0.15rem 0.5rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.nav-link.active {
    color: var(--gold-dark);
    background: var(--gold-bg);
    border-bottom: 2px solid var(--gold);
}

/* ── Main Content ──────────────────────────────────────────────────────────── */

.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: calc(100vh - 64px - 200px);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ── Page Header ───────────────────────────────────────────────────────────── */

.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-title svg {
    color: var(--gold);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: all 0.2s;
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow);
}

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

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}

.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }
.card-value.neutral { color: var(--gold-dark); }

/* ── Stat Grid ─────────────────────────────────────────────────────────────── */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-value.teal, .stat-value.accent { color: var(--gold-dark); }

.stat-sub {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ── Charts ────────────────────────────────────────────────────────────────── */

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.chart-container .plotly {
    min-width: 520px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .chart-container {
        padding: 1rem;
    }

    .chart-container .plotly {
        min-width: 680px;
    }
}

/* ── Tables ────────────────────────────────────────────────────────────────── */

.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.table-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

thead th:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

thead th.sorted-asc::after { content: " \2191"; color: var(--gold); }
thead th.sorted-desc::after { content: " \2193"; color: var(--gold); }

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

tbody tr:last-child td {
    border-bottom: none;
}

.cell-symbol {
    font-weight: 600;
    color: var(--gold-dark);
    cursor: pointer;
    text-decoration: none;
}

.cell-symbol:hover {
    color: var(--gold);
    text-decoration: underline;
}

.cell-positive { color: var(--green); }
.cell-negative { color: var(--red); }
.cell-muted { color: var(--text-dim); }
.cell-mono { font-family: var(--font-mono); font-size: 0.8rem; }

/* ── Forms / Inputs ────────────────────────────────────────────────────────── */

.input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="text"],
input[type="number"],
input[type="search"],
select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-bg);
}

.search-input {
    min-width: 240px;
    padding-left: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.75rem center;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--gold);
    color: #1a1a1a;
    border-color: var(--gold);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--gold-dark);
    border-color: var(--gold-dark);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-teal, .badge-accent { background: var(--gold-bg); color: var(--gold-dark); border: 1px solid var(--gold-border); }
.badge-amber { background: var(--gold-bg); color: var(--gold-dark); }

/* ── Metric Cards (Stock Detail) ───────────────────────────────────────────── */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.metric-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* ── Top/Bottom Lists ──────────────────────────────────────────────────────── */

.list-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.list-card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.15s;
}

.list-item:hover {
    background: var(--bg-card-hover);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item-symbol {
    font-weight: 600;
    color: var(--gold-dark);
    text-decoration: none;
    font-size: 0.9rem;
}

.list-item-symbol:hover {
    color: var(--gold);
}

.list-item-value {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ── Compare Page ──────────────────────────────────────────────────────────── */

.compare-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.compare-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: var(--gold-bg);
    border: 1px solid var(--gold-border);
    border-radius: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gold-dark);
}

.chip-remove {
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s;
    background: none;
    border: none;
    color: var(--gold-dark);
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}

.chip-remove:hover { opacity: 1; }

.compare-table {
    overflow-x: auto;
}

/* ── Methodology Tables ───────────────────────────────────────────────────── */

.methodology-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.methodology-table thead th {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    position: static;
    cursor: default;
}

.methodology-table thead th:hover {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.methodology-table tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
    white-space: normal;
}

.methodology-table code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--bg-tertiary);
    padding: 0.1rem 0.35rem;
    border: 1px solid var(--border-light);
}

.methodology-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.methodology-list li {
    padding: 0.35rem 0 0.35rem 1.25rem;
    position: relative;
    line-height: 1.5;
}

.methodology-list li::before {
    content: "\2022";
    position: absolute;
    left: 0.25rem;
    color: var(--gold);
    font-weight: bold;
}

/* ── Downloads Page ────────────────────────────────────────────────────────── */

.download-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.download-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text-primary);
}

.download-card:hover {
    border-color: var(--gold-border);
    background: var(--bg-card-hover);
    box-shadow: var(--shadow);
}

.download-icon {
    width: 48px;
    height: 48px;
    background: var(--gold-bg);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gold-dark);
    flex-shrink: 0;
    border: 1px solid var(--gold-border);
}

.download-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.download-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Empty State ───────────────────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state svg {
    color: var(--text-dim);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 400px;
    margin: 0 auto;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */

.footer {
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer-content {
    text-align: center;
}

.footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.footer-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.footer-disclaimer {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-style: italic;
}

/* ── Utility ───────────────────────────────────────────────────────────────── */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-teal, .text-accent { color: var(--gold-dark); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.two-col-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

/* ── Stale Data Banner ─────────────────────────────────────────────────────── */

.stale-banner {
    background: var(--gold-bg);
    border-bottom: 1px solid var(--gold-border);
    padding: 0.4rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    color: var(--gold-dark);
    font-weight: 500;
    letter-spacing: 0.01em;
}

.stale-banner svg {
    flex-shrink: 0;
    opacity: 0.8;
}

/* ── Loading Spinner ───────────────────────────────────────────────────────── */

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 2rem auto;
}

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

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
    .data-date-badge {
        display: none;
    }
}

@media (max-width: 768px) {

    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: #ffffff;
        border-bottom: 2px solid var(--silver);
        flex-direction: column;
        padding: 0.5rem;
    }

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

    .nav-link {
        padding: 0.75rem 1rem;
        width: 100%;
    }

    .main-content {
        padding: 1rem;
    }

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

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

    .two-col-grid {
        grid-template-columns: 1fr;
    }

    .table-controls {
        width: 100%;
    }

    .search-input {
        min-width: 100%;
    }

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

    .compare-selector {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .page-title {
        font-size: 1.35rem;
    }
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ── Selection ─────────────────────────────────────────────────────────────── */

::selection {
    background: var(--gold);
    color: #1a1a1a;
}
