/* ═══════════════════════════════════════════════════════════════════════
   TradingAgents — MD3-inspired Design System
   Based on ui-reference/style.css patterns
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --surface-variant: #f1f3f4;
    --border: #dadce0;
    --text: #202124;
    --text-secondary: #5f6368;
    --text-muted: #80868b;
    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --accent-light: #e8f0fe;
    --cash: #0d904f;
    --cash-light: #e6f4ea;
    --holdings: #7c3aed;
    --holdings-light: #f3e8ff;
    --danger: #d93025;
    --danger-light: #fce8e6;
    --warning: #e37400;
    --warning-light: #fef7e0;
    --success: #1e8e3e;
    --success-light: #e6f4ea;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --transition: 0.2s cubic-bezier(.4,0,.2,1);
}

html.dark {
    --bg: #1e1e1e;
    --surface: #2d2d2d;
    --surface-variant: #353535;
    --border: #444444;
    --text: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #80868b;
    --accent: #8ab4f8;
    --accent-hover: #aecbfa;
    --accent-light: #1a2a40;
    --cash: #34a853;
    --cash-light: #1a3c28;
    --holdings: #a78bfa;
    --holdings-light: #2a1a40;
    --danger: #f28b82;
    --danger-light: #3a1a1a;
    --warning: #fdd663;
    --warning-light: #3a2a10;
    --success: #34a853;
    --success-light: #1a3c28;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.25);
}

body {
    font-family: 'Google Sans', 'Roboto', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* ── View Transitions ─────────────────────────────────────────────── */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* ── Custom Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c4c7cc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0a4aa; }

html.dark ::-webkit-scrollbar-thumb { background: #555; }
html.dark ::-webkit-scrollbar-thumb:hover { background: #777; }

* {
    scrollbar-width: thin;
    scrollbar-color: #c4c7cc transparent;
}
html.dark * { scrollbar-color: #555 transparent; }

/* ── Top Bar ──────────────────────────────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
    color: var(--accent);
}

.app-title {
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.3px;
    color: var(--text);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-bar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    flex-shrink: 0;
}

.status-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    background: var(--surface-variant);
    color: var(--text-secondary);
}

.status-chip.running { background: var(--accent-light); color: var(--accent); }
.status-chip.completed { background: var(--success-light); color: var(--success); }
.status-chip.failed { background: var(--danger-light); color: var(--danger); }

.btn-icon-only {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.btn-icon-only:hover { background: var(--surface-variant); color: var(--text); }

/* ── Navigation ───────────────────────────────────────────────────── */
.nav-sidebar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 64px;
    z-index: 99;
}
.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 24px;
    display: flex;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 24px;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.nav-item:hover { background: var(--surface-variant); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .material-symbols-outlined { font-size: 20px; }

html.dark .nav-item.active { color: #1e1e1e; }

/* ── View Scroll Wrapper ──────────────────────────────────────────── */
.view-scroll {
    height: calc(100vh - 116px);
    overflow-y: auto;
}

/* ── Main Content ─────────────────────────────────────────────────── */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.hidden { display: none !important; }

/* ── Summary Cards ────────────────────────────────────────────────── */
.summary-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.breakdown-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.card-value {
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.5px;
}

.card-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.cash-color { color: var(--cash); }
.holdings-color { color: var(--holdings); }
.invested-color { color: var(--warning); }

.change-up { color: var(--success); }
.change-down { color: var(--danger); }

.source-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    border-radius: 8px;
    background: var(--surface-variant);
    color: var(--text-muted);
    margin-left: 6px;
    vertical-align: middle;
}

/* ── Chart Card ───────────────────────────────────────────────────── */
.chart-card { min-height: 280px; display: flex; flex-direction: column; }
.chart-card-wide { /* wider */ }
.chart-wrap { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; }
.chart-wrap canvas { max-height: 260px; max-width: 65%; }
.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 8px;
    max-height: 260px;
    overflow-y: auto;
}
.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}
.chart-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.chart-legend-label {
    white-space: nowrap;
    font-family: 'Google Sans', 'Roboto', sans-serif;
}
.chart-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ── Recent Transactions Mini List ────────────────────────────────── */
.tx-mini-list {
    max-height: 240px;
    overflow-y: auto;
    margin-top: 8px;
}
.tx-mini-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.tx-mini-item:last-child { border-bottom: none; }
.tx-mini-ticker { font-weight: 500; min-width: 50px; }
.tx-mini-type { font-size: 12px; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.tx-mini-type.buy { background: var(--success-light); color: var(--success); }
.tx-mini-type.sell { background: var(--danger-light); color: var(--danger); }
.tx-mini-details { color: var(--text-secondary); flex: 1; }
.tx-mini-total { font-weight: 500; color: var(--text); min-width: 70px; text-align: right; }
.tx-mini-date { color: var(--text-muted); font-size: 12px; margin-left: auto; }

/* ── Tables ───────────────────────────────────────────────────────── */
.orders-section { margin-top: 8px; }

.orders-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
}

.orders-header h2 {
    font-size: 18px;
    font-weight: 500;
}

.order-count {
    font-size: 13px;
    color: var(--text-secondary);
}

.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.orders-table {
    width: 100%;
    border-collapse: collapse;
}

.orders-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-variant);
}

.orders-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.orders-table th.sortable:hover { color: var(--accent); }

.orders-table td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.orders-table tr:last-child td { border-bottom: none; }

.orders-table tbody tr {
    transition: background var(--transition);
}

.orders-table tbody tr.clickable { cursor: pointer; }
.orders-table tbody tr.clickable:hover { background: var(--accent-light); }

html.dark .orders-table tbody tr.clickable:hover { background: var(--surface-variant); }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 16px !important;
    cursor: default !important;
}

td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Fixed column widths for clean table layout */
.orders-table th.col-w-action { width: 48px; text-align: center; }
.orders-table td.col-w-action { text-align: center; padding: 8px 4px; }
.orders-table th.col-w-ticker { width: 14%; }
.orders-table th.col-w-qty { width: 12%; }
.orders-table th.col-w-price { width: 12%; }
.orders-table th.col-w-value { width: 14%; }
.orders-table th.col-w-day { width: 10%; }
.orders-table th.col-w-weight { width: 10%; }
.orders-table th.col-w-type { width: 8%; }
.orders-table th.col-w-date { width: 13%; }
.orders-table th.col-w-fees { width: 9%; }

/* ── Chip Group ───────────────────────────────────────────────────── */
.chip-group {
    display: flex;
    gap: 6px;
}

.chip-group .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1;
}

.chip-group .chip:hover { background: var(--surface-variant); }

.chip-group .chip.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

html.dark .chip-group .chip.active { color: #1e1e1e; }

.chip-group .chip .material-symbols-outlined { font-size: 18px; }

/* ── Styled Select ────────────────────────────────────────────────── */
.select-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.select-icon {
    position: absolute;
    left: 12px;
    font-size: 20px;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 1;
}

.select-wrap select {
    width: 100%;
    padding: 10px 36px 10px 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2380868b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color var(--transition);
}

.select-wrap select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}

html.dark .select-wrap select:focus {
    box-shadow: 0 0 0 3px rgba(138,180,248,.25);
}

/* ── Pagination ───────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 0;
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
}

.pagination button:hover:not(:disabled) { background: var(--surface-variant); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
html.dark .pagination button.active { color: #1e1e1e; }
.pagination .page-info { font-size: 13px; color: var(--text-secondary); }

/* ── Buttons ──────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 24px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
html.dark .btn-primary { color: #1e1e1e; }

.btn-primary.btn-sm {
    padding: 8px 18px;
    font-size: 13px;
}

.btn-primary.btn-danger {
    background: var(--danger);
}
.btn-primary.btn-danger:hover { background: #c5221f; }

.btn-refresh {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    color: var(--accent);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-refresh:hover {
    background: var(--accent-light);
    border-color: var(--accent);
}

.btn-refresh:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-refresh .material-symbols-outlined { font-size: 20px; }
.btn-refresh.refreshing .material-symbols-outlined { animation: spin 1s linear infinite; }

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--transition);
}

.btn-icon:hover { background: var(--surface-variant); }

.btn-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border: none;
    border-radius: 20px;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-text:hover { background: var(--accent-light); }

/* ── Filters Bar ──────────────────────────────────────────────────── */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-search {
    position: relative;
    flex: 1;
    min-width: 160px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: var(--text-muted);
}

.filter-search input,
.filter-search select {
    width: 100%;
    padding: 9px 16px 9px 40px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    transition: all var(--transition);
}

.filter-search select {
    padding: 9px 36px 9px 40px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2380868b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.filter-search input::placeholder { color: var(--text-muted); }
.filter-search input:focus,
.filter-search select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}
html.dark .filter-search input:focus,
html.dark .filter-search select:focus {
    box-shadow: 0 0 0 3px rgba(138,180,248,.25);
}

/* ── History Controls ─────────────────────────────────────────────── */
.history-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.history-controls .filter-search { min-width: 120px; max-width: 180px; }
.history-controls .filter-search select { padding: 9px 36px 9px 16px; }

/* Analysis history table — compact dates */
.orders-table td.date-cell {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ── Analysis Layout (MD3 two-column) ─────────────────────────────── */
.analysis-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    align-items: start;
}

.analysis-section-title {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.25px;
    color: var(--text);
    margin-bottom: 20px;
}

/* Left: History card */
.analysis-history-card {
    min-width: 0;
}

.analysis-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.analysis-history-header .analysis-section-title {
    margin-bottom: 0;
}

/* Right: Sidebar */
.analysis-sidebar {
    position: sticky;
    top: 140px; /* below top bar + nav */
}

.analysis-form-card {
    display: flex;
    flex-direction: column;
}

.analysis-form-card .analysis-section-title {
    margin-bottom: 16px;
}

.analysis-form-card .form-field {
    margin-bottom: 16px;
}

.analysis-form-card .form-field:last-of-type {
    margin-bottom: 20px;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

/* Responsive: stack on narrow screens */
@media (max-width: 900px) {
    .analysis-layout {
        grid-template-columns: 1fr;
    }
    .analysis-sidebar {
        position: static;
    }
    .analysis-history-header {
        flex-direction: column;
        align-items: stretch;
    }
    .history-controls .filter-search {
        min-width: unset;
        max-width: none;
        flex: 1;
    }
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-field input,
.form-field select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    transition: all var(--transition);
}

.form-field input:focus,
.form-field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}

.form-field input[type="date"] {
    color-scheme: light;
}
html.dark .form-field input[type="date"] { color-scheme: dark; }

.form-field select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2380868b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* Form grid layouts (Portfolio Manager) */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }
.form-grid-6 { grid-template-columns: repeat(6, 1fr); }

/* ── Portfolio Stack ──────────────────────────────────────────────── */
.portfolio-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ── SimpleFIN Brokerage Connection Card ──────────────────────────── */
.sf-card-header {
    margin-bottom: 16px;
}

.sf-header-title {
    margin-bottom: 0 !important;
    display: flex;
    align-items: center;
}

.sf-header-icon {
    margin-right: 8px;
    font-size: 22px;
    color: var(--accent);
}

.sf-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
    max-width: 640px;
}

.sf-description a {
    color: var(--accent);
    text-decoration: none;
}

.sf-description a:hover {
    text-decoration: underline;
}

.sf-token-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.sf-textarea {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    outline: none;
    background: var(--surface);
    color: var(--text);
    resize: vertical;
    transition: border-color var(--transition);
}

.sf-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}

.sf-textarea::placeholder {
    color: var(--text-muted);
}

.sf-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

/* Account selection list */
.sf-account-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.sf-account-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    transition: all var(--transition);
}

.sf-account-option:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.sf-account-option .material-symbols-outlined {
    font-size: 28px;
    color: var(--accent);
    flex-shrink: 0;
}

.sf-account-option-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.sf-account-option-org {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Connected state */
.sf-connected-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}

.sf-connected-details {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sf-org-icon {
    font-size: 32px;
    color: var(--accent);
    flex-shrink: 0;
}

.sf-account-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

.sf-account-org {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sf-sync-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sf-last-sync {
    font-size: 12px;
    color: var(--text-muted);
}

/* Progress indicator */
.sf-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.sf-progress .spinner {
    margin: 0;
    width: 24px;
    height: 24px;
    border-width: 2px;
}

/* Error display */
.sf-error {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--danger-light);
    color: var(--danger);
    font-size: 13px;
    line-height: 1.5;
    margin-top: 12px;
}

@media (max-width: 600px) {
    .sf-connected-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .sf-sync-actions {
        flex-wrap: wrap;
    }
    .sf-token-row {
        flex-direction: column;
    }
}

.pm-inline-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.pm-form-fields {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.pm-form-fields input,
.pm-form-fields select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition);
    width: 130px;
}

.pm-form-fields input:focus,
.pm-form-fields select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}

.pm-form-fields input[type="date"] {
    width: 150px;
    color-scheme: light;
}
html.dark .pm-form-fields input[type="date"] { color-scheme: dark; }

.pm-form-fields select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2380868b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
    width: 100px;
}

@media (max-width: 900px) {
    .pm-form-fields input,
    .pm-form-fields select { width: 100%; }
    .pm-inline-form { flex-direction: column; align-items: stretch; }
    .pm-inline-form .btn-primary { width: 100%; justify-content: center; }
}
.analysis-progress {
    margin-top: 24px;
    text-align: center;
    padding: 24px;
}

.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

.analysis-progress p {
    color: var(--text-secondary);
    font-size: 14px;
}

.progress-sub {
    font-size: 12px !important;
    color: var(--text-muted) !important;
    margin-top: 4px;
}

/* ── Analysis Results ─────────────────────────────────────────────── */
.analysis-results { margin-top: 24px; }

.results-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.results-ticker {
    font-size: 20px;
    font-weight: 500;
}

.rating-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
}

.rating-pill.rating-buy,
.rating-pill.rating-strong_buy { background: var(--success-light); color: var(--success); }
.rating-pill.rating-overweight { background: rgba(66,133,244,.12); color: #1557B0; }
.rating-pill.rating-hold { background: var(--warning-light); color: var(--warning); }
.rating-pill.rating-underweight { background: rgba(227,116,0,.12); color: #B45309; }
.rating-pill.rating-sell,
.rating-pill.rating-strong_sell { background: var(--danger-light); color: var(--danger); }
.rating-pill.rating-unknown { background: var(--surface-variant); color: var(--text-secondary); }

.results-grid {
    display: grid;
    gap: 12px;
}

.result-card {
    background: var(--surface-variant);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.result-card-pm {
    background:
        linear-gradient(var(--surface-variant), var(--surface-variant)) padding-box,
        linear-gradient(135deg, #4285F4, #9B51E0, #E2336E) border-box;
    border: 2px solid transparent;
    border-radius: 14px;
    box-shadow:
        0 0 24px 0 rgba(66,133,244,.06),
        0 0 36px 0 rgba(155,81,224,.04);
}

html.dark .result-card-pm {
    box-shadow:
        0 0 16px 0 rgba(138,180,248,.05),
        0 0 24px 0 rgba(179,136,255,.03);
}

.result-card-streaming {
    animation: cardSlideIn 0.35s ease;
}

@keyframes cardSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.result-agent {
    font-size: 14px;
    font-weight: 500;
    text-transform: capitalize;
}

.result-type {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-body {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    max-height: 240px;
    overflow-y: auto;
    line-height: 1.6;
}

/* ── Drawer ───────────────────────────────────────────────────────── */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.drawer-overlay.open { opacity: 1; pointer-events: auto; }

body.drawer-open { overflow: hidden; }

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 560px;
    max-width: 100vw;
    height: 100vh;
    background: var(--surface);
    z-index: 301;
    box-shadow: -8px 0 24px rgba(0,0,0,.12);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    display: flex;
    flex-direction: column;
}

.drawer.open { transform: translateX(0); }

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.drawer-header h2 { font-size: 20px; font-weight: 500; }

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.drawer-body .detail-section {
    margin-bottom: 20px;
}

.drawer-body .detail-section h3 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.drawer-body .detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.drawer-body .detail-row:last-child { border-bottom: none; }

.drawer-body .detail-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.drawer-body .detail-value {
    font-size: 14px;
    font-weight: 500;
}

.drawer-body .detail-content {
    background: var(--surface-variant);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-secondary);
}

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 24px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    z-index: 400;
    box-shadow: 0 8px 24px rgba(0,0,0,.2);
    animation: toastIn 0.3s ease;
}

.toast.success { background: #1e8e3e; }
.toast.error { background: var(--danger); }
.toast.info { background: var(--text); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Delete button in tables ──────────────────────────────────────── */
.btn-delete-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
}
.btn-delete-row:hover { background: var(--danger-light); color: var(--danger); }
.btn-delete-row .material-symbols-outlined { font-size: 18px; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .summary-row { grid-template-columns: repeat(2, 1fr); }
    .breakdown-row { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid-4, .form-grid-6 { grid-template-columns: repeat(2, 1fr); }
    .drawer { width: 100vw; }
    .history-controls { flex-direction: column; align-items: stretch; }
    .history-controls .filter-search { max-width: none; }
}

@media (max-width: 560px) {
    .summary-row { grid-template-columns: 1fr; }
    .form-grid, .form-grid-4, .form-grid-6 { grid-template-columns: 1fr; }
    .top-bar { padding: 0 16px; }
    .top-bar-right { gap: 8px; }
    .app-title { font-size: 18px; }
    .nav-inner { padding: 8px 12px; gap: 2px; }
    .nav-item { padding: 8px 12px; font-size: 13px; }
    .nav-item span:last-child { display: none; }
}

/* ── Setup Wizard ────────────────────────────────────────────────────
   MD3 single-card layout. All providers visible (no scroll). When a
   provider is selected the card expands with a decelerated animation
   to reveal model & API-key fields.                                  */
.setup-wizard {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 40px 24px;
}

.setup-card {
    background: var(--surface);
    border-radius: 28px;
    padding: 32px;
    max-width: 640px;
    width: 100%;
    box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 32px rgba(0,0,0,.16);
    transition: box-shadow 0.35s cubic-bezier(0.2, 0, 0, 1);
}

/* ── Header ─────────────────────────────────────────────────────── */
.setup-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.setup-logo {
    font-size: 36px;
    color: var(--accent);
    flex-shrink: 0;
}

.setup-title {
    font-size: 20px;
    font-weight: 500;
    line-height: 26px;
    color: var(--text);
    margin: 0;
}

.setup-subtitle {
    font-size: 13px;
    line-height: 18px;
    color: var(--text-secondary);
    margin: 1px 0 0 0;
}

/* ── Section label ───────────────────────────────────────────────── */
.setup-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* ── Provider grid ──────────────────────────────────────────────── */
.provider-scroll {
    margin-bottom: 0;
}

.provider-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.provider-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    transition: background .12s, border-color .12s;
    text-align: left;
    font-family: inherit;
}

.provider-card:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.provider-card.selected {
    border-color: var(--accent);
    background: var(--accent-light);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.provider-name {
    font-weight: 500;
    font-size: 12px;
    line-height: 16px;
    color: var(--text);
}

.provider-env {
    font-size: 10px;
    line-height: 14px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ── Config section — animated reveal ─────────────────────────────
   JS sets inline max-height for smooth expansion; CSS handles the
   transition curve.  Collapsed by default via overflow + zero height. */
#setupConfig {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.2, 0, 0, 1);
}

#setupConfig.visible {
    /* max-height set via JS to scrollHeight */
}

.setup-fields {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
    padding-top: 20px;  /* spacing from provider grid */
}

#setupConfig .form-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

#setupConfig .form-field label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .3px;
}

#setupConfig select,
#setupConfig input[type="password"],
#setupConfig input[type="text"] {
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

#setupConfig select:focus,
#setupConfig input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.form-hint {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 1px;
}

.custom-model-input {
    margin-top: 4px;
}

/* ── User Chip ─────────────────────────────────────────────────────── */
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 20px;
    background: var(--surface-variant);
}

.user-chip .material-symbols-outlined {
    font-size: 18px;
}

/* ── Setup Wizard responsive ──────────────────────────────────── */
@media (max-width: 600px) {
    .setup-card { padding: 24px 20px; }
    .setup-fields { grid-template-columns: 1fr; }
    .provider-grid { grid-template-columns: repeat(2, 1fr); }
    #setupConfig.visible { max-height: 500px; }
}

/* ── Setup Wizard responsive ──────────────────────────────────── */
@media (max-width: 700px) {
    .setup-body {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .provider-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .provider-scroll {
        max-height: 240px;
    }
    .setup-card {
        padding: 24px 20px;
    }
}
