/* Scannable Financial Analyzer - Custom Styles */

:root {
    --sidebar-width: 240px;
    --header-height: 56px;
    --brand-blue: #2563eb;
    --brand-dark: #0f172a;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --muted: #64748b;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f1f5f9;
    color: #1e293b;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--brand-dark);
    color: white;
    z-index: 50;
    overflow-y: auto;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    padding: 16px 20px;
    font-size: 17px;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    letter-spacing: -0.3px;
}

.sidebar-logo span { color: #60a5fa; }

.nav-section {
    padding: 12px 12px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    margin: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    color: #94a3b8;
    transition: all 0.15s;
    text-decoration: none;
}

.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: var(--brand-blue); color: white; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Sidebar toggle */
.sidebar-toggle {
    position: fixed;
    top: 12px;
    left: calc(var(--sidebar-width) - 12px);
    z-index: 60;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--brand-dark);
    border: 2px solid #334155;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.2s, background 0.15s, color 0.15s;
    padding: 0;
}

.sidebar-toggle:hover {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform 0.2s;
}

body.sidebar-collapsed .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

body.sidebar-collapsed .sidebar-toggle {
    left: 12px;
}

body.sidebar-collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

body.sidebar-collapsed .main-content {
    margin-left: 0;
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.2s;
}

.page-header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.3px;
}

.page-body { padding: 24px 32px; }

/* Cards */
.card {
    background: white;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    padding: 20px;
    margin-bottom: 20px;
}

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

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: white;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    padding: 18px 20px;
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #0f172a;
}

.kpi-change {
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

.kpi-change.positive { color: var(--success); }
.kpi-change.negative { color: var(--danger); }
.kpi-change.neutral { color: var(--muted); }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}

.data-table tbody tr:hover { background: #f8fafc; }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .total-row td { font-weight: 700; border-top: 2px solid #e2e8f0; background: #f8fafc; }
.data-table .section-row td { font-weight: 700; color: #0f172a; background: #f1f5f9; }
.data-table .negative { color: var(--danger); }
.data-table .positive { color: var(--success); }

/* Charts */
.chart-container {
    position: relative;
    width: 100%;
    max-height: 360px;
}

.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.btn-primary { background: var(--brand-blue); color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: white; color: #334155; border-color: #d1d5db; }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 4px;
}

.form-input, .form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    color: #1e293b;
    background: white;
    transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder { color: #94a3b8; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 640px;
    width: 95%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title { font-size: 18px; font-weight: 700; }

.drilldown-link {
    color: #2563eb;
    text-decoration: none;
    cursor: pointer;
}
.drilldown-link:hover {
    text-decoration: underline;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* Tabs */
.tab-bar {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 20px;
}

.tab-item {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

.tab-item:hover { color: #334155; }
.tab-item.active { color: var(--brand-blue); border-bottom-color: var(--brand-blue); }

/* Scenario adjustments list */
.adj-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #fafbfc;
}

.adj-item:hover { background: #f1f5f9; }

.adj-type {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Expense category drill-down rows */
.expense-cat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.expense-cat-row:hover { background: #f8fafc; }
.expense-cat-row svg { width: 16px; height: 16px; max-width: 16px; max-height: 16px; flex-shrink: 0; }

.adj-detail { font-size: 13px; font-weight: 500; color: #334155; }
.adj-value { font-size: 13px; font-weight: 700; }

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #e2e8f0;
    border-top-color: var(--brand-blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: #64748b;
    gap: 12px;
}

/* Responsive */
@media (max-width: 1024px) {
    .chart-row { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .page-body { padding: 16px; }
}

/* Tooltip */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.tooltip:hover::after { opacity: 1; }

/* Drill-down */
.drill-row { cursor: pointer; }
.drill-row:hover { background: #eef2ff !important; }
.drill-children { background: #f8fafc; }
.drill-children td { padding-left: 32px !important; font-size: 12px; }

/* Toggle switch */
.toggle {
    position: relative;
    width: 40px;
    height: 22px;
    background: #cbd5e1;
    border-radius: 99px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle.active { background: var(--brand-blue); }

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle.active::after { transform: translateX(18px); }

/* Search bar */
.search-bar {
    display: flex;
    align-items: center;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0 12px;
    gap: 8px;
}

.search-bar input {
    border: none;
    outline: none;
    padding: 8px 0;
    font-size: 13px;
    flex: 1;
}

.search-bar svg { color: #94a3b8; width: 16px; height: 16px; }

/* Animations */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #94a3b8;
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; color: #475569; margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* ── Login page ───────────────────────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f8fafc;
    margin: 0;
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1), 0 4px 20px rgba(0,0,0,.06);
    padding: 48px 40px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.login-logo {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 4px;
}

.login-logo span {
    color: #2563eb;
}

.login-subtitle {
    color: #64748b;
    font-size: 14px;
    margin-bottom: 32px;
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    margin-bottom: 24px;
    text-align: left;
}

.login-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #3c4043;
    text-decoration: none;
    transition: background .15s, box-shadow .15s;
    cursor: pointer;
}

.login-btn:hover {
    background: #f8fafc;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

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

.sidebar-user {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sidebar-user-avatar-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-details {
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.5);
    text-transform: capitalize;
}

.sidebar-logout {
    color: rgba(255,255,255,0.5);
    padding: 6px;
    border-radius: 6px;
    transition: color .15s, background .15s;
    flex-shrink: 0;
}

.sidebar-logout:hover {
    color: #ef4444;
    background: rgba(255,255,255,0.1);
}

/* ── Admin page ───────────────────────────────────────────── */

.admin-add-form {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    align-items: center;
}

.admin-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color .15s;
}

.admin-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.admin-select, .admin-role-select {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    background: #fff;
    cursor: pointer;
}

.admin-role-select {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-icon {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    color: #94a3b8;
    transition: color .15s, background .15s;
}

.btn-danger-icon:hover {
    color: #ef4444;
    background: #fef2f2;
}

/* ── Spreadsheet view ─────────────────────────────────────── */
.page-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.filter-select {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    color: #1e293b;
    cursor: pointer;
    min-width: 140px;
}

.filter-select:hover { border-color: #94a3b8; }
.filter-select:focus { outline: 2px solid var(--brand-blue); outline-offset: -1px; }

.ss-scroll {
    overflow: auto;
    max-height: calc(100vh - 220px);
    border-top: 1px solid #e2e8f0;
}

.ss-table {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.ss-table thead th {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 600;
    text-align: right;
    padding: 8px 12px;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    z-index: 2;
}

.ss-table thead .ss-rowlabel {
    text-align: left;
    z-index: 4;
}

.ss-rowlabel {
    text-align: left;
    padding: 6px 12px 6px 12px;
    border-bottom: 1px solid #f1f5f9;
    background: white;
    white-space: nowrap;
    min-width: 280px;
    max-width: 380px;
}

.ss-num {
    text-align: right;
    padding: 6px 12px;
    border-bottom: 1px solid #f1f5f9;
    background: white;
    white-space: nowrap;
    min-width: 88px;
}

.ss-summary {
    background: #fafbfc;
    font-weight: 500;
    border-left: 1px solid #e2e8f0;
}

.ss-sticky-col {
    position: sticky;
    left: 0;
    z-index: 3;
    box-shadow: 1px 0 0 #e2e8f0;
}

tr.ss-row-group .ss-num,
tr.ss-row-group .ss-rowlabel {
    background: #f1f5f9;
    font-weight: 700;
    border-bottom: 1px solid #cbd5e1;
}

tr.ss-row-subgroup .ss-num,
tr.ss-row-subgroup .ss-rowlabel {
    background: #f8fafc;
    font-weight: 600;
}

tr.ss-row-calc .ss-num,
tr.ss-row-calc .ss-rowlabel {
    background: #fffbeb;
    font-weight: 700;
    border-top: 1px solid #fde68a;
    border-bottom: 1px solid #fde68a;
}

tr.ss-row-line:hover .ss-num,
tr.ss-row-line:hover .ss-rowlabel {
    background: #f8fafc;
}

tr.ss-row-informational .ss-num,
tr.ss-row-informational .ss-rowlabel-text {
    color: #94a3b8;
    font-style: italic;
}

.ss-toggle {
    display: inline-block;
    width: 14px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    margin-right: 4px;
}

.ss-toggle:hover { color: var(--brand-blue); }
.ss-toggle-spacer { display: inline-block; width: 14px; margin-right: 4px; }

.ss-rowlabel-text { user-select: text; }

.ss-locked {
    margin-left: 6px;
    font-size: 11px;
    opacity: 0.6;
    cursor: help;
}

.ss-drilldown {
    margin-left: 6px;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity .15s, color .15s;
}

.ss-drilldown:hover { color: var(--brand-blue); opacity: 1; }

.ss-num.negative { color: var(--danger); }
.ss-num.zero { color: #cbd5e1; }
.ss-num.percent { font-style: italic; }

/* Modal (used by spreadsheet drilldown and other pages) */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 100%;
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 { margin: 0; font-size: 16px; font-weight: 600; }

.modal-body { padding: 16px 20px; }

/* ───────────────── Plan page ───────────────── */

.plan-page { padding: 24px 32px; }

.plan-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.plan-toolbar .plan-toolbar-left {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.plan-scenario-select {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 6px 10px;
    background: white;
    font-size: 14px;
    font-weight: 600;
    min-width: 200px;
}

.plan-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.plan-kpi {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
}

.plan-kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
}

.plan-kpi-value {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
    margin-top: 2px;
}

.plan-kpi-sub {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.plan-kpi-sub.positive { color: var(--success); }
.plan-kpi-sub.negative { color: var(--danger); }

.plan-drivers-strip {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.plan-driver-chip {
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
    transition: border-color .15s;
}

.plan-driver-chip:hover { border-color: var(--brand-blue); }

.plan-driver-chip .label { color: var(--muted); }
.plan-driver-chip .value { font-weight: 600; color: #0f172a; }
.plan-driver-chip .baseline { color: var(--muted); font-style: italic; margin-left: 4px; }
.plan-driver-chip.changed { border-color: var(--brand-blue); background: #eff6ff; }
.plan-driver-chip.changed .value { color: var(--brand-blue); }

.plan-grid-wrap {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.plan-grid-scroll {
    overflow: auto;
    max-height: calc(100vh - 360px);
    min-height: 400px;
}

/* The plan grid reuses .ss-table styles, with extras for cell states */

.plan-grid .pg-cell {
    text-align: right;
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
    border-left: 1px solid #f1f5f9;
    background: white;
    white-space: nowrap;
    min-width: 90px;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    position: relative;
}

.plan-grid .pg-cell.actual,
.plan-grid .pg-cell.actual_partial { background: #f1f5f9; cursor: pointer; }
.plan-grid .pg-cell.actual_partial { background-image: repeating-linear-gradient(135deg, #f1f5f9, #f1f5f9 6px, #e2e8f0 6px, #e2e8f0 8px); }
.plan-grid .pg-cell.computed { background: #fafbfc; color: #475569; cursor: default; font-weight: 500; }
.plan-grid .pg-cell.forecast_default { background: white; }
.plan-grid .pg-cell.forecast_override { background: white; font-weight: 700; }
.plan-grid .pg-cell.historical_override_now_actual { background: #f1f5f9; }
.plan-grid .pg-cell.informational { color: var(--muted); font-style: italic; background: #fafbfc; cursor: default; }
.plan-grid .pg-cell.zero { color: #cbd5e1; }
.plan-grid .pg-cell.negative { color: var(--danger); }
.plan-grid .pg-cell.editing { outline: 2px solid var(--brand-blue); outline-offset: -2px; background: #fef9c3 !important; }
.plan-grid .pg-cell.flash { animation: flashCell 1.2s ease; }
.plan-grid .pg-cell.forecast_override::after,
.plan-grid .pg-cell.historical_override_now_actual::after {
    content: '';
    position: absolute;
    top: 2px; right: 2px;
    width: 6px; height: 6px;
    background: #facc15;
    border-radius: 50%;
}

@keyframes flashCell {
    0% { background: #fde68a; }
    100% { background: white; }
}

.plan-grid tr.row-month-divider .pg-cell {
    border-left: 2px solid #94a3b8;
}

.plan-grid tr.row-group .pg-cell,
.plan-grid tr.row-group .ss-rowlabel {
    background: #f1f5f9;
    font-weight: 700;
    border-bottom: 1px solid #cbd5e1;
}

.plan-grid tr.row-subgroup .pg-cell,
.plan-grid tr.row-subgroup .ss-rowlabel {
    background: #f8fafc;
    font-weight: 600;
}

.plan-grid tr.row-computed .pg-cell,
.plan-grid tr.row-computed .ss-rowlabel {
    background: #fffbeb;
    font-weight: 700;
    border-top: 1px solid #fde68a;
    border-bottom: 1px solid #fde68a;
}

.plan-grid tr.row-line:hover .pg-cell,
.plan-grid tr.row-line:hover .ss-rowlabel {
    background: #f8fafc;
}

.rule-icon {
    display: inline-block;
    width: 16px;
    text-align: center;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    margin-right: 4px;
    user-select: none;
}

.rule-icon:hover { color: var(--brand-blue); }

/* Cell trace popover */

.cell-popover {
    position: absolute;
    z-index: 100;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.18);
    padding: 14px 16px;
    min-width: 360px;
    max-width: 480px;
    font-size: 13px;
    line-height: 1.45;
}

.cell-popover h4 { margin: 0 0 4px 0; font-size: 13px; color: var(--muted); font-weight: 500; }
.cell-popover .pop-value { font-size: 22px; font-weight: 700; color: #0f172a; margin-bottom: 10px; }
.cell-popover .pop-section { margin-top: 10px; }
.cell-popover .pop-section-title { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; margin-bottom: 4px; }
.cell-popover .pop-link { color: var(--brand-blue); cursor: pointer; text-decoration: underline dotted; }
.cell-popover .pop-link:hover { text-decoration: underline; }
.cell-popover .pop-close {
    position: absolute;
    top: 6px;
    right: 8px;
    cursor: pointer;
    color: var(--muted);
    font-size: 18px;
    background: none;
    border: none;
    padding: 4px 6px;
    line-height: 1;
}

.cell-popover .pop-tag {
    display: inline-block;
    background: #f1f5f9;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    color: #334155;
    margin-right: 4px;
}

.cell-popover .pop-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    padding: 2px 0;
}

.cell-popover .pop-row .label { color: var(--muted); }
.cell-popover .pop-row .value { font-variant-numeric: tabular-nums; font-weight: 500; }
.cell-popover .pop-row .value.negative { color: var(--danger); }

.cell-popover .pop-context-menu {
    position: absolute;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.15);
    padding: 4px 0;
    z-index: 110;
    min-width: 200px;
}

.context-menu-item {
    display: block;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
}

.context-menu-item:hover { background: #f1f5f9; }

/* Cell editor modal/inline */

.cell-edit-modal {
    position: absolute;
    z-index: 120;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.2);
    padding: 14px 16px;
    min-width: 280px;
}

.cell-edit-modal .row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.cell-edit-modal label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.cell-edit-modal input[type=number],
.cell-edit-modal input[type=text],
.cell-edit-modal input[type=month],
.cell-edit-modal select,
.cell-edit-modal textarea {
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 14px;
    font-family: inherit;
    width: 100%;
}

.cell-edit-modal .modal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }

/* Charts panel */

.plan-charts-panel {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 14px;
    overflow: hidden;
}

.plan-charts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.plan-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 12px;
}

.plan-chart-cell {
    height: 220px;
    position: relative;
}

.plan-chart-cell h5 {
    margin: 0 0 8px 0;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Assumptions drawer */

.assumptions-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 480px;
    max-width: 92vw;
    background: white;
    box-shadow: -10px 0 30px rgba(15, 23, 42, 0.18);
    z-index: 150;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.assumptions-drawer header {
    padding: 14px 18px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.assumptions-drawer .drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 18px;
}

.assumptions-drawer h4 {
    margin: 18px 0 8px 0;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
}

.assumption-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #f1f5f9;
    padding: 6px 0;
    gap: 10px;
}

.assumption-item .label { font-size: 13px; flex: 1; }
.assumption-item .meta { font-size: 11px; color: var(--muted); }
.assumption-item .actions button { font-size: 11px; margin-left: 4px; }

/* Add-person form */

.headcount-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 6px;
}
.headcount-form label { font-size: 11px; color: var(--muted); }
.headcount-form input, .headcount-form select {
    border: 1px solid #cbd5e1; border-radius: 4px; padding: 4px 6px; font-size: 13px;
}
.headcount-form .full { grid-column: span 2; }
.headcount-form .actions { grid-column: span 2; display: flex; justify-content: flex-end; gap: 4px; }

/* Compare KPI table */
.compare-kpi-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compare-kpi-table th, .compare-kpi-table td {
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 12px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.compare-kpi-table th:first-child, .compare-kpi-table td:first-child { text-align: left; }
.compare-kpi-table thead th { background: #f1f5f9; font-weight: 700; }
.compare-kpi-table tr.variance td { background: #fef9c3; font-style: italic; }
.compare-kpi-table tr.baseline td { background: #f8fafc; }
.compare-kpi-table .scenario-color { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
