/* SnowLedger Design System - Adapted from Xplor Data Portal */

:root {
    /* Brand - SnowLedger blue/teal theme */
    --primary: #0EA5E9;
    --primary-hover: #0284C7;
    --primary-light: rgba(14, 165, 233, 0.08);
    --primary-ring: rgba(14, 165, 233, 0.25);
    --gradient-brand: linear-gradient(135deg, #0EA5E9, #06B6D4);

    /* Surfaces */
    --bg: #F3F4F6;
    --surface: #FFFFFF;
    --surface-hover: #F9FAFB;
    --border: #E5E7EB;
    --border-strong: #D1D5DB;

    /* Text */
    --text: #111827;
    --text-secondary: #4B5563;
    --text-dim: #6B7280;
    --text-muted: #9CA3AF;

    /* Semantic */
    --success: #059669;
    --error: #DC2626;
    --warning: #D97706;
    --accent: #7C3AED;
    --info: #2563EB;

    /* Sidebar */
    --sidebar-bg: #0F172A;
    --sidebar-hover: #1E293B;
    --sidebar-text: #CBD5E1;
    --sidebar-text-active: #FFFFFF;
    --sidebar-accent: #0EA5E9;
    --sidebar-width: 240px;

    /* Layout */
    --header-height: 56px;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
    --shadow-md: 0 4px 12px -2px rgba(0,0,0,.08), 0 2px 6px -2px rgba(0,0,0,.04);
    --shadow-lg: 0 8px 24px -4px rgba(0,0,0,.10), 0 4px 8px -4px rgba(0,0,0,.05);

    /* Additional surfaces */
    --surface-subtle: #F8FAFC;

    /* Typography scale */
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.875rem;
    --text-md: 0.9375rem;
    --text-lg: 1.0625rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Spacing scale */
    --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
    --space-4: 16px; --space-5: 20px; --space-6: 24px;
    --space-8: 32px; --space-10: 40px; --space-12: 48px;

    /* Charts */
    --chart-height: 320px;
    --chart-height-sm: 200px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ── Layout ─────────────────────────────────── */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform .2s;
}

.sidebar-logo {
    padding: 16px 20px;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo .logo-icon {
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.sidebar-logo .logo-icon-img {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-section {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    color: var(--sidebar-text);
    font-size: 13px;
    font-weight: 500;
    border-radius: 0;
    transition: background .15s, color .15s;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.nav-item.active {
    color: var(--sidebar-text-active);
    background: var(--sidebar-hover);
    border-right: 3px solid var(--sidebar-accent);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .7;
}

.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
}

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

.top-header {
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 16px; }

.page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-dim);
}

.breadcrumbs a { color: var(--text-dim); }
.breadcrumbs a:hover { color: var(--primary); }
.breadcrumbs .sep { color: var(--text-muted); }

/* ── Page Content ───────────────────────────── */

.page-content {
    padding: 28px 32px;
    max-width: 1400px;
}

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

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h2, .card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.card-body { padding: 24px; }

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

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

textarea.form-control { resize: vertical; min-height: 80px; }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236B7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-secondary {
    background: var(--surface);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-hover); }

.btn-danger {
    background: var(--error);
    color: #fff;
}
.btn-danger:hover { background: #B91C1C; color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-block { width: 100%; justify-content: center; }

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

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .3px;
    border-bottom: 2px solid var(--border);
    background: var(--surface-hover);
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
}

.table tbody tr:hover { background: var(--surface-hover); }

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

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: 12px;
}

.badge-success { background: rgba(5,150,105,.1); color: var(--success); }
.badge-error { background: rgba(220,38,38,.1); color: var(--error); }
.badge-warning { background: rgba(217,119,6,.1); color: var(--warning); }
.badge-info { background: rgba(37,99,235,.1); color: var(--info); }
.badge-muted { background: rgba(107,114,128,.1); color: var(--text-dim); }
.badge-accent { background: rgba(124,58,237,.1); color: var(--accent); }
.badge-primary { background: rgba(14,165,233,.1); color: var(--primary); }

/* ── Flash Messages ─────────────────────────── */

.flash-messages {
    padding: 0 24px;
    margin-top: 16px;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.flash-success { background: rgba(5,150,105,.08); color: var(--success); border: 1px solid rgba(5,150,105,.2); }
.flash-error { background: rgba(220,38,38,.08); color: var(--error); border: 1px solid rgba(220,38,38,.2); }
.flash-warning { background: rgba(217,119,6,.08); color: var(--warning); border: 1px solid rgba(217,119,6,.2); }
.flash-info { background: rgba(37,99,235,.08); color: var(--info); border: 1px solid rgba(37,99,235,.2); }

/* ── Auth Pages ─────────────────────────────── */

.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 32px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.auth-logo p {
    font-size: 14px;
    color: var(--text-dim);
    margin-top: 4px;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--border);
}

.oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
    font-family: inherit;
}

.btn-oauth:hover { background: var(--surface-hover); color: var(--text); }

.btn-oauth svg { width: 18px; height: 18px; }

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-dim);
}

.auth-footer a { color: var(--primary); font-weight: 500; }

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
}

/* Semantic background tints for stat cards */
.stat-card:has(.stat-value--primary) { background: rgba(14, 165, 233, 0.03); }
.stat-card:has(.stat-value--success) { background: rgba(5, 150, 105, 0.03); }
.stat-card:has(.stat-value--error)   { background: rgba(220, 38, 38, 0.03); }
.stat-card:has(.stat-value--warning) { background: rgba(217, 119, 6, 0.03); }
.stat-card:has(.stat-value--accent)  { background: rgba(124, 58, 237, 0.03); }

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .3px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-change {
    font-size: 12px;
    margin-top: 2px;
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--error); }

.stat-value--primary { color: var(--primary); }
.stat-value--success { color: var(--success); }
.stat-value--error   { color: var(--error); }
.stat-value--warning { color: var(--warning); }
.stat-value--accent  { color: var(--accent); }
.stat-value--sm      { font-size: 1.1rem; }

/* Clickable stat cards (drill-through) */
a.stat-card {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
    position: relative;
}

a.stat-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.10);
}

a.stat-card::after {
    content: '\2192';
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 14px;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity .15s, transform .15s;
}

a.stat-card:hover::after {
    opacity: 1;
    transform: translateX(2px);
}

.stat-subtitle {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ── Tabs ───────────────────────────────────── */

.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.tab {
    padding: 12px 20px;
    font-size: var(--text-base);
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    outline: none;
    font-family: inherit;
    transition: color .15s, border-color .15s;
}

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

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

/* ── Empty States ───────────────────────────── */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: .5;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 13px;
    margin-bottom: 16px;
}

/* ── Connection Status ──────────────────────── */

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.connected { background: var(--success); }
.status-dot.error { background: var(--error); }
.status-dot.untested { background: var(--text-muted); }

/* ── Report Header ─────────────────────────── */

.report-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-8);
}

.report-header__controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.report-header__meta {
    font-size: var(--text-sm);
    color: var(--text-dim);
}

.report-header__cache {
    margin-left: var(--space-2);
    font-size: var(--text-xs);
    opacity: 0.7;
}

.report-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* ── Period Selector ───────────────────────── */

.period-selector {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.period-btn {
    padding: 6px 14px;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    border: none;
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.period-btn:not(:last-child) { border-right: 1px solid var(--border); }
.period-btn.active { background: var(--primary); color: #fff; }
.period-btn:hover:not(.active) { background: var(--surface-hover); color: var(--text); }

/* ── Chart Container ───────────────────────── */

.chart-container { position: relative; height: var(--chart-height); }
.chart-container--sm { height: var(--chart-height-sm); }

/* ── Loading State ─────────────────────────── */

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-10);
    gap: var(--space-4);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner--sm { width: 16px; height: 16px; border-width: 2px; }

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

.loading-state p { color: var(--text-dim); font-size: var(--text-md); }

/* ── Error Banner ──────────────────────────── */

.error-banner {
    background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.2);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-6);
    color: var(--error);
    font-size: var(--text-base);
    display: none;
}

.error-banner.visible { display: block; }

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

.nav-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-5);
}

.nav-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-8);
    text-decoration: none;
    color: inherit;
    transition: all 0.15s;
    cursor: pointer;
    display: block;
    box-shadow: var(--shadow);
}

.nav-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.1);
    color: inherit;
}

.nav-card h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text);
    margin: 0 0 6px;
}

.nav-card p {
    font-size: var(--text-base);
    color: var(--text-dim);
    margin: 0 0 var(--space-3);
    line-height: 1.5;
}

.nav-card-link {
    font-size: var(--text-sm);
    color: var(--primary);
    font-weight: var(--font-medium);
}

/* ── Section Title ─────────────────────────── */

.section-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text);
    margin: var(--space-10) 0 var(--space-5);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border);
}

.section-title:first-child { margin-top: 0; }

/* ── Role Tags ─────────────────────────────── */

.role-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    background: var(--bg);
    color: var(--text-secondary);
    margin: 1px 2px;
}

.role-tag--privileged {
    background: rgba(220, 38, 38, 0.08);
    color: var(--error);
    font-weight: var(--font-semibold);
}

/* ── Storage Bar ───────────────────────────── */

.storage-bar {
    width: 100px;
    height: 8px;
    border-radius: 4px;
    background: var(--bg);
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

.storage-bar__fill {
    height: 100%;
    border-radius: 4px;
    background: var(--primary);
}

/* ── Table Enhancements ────────────────────── */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.cell-mono {
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: var(--text-xs);
    color: var(--text-dim);
    max-width: 420px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-mono:hover { white-space: normal; word-break: break-all; }

/* ── Refresh Button ────────────────────────── */

.btn-refresh {
    padding: 6px 12px;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
}

.btn-refresh:hover { background: var(--surface-hover); color: var(--text); }
.btn-refresh svg { width: 14px; height: 14px; }

/* ── Modal ─────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--space-6);
    max-width: 420px;
    width: 90%;
    box-shadow: var(--shadow-md);
}

.modal-box h3 {
    font-size: 16px;
    font-weight: var(--font-semibold);
    color: var(--text);
    margin-bottom: var(--space-2);
}

.modal-box p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--space-5);
}

.modal-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
}

/* ── Danger Zone ───────────────────────────── */

.danger-zone {
    border: 1px solid rgba(220,38,38,0.3);
    border-radius: var(--radius);
    margin-top: var(--space-8);
}

.danger-zone .card-header {
    color: var(--error);
    border-bottom-color: rgba(220,38,38,0.2);
}

.danger-zone .card-body p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

/* ── Animations ────────────────────────────── */

.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Sidebar Sub-items ─────────────────────── */

.nav-item--indent { padding-left: 36px; }

/* ── Dashboard Utilities ───────────────────── */

.welcome-header { margin-bottom: var(--space-6); }
.welcome-header h2 { font-size: 20px; font-weight: var(--font-bold); margin-bottom: 4px; }
.welcome-header p { font-size: 14px; color: var(--text-dim); }

.actions-bar {
    margin-bottom: var(--space-6);
    display: flex;
    gap: var(--space-2);
}

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

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

/* ── Org Switcher ───────────────────────────── */

.org-switcher {
    position: relative;
}

.org-switcher-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
}

.org-switcher-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    z-index: 200;
    display: none;
}

.org-switcher-dropdown.open { display: block; }

.org-switcher-item {
    display: block;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    transition: background .15s;
}

.org-switcher-item:hover { background: var(--surface-hover); }
.org-switcher-item.active { color: var(--primary); font-weight: 600; }

/* ── User Menu ──────────────────────────────── */

.user-menu {
    position: relative;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 200;
    display: none;
}

.user-dropdown.open { display: block; }

.user-dropdown-header {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.user-dropdown-header .name {
    font-size: 13px;
    font-weight: 600;
}

.user-dropdown-header .email {
    font-size: 12px;
    color: var(--text-dim);
}

.user-dropdown-item {
    display: block;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    transition: background .15s;
}

.user-dropdown-item:hover { background: var(--surface-hover); }

/* ── Trial Banner ──────────────────────────── */

.trial-banner {
    background: linear-gradient(135deg, #0EA5E9, #06B6D4);
    color: #fff;
    padding: 8px 24px;
    font-size: var(--text-sm);
    font-weight: 500;
    text-align: center;
}

.trial-banner strong { font-weight: 700; }

.trial-banner a {
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
    margin-left: var(--space-2);
}

.trial-banner a:hover { opacity: 0.9; }

.demo-banner {
    background: linear-gradient(135deg, #7C3AED, #A855F7);
    color: #fff;
    padding: 8px 24px;
    font-size: var(--text-sm);
    font-weight: 500;
    text-align: center;
}

.demo-banner strong { font-weight: 700; }

.demo-banner a {
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
    margin-left: var(--space-2);
}

.demo-banner a:hover { opacity: 0.9; }

/* ── Admin Panel ───────────────────────────── */

.admin-sidebar .sidebar-logo small {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.6;
    margin-top: 2px;
}

.admin-sidebar .nav-item.active {
    border-right-color: var(--accent);
    background: rgba(124, 58, 237, 0.08);
}

.admin-sidebar .nav-item:hover {
    background: rgba(124, 58, 237, 0.05);
}

/* Impersonation Banner */
.impersonation-banner {
    background: var(--warning);
    color: #fff;
    padding: 8px 24px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 200;
}

.impersonation-banner .btn-exit {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 4px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
}

.impersonation-banner .btn-exit:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Admin search bar */
.admin-search {
    margin-bottom: var(--space-6);
    display: flex;
    gap: var(--space-2);
}

.admin-search input[type="text"] {
    max-width: 400px;
    flex: 1;
}

/* Pagination */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    font-size: 13px;
}

.pagination-controls a,
.pagination-controls span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
}

.pagination-controls a:hover {
    background: var(--surface-hover);
}

.pagination-controls .current-page {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.pagination-controls .disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Admin impersonate button */
.btn-impersonate {
    background: var(--warning);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-impersonate:hover {
    opacity: 0.9;
}

/* Admin info grid */
.info-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    font-size: 13px;
}

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

.info-grid dd {
    margin: 0;
}


/* ===================================================================
   AI Insights — Chat UI
   =================================================================== */

.insights-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 48px);
    max-width: 900px;
    margin: 0 auto;
}

/* Header bar */
.insights-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 12px;
    flex-shrink: 0;
}

.insights-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.insights-title {
    font-weight: 600;
    font-size: var(--text-lg);
    color: var(--text);
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.insights-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Insight Cards */
.insight-cards {
    display: flex;
    gap: 12px;
    padding-bottom: 12px;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.insight-card {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    min-width: 220px;
    max-width: 300px;
    border-left: 3px solid var(--border);
    transition: box-shadow 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.insight-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.insight-card--warning { border-left-color: var(--warning); }
.insight-card--error { border-left-color: var(--error); }
.insight-card--success { border-left-color: var(--success); }
.insight-card--info { border-left-color: var(--info); }

.insight-card--warning .insight-card-icon { color: var(--warning); }
.insight-card--error .insight-card-icon { color: var(--error); }
.insight-card--success .insight-card-icon { color: var(--success); }
.insight-card--info .insight-card-icon { color: var(--info); }

.insight-card-icon {
    flex-shrink: 0;
    margin-top: 2px;
}

.insight-card-title {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text);
    margin-bottom: 2px;
}

.insight-card-detail {
    font-size: var(--text-xs);
    color: var(--text-dim);
    line-height: 1.4;
}

/* Suggested Question Chips */
.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 12px;
    flex-shrink: 0;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Welcome message */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    flex: 1;
}

.chat-welcome-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.chat-welcome h3 {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text);
    margin: 0 0 8px;
}

.chat-welcome p {
    font-size: var(--text-sm);
    color: var(--text-dim);
    max-width: 400px;
    margin: 0;
    line-height: 1.5;
}

/* Chat Messages */
.chat-message {
    display: flex;
    padding: 4px 0;
}

.chat-message--user {
    justify-content: flex-end;
}

.chat-message--assistant {
    justify-content: flex-start;
}

.chat-message--animate {
    animation: chatSlideIn 0.2s ease-out;
}

@keyframes chatSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: var(--text-sm);
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-bubble--user {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-bubble--assistant {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-bottom-left-radius: 4px;
}

/* Markdown styling inside assistant bubbles */
.chat-bubble--assistant h1,
.chat-bubble--assistant h2,
.chat-bubble--assistant h3 {
    font-size: var(--text-md);
    font-weight: 600;
    margin: 12px 0 6px;
    color: var(--text);
}

.chat-bubble--assistant h1:first-child,
.chat-bubble--assistant h2:first-child,
.chat-bubble--assistant h3:first-child {
    margin-top: 0;
}

.chat-bubble--assistant p {
    margin: 6px 0;
}

.chat-bubble--assistant p:first-child {
    margin-top: 0;
}

.chat-bubble--assistant p:last-child {
    margin-bottom: 0;
}

.chat-bubble--assistant ul,
.chat-bubble--assistant ol {
    margin: 6px 0;
    padding-left: 20px;
}

.chat-bubble--assistant li {
    margin: 3px 0;
}

.chat-bubble--assistant strong {
    font-weight: 600;
    color: var(--text);
}

.chat-bubble--assistant code {
    background: rgba(0,0,0,0.05);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.9em;
}

.chat-bubble--assistant pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px 14px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: var(--text-xs);
}

.chat-bubble--assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.chat-bubble--assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: var(--text-xs);
}

.chat-bubble--assistant th,
.chat-bubble--assistant td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.chat-bubble--assistant th {
    background: var(--bg);
    font-weight: 600;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input Bar */
.chat-input-bar {
    flex-shrink: 0;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px 8px 14px;
    transition: border-color 0.15s;
}

.chat-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

.chat-input-wrap textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.5;
    color: var(--text);
    background: transparent;
    min-height: 22px;
    max-height: 120px;
}

.chat-input-wrap textarea::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
}

.chat-send-btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-input-footer {
    display: flex;
    justify-content: flex-end;
    padding: 4px 4px 0;
}

.chat-char-count {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* History Dropdown */
.history-dropdown {
    position: relative;
}

.history-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 320px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.history-dropdown-menu.open {
    display: block;
}

.history-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}

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

.history-item:hover {
    background: var(--surface-hover);
}

.history-item-info {
    flex: 1;
    min-width: 0;
}

.history-item-title {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

.history-item-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    margin-left: 8px;
    transition: all 0.1s;
}

.history-item-delete:hover {
    color: var(--error);
    background: rgba(220, 38, 38, 0.08);
}

/* ── Mobile Responsive ── */

@media (max-width: 768px) {
    .insights-page {
        height: calc(100vh - var(--header-height) - 24px);
    }

    .insights-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .insight-cards {
        gap: 8px;
    }

    .insight-card {
        min-width: 180px;
        padding: 10px 12px;
    }

    .chat-bubble {
        max-width: 90%;
    }

    .history-dropdown-menu {
        width: 280px;
    }

    .chip {
        font-size: 11px;
        padding: 5px 10px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Custom Reports
   ═══════════════════════════════════════════════════════════════ */

/* Report gallery grid */
.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.report-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    cursor: pointer;
    box-shadow: var(--shadow);
}
.report-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.10);
    transform: translateY(-1px);
}

.report-card__title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text);
    margin: 0 0 6px;
    line-height: 1.3;
}

.report-card__desc {
    font-size: var(--text-sm);
    color: var(--text-dim);
    margin: 0 0 12px;
    line-height: 1.4;
}

.report-card__meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Report badges */
.report-badge {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    border-radius: 10px;
    line-height: 1.6;
}
.report-badge--ai {
    background: rgba(124, 58, 237, 0.1);
    color: var(--accent);
}
.report-badge--shared {
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary);
}

/* Widget grid (report view page) */
.widget-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}
.widget-kpi-row {
    grid-column: 1 / -1;
}
.widget-card {
    min-width: 0;
}
.widget-card--full {
    grid-column: 1 / -1;
}

/* AI prompt textarea */
.ai-prompt-area {
    min-height: 100px;
    font-family: inherit;
    font-size: var(--text-base);
    line-height: 1.5;
    resize: vertical;
}

/* Compact icon buttons (edit page widget table) */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.btn-icon:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.btn-icon--danger:hover {
    background: rgba(220, 38, 38, 0.08);
    color: var(--error);
    border-color: rgba(220, 38, 38, 0.2);
}

/* Small danger button */
.btn-danger {
    background: var(--error);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-danger:hover {
    opacity: 0.9;
}

/* Widget form (manual builder on new.html) */
.widget-form {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.widget-form__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.widget-form__fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

/* Summary charts row (list page) */
.summary-charts-row {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
}

/* ── Form Inputs (report filters) ──────────── */

.form-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    font-family: inherit;
    background: var(--surface-subtle);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
    background: var(--surface);
}
.form-input::placeholder {
    color: var(--text-muted);
}

/* Filter row */
.filter-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filter-row__search {
    position: relative;
    flex: 1;
    min-width: 200px;
}
.filter-row__search .form-input {
    width: 100%;
    margin: 0;
}
.filter-row__dropdowns {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.filter-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-input--sm {
    padding: 6px 12px;
    font-size: var(--text-sm);
    min-width: 120px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-subtle);
    font-family: inherit;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.form-input--sm:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
    background: var(--surface);
}
select.form-input--sm {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236B7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

/* Sortable table headers */
.sortable-header {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: color 0.1s, background 0.1s;
}
.sortable-header:hover {
    color: var(--primary);
    background: var(--primary-light);
}
.sort-indicator {
    font-size: 10px;
    margin-left: 4px;
    color: var(--primary);
}

/* Clickable table rows */
.report-table-row {
    transition: background 0.1s;
}
.report-table-row:hover {
    background: var(--surface-hover);
}

/* ── Custom Reports Responsive ─────────────────────────────── */
@media (max-width: 768px) {
    .report-grid {
        grid-template-columns: 1fr;
    }
    .widget-grid {
        grid-template-columns: 1fr;
    }
    .widget-card--full {
        grid-column: 1;
    }
    .widget-form__fields {
        grid-template-columns: 1fr;
    }
    .summary-charts-row {
        flex-direction: column;
    }
    .filter-row {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 14px;
    }
    .filter-row__search {
        min-width: 0;
    }
    .filter-row__dropdowns {
        flex-wrap: wrap;
    }
}

/* ========================================================================
   Ask SnowLedger contextual chat panel
   ======================================================================== */

.ask-panel-trigger {
    position: fixed;
    top: 14px;
    right: 180px;
    z-index: 90;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: linear-gradient(135deg, #0ea5e9 0%, #14b8a6 100%);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ask-panel-trigger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.5);
}
.ask-panel-trigger svg { flex-shrink: 0; }

.ask-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    background: #fff;
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}
.ask-panel.open { transform: translateX(0); }

.ask-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-subtle, #f8fafc);
}
.ask-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ask-panel-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ea5e9 0%, #14b8a6 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ask-panel-title-main {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}
.ask-panel-title-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ask-panel-close {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 6px;
}
.ask-panel-close:hover { background: rgba(0, 0, 0, 0.05); color: var(--text); }

.ask-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ask-panel-empty {
    margin: auto 0;
    text-align: center;
    color: var(--text-secondary);
    padding: 24px 12px;
}
.ask-panel-empty-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e0f2fe 0%, #ccfbf1 100%);
    color: #0ea5e9;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
}
.ask-panel-empty p {
    font-size: 14px;
    margin: 0 0 14px;
    color: var(--text);
}
.ask-panel-prompts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}
.ask-panel-prompt {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ask-panel-prompt:hover {
    border-color: var(--primary);
    background: #f0f9ff;
}

.ask-panel-msg {
    display: flex;
}
.ask-panel-msg--user { justify-content: flex-end; }
.ask-panel-msg--assistant { justify-content: flex-start; }

.ask-panel-msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
}
.ask-panel-msg--user .ask-panel-msg-bubble {
    background: linear-gradient(135deg, #0ea5e9 0%, #14b8a6 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ask-panel-msg--assistant .ask-panel-msg-bubble {
    background: #f1f5f9;
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.ask-panel-msg--assistant .ask-panel-msg-bubble p { margin: 0 0 8px; }
.ask-panel-msg--assistant .ask-panel-msg-bubble p:last-child { margin-bottom: 0; }
.ask-panel-msg--assistant .ask-panel-msg-bubble ul,
.ask-panel-msg--assistant .ask-panel-msg-bubble ol {
    margin: 4px 0 8px; padding-left: 20px;
}
.ask-panel-msg--assistant .ask-panel-msg-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}

.ask-panel-typing {
    display: inline-block;
    color: var(--text-secondary);
    font-style: italic;
    letter-spacing: 2px;
    animation: askPanelPulse 1.2s ease-in-out infinite;
}
@keyframes askPanelPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.ask-panel-form {
    border-top: 1px solid var(--border);
    padding: 12px 14px;
    position: relative;
    background: #fff;
}
.ask-panel-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 44px 10px 14px;
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    max-height: 160px;
    line-height: 1.4;
}
.ask-panel-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}
.ask-panel-send {
    position: absolute;
    right: 22px;
    bottom: 22px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: linear-gradient(135deg, #0ea5e9 0%, #14b8a6 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.ask-panel-send:disabled { opacity: 0.5; cursor: wait; }
.ask-panel-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 6px;
    text-align: center;
}

@media (max-width: 640px) {
    .ask-panel { width: 100vw; }
    .ask-panel-trigger { right: 12px; top: auto; bottom: 18px; }
}

/* AI Insights — full-page layout with chat history right-rail */
.insights-layout {
    display: flex;
    gap: 20px;
    align-items: stretch;
    min-height: calc(100vh - 140px);
}
.insights-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.insights-rail {
    width: 280px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 120px);
    overflow: hidden;
    transition: width 0.2s ease, margin 0.2s ease, opacity 0.2s ease;
}
.insights-layout.rail-collapsed .insights-rail {
    width: 0;
    margin: 0;
    opacity: 0;
    border: none;
    overflow: hidden;
}
.insights-rail-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-subtle, #f8fafc);
}
.insights-rail-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.insights-rail-empty {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    padding: 28px 10px;
}
.insights-rail-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s ease;
}
.insights-rail-item:hover { background: #f0f9ff; }
.insights-rail-item.active { background: #e0f2fe; }
.insights-rail-item-info {
    flex: 1;
    min-width: 0;
}
.insights-rail-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.insights-rail-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.insights-rail-item-delete {
    background: none;
    border: none;
    padding: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease;
    border-radius: 4px;
}
.insights-rail-item:hover .insights-rail-item-delete { opacity: 1; }
.insights-rail-item-delete:hover { background: rgba(0, 0, 0, 0.06); color: var(--error, #dc2626); }

@media (max-width: 900px) {
    .insights-layout { flex-direction: column; }
    .insights-rail { width: 100%; max-height: 280px; }
    .insights-layout.rail-collapsed .insights-rail { display: none; }
}

/* Report preview card (chat-to-report) */
.ask-panel-report-preview,
.chat-report-preview {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    max-width: 90%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.chat-report-preview {
    margin: 10px 0;
    max-width: 640px;
}
.rp-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.rp-icon {
    display: inline-flex;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: linear-gradient(135deg, #0ea5e9 0%, #14b8a6 100%);
    color: #fff;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.rp-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}
.rp-widget-list {
    list-style: none;
    padding: 0;
    margin: 0 0 12px;
    border-top: 1px solid var(--border);
}
.rp-widget-list li {
    padding: 7px 0;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.rp-widget-list li:last-child { border-bottom: none; }
.rp-type {
    color: var(--text-secondary);
    font-size: 11.5px;
    text-transform: capitalize;
    white-space: nowrap;
}
.rp-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.rp-status {
    font-size: 12px;
    color: var(--text-secondary);
}
.rp-status a { color: var(--primary); font-weight: 600; }
