/* Analysis page — sidebar, plot card, results table. */

html, body { overflow: auto; }

.analysis-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: var(--space-4);
    align-items: start;
    min-height: calc(100vh - 52px - 2 * var(--space-4));
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.filter-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    position: sticky;
    top: calc(52px + var(--space-4));
    max-height: calc(100vh - 52px - 2 * var(--space-4));
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.sidebar-header-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.plot-type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: var(--space-3);
    border-bottom: 1px solid var(--border);
}
.plot-type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 56px;
    padding: 8px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-size: 10.5px;
    font-weight: 500;
    line-height: 1.3;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.plot-type-btn svg { width: 16px; height: 16px; }
.plot-type-btn:hover { border-color: var(--border-strong); color: var(--text); }
.plot-type-btn.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
}

#filter-steps { display: flex; flex-direction: column; }
.f-section {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.f-section:last-child { border-bottom: none; }
.f-section-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 7px;
}

.pill-row { display: flex; flex-wrap: wrap; gap: 5px; }
.f-pill {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.f-pill:hover { border-color: var(--border-strong); color: var(--text); }
.f-pill.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
}

.f-input-row { display: flex; gap: 6px; align-items: center; }
.f-input-row span { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.f-input { flex: 1; min-width: 0; width: 100%; font-size: 12px; padding: 6px 9px; }
.f-select { width: 100%; font-size: 12px; padding: 6px 9px; }
.year-row { display: flex; gap: 6px; align-items: center; }
.year-row span { color: var(--text-3); font-size: 11px; }

.metric-toggle { display: flex; gap: 5px; }
.metric-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-size: 11px;
    font-weight: 550;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.metric-btn:hover { border-color: var(--border-strong); color: var(--text); }
.metric-btn.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
}

.sidebar-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: var(--space-3) var(--space-4) var(--space-4);
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.btn-run {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #ffffff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease;
}
.btn-run:hover { background: var(--accent-strong); }
.btn-reset {
    padding: 7px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-3);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.12s ease, color 0.12s ease;
}
.btn-reset:hover { border-color: var(--danger); color: var(--danger); }

/* ── Main column ────────────────────────────────────────────────────────── */

.analysis-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
}

.plot-card {
    display: flex;
    flex-direction: column;
    min-height: 540px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}
.plot-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.plot-card-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.plot-card-title svg { color: var(--text-3); }
.title-badge {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.plot-card-actions { display: flex; gap: 6px; }
.btn-icon {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.12s ease, color 0.12s ease;
}
.btn-icon:hover { border-color: var(--border-strong); color: var(--text); }

.plot-body {
    position: relative;
    display: flex;
    align-items: stretch;
    flex: 1;
    min-height: 480px;
}
#plotDiv { width: 100% !important; height: 100% !important; min-height: 480px; }

.plot-empty, .plot-loading, .plot-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: var(--space-3);
}
.plot-empty svg { color: var(--text-3); opacity: 0.5; }
.plot-empty-text { font-size: 13px; color: var(--text-3); text-align: center; line-height: 1.6; }
.plot-empty-text strong { color: var(--text-2); font-weight: 600; }
.plot-loading { color: var(--text-2); font-size: 13px; }
.plot-error { color: var(--danger); font-size: 13px; text-align: center; padding: var(--space-5); }

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Results table ──────────────────────────────────────────────────────── */

.results-table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}
.results-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.results-table-title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.results-table-scroll { overflow: auto; max-height: 300px; }

.trend-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 550;
}
.trend-badge.up   { background: var(--danger-soft); color: var(--danger); }
.trend-badge.down { background: rgba(5, 150, 105, 0.12); color: var(--success); }
.trend-badge.flat { background: var(--surface-2); color: var(--text-2); }
.trend-badge.na   { background: var(--surface-2); color: var(--text-3); }

/* ── Presets strip ──────────────────────────────────────────────────────── */

.presets-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 2px 2px 12px;
}
.preset-chip {
    padding: 4px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.preset-chip:hover {
    border-color: var(--border-strong);
    color: var(--text);
    background: var(--surface-2);
}
.preset-chip.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
}
