:root {
    /* SaaS Zinc / Indigo Theme */
    --bg-base: #09090b;       /* Zinc 950 */
    --bg-surface: #18181b;    /* Zinc 900 */
    --bg-elevated: #27272a;   /* Zinc 800 */
    --border-subtle: #27272a;
    --border-strong: #3f3f46;
    
    --text-primary: #f4f4f5;  /* Zinc 50 */
    --text-muted: #a1a1aa;    /* Zinc 400 */
    
    --brand-primary: #4f46e5; /* Indigo 600 */
    --brand-hover: #4338ca;   /* Indigo 700 */
    --brand-subtle: rgba(79, 70, 229, 0.15);
    
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --radius: 6px;
    --transition: all 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    overflow: hidden; /* App wrapper handles scroll */
}

/* Base SaaS Layout */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.brand {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.brand-logomark {
    width: 24px; height: 24px;
    border-radius: 4px;
    background: var(--brand-primary);
    box-shadow: 0 0 10px var(--brand-subtle);
}
.brand h1 { font-size: 1rem; font-weight: 700; color: var(--text-primary); letter-spacing: 0.02em; }

.side-nav {
    flex: 1;
    padding: 24px 16px;
    overflow-y: auto;
}
.nav-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 8px 12px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    transition: var(--transition);
    margin-bottom: 4px;
}
.nav-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.nav-item.active { background: var(--brand-subtle); color: var(--brand-primary); }

.user-profile {
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
}
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--bg-elevated);
    display: flex; justify-content: center; align-items: center;
    font-size: 0.8rem; font-weight: 600; color: var(--text-primary);
}
.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: 0.7rem; color: var(--text-muted); }

/* Main Content Area */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--bg-base);
}

/* Topbar */
.topbar {
    height: 72px;
    padding: 0 32px;
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
}

.breadcrumbs { display: flex; align-items: center; padding-top: 6px; font-size: 0.875rem; color: var(--text-muted); }
.breadcrumbs .divider { margin: 0 8px; opacity: 0.5; }
.breadcrumbs .current { color: var(--text-primary); font-weight: 500; }

.search-form { display: flex; gap: 12px; align-items: center; }

.search-input-wrapper {
    position: relative;
    width: 340px;
}
.search-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: var(--transition);
}
input:focus { outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 2px var(--brand-subtle); }

button {
    padding: 8px 16px;
    background: var(--brand-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex; justify-content: center; align-items: center; min-width: 90px;
}
button:hover { background: var(--brand-hover); }

.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dashboard Container */
.dashboard-container {
    padding: 32px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* KPI Widgets */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.kpi-widget {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 20px;
    display: flex; flex-direction: column;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.kpi-title { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); margin-bottom: 8px; }
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; }

/* Accordion Result Cards */
.result-list { display: flex; flex-direction: column; gap: 12px; }

.db-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}
.db-card:hover { border-color: var(--border-strong); }

.db-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    cursor: pointer; user-select: none;
}

.db-header-left { display: flex; align-items: center; gap: 16px; }
.db-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.db-badge { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-strong); color: var(--text-muted); padding: 4px 10px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }

.expand-icon { color: var(--text-muted); transition: transform 0.2s ease; }
.db-card.expanded .expand-icon { transform: rotate(180deg); }

.db-body { display: none; padding: 0 20px 20px 20px; }
.db-card.expanded .db-body { display: block; border-top: 1px solid var(--border-subtle); padding-top: 20px; margin-top: 4px; }

.db-info { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 20px; line-height: 1.6; }

.data-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; background: var(--bg-base); padding: 16px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid var(--border-subtle); }
.data-item { display: flex; flex-direction: column; }
.data-key { font-size: 0.65rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.data-val { font-size: 0.875rem; color: var(--text-primary); word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; cursor: pointer; transition: all 0.2s ease; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; border: 1px solid transparent; }
.data-val.hl { color: #f43f5e; font-weight: 500; } /* Rose 500 */
.data-val:hover { background: rgba(255,255,255,0.05); border-color: var(--border-strong); }

/* Empty States */
.empty-dashboard { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 300px; color: var(--text-muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: rgba(24, 24, 27, 0.5); }
.empty-icon-wrapper { margin-bottom: 16px; padding: 16px; background: var(--bg-base); border-radius: 50%; color: var(--text-muted); border: 1px solid var(--border-subtle); }
.empty-dashboard h3 { font-size: 1rem; color: var(--text-primary); margin-bottom: 8px; font-weight: 500; }
.sub-text { font-size: 0.875rem; opacity: 0.8; }

.status-message { font-size: 0.875rem; text-align: center; padding: 12px; margin-bottom: 24px; border-radius: var(--radius); display: none; }
.status-message.show { display: block; }
.error-msg { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }

/* Views & Routing Logic */
.view-container { display: none; }
.view-container.active { display: block; animation: fadeIn 0.3s ease forwards; }

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

/* History Table */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; border: 1px solid var(--border-subtle); }
.history-table { width: 100%; min-width: 800px; border-collapse: collapse; text-align: left; }
.history-table th { padding: 12px 16px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 1px solid var(--border-strong); background: rgba(0,0,0,0.1); }
.history-table td { padding: 16px; font-size: 0.875rem; color: var(--text-primary); border-bottom: 1px solid var(--border-subtle); }
.history-table tr:hover td { background: rgba(255,255,255,0.02); }
.history-table td:first-child { font-weight: 600; color: #60a5fa; }

.view-btn {
    padding: 6px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
}
.view-btn:hover {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: #ffffff;
}

.pagination-controls { display: flex; justify-content: space-between; align-items: center; padding-top: 16px; margin-top: 20px; border-top: 1px dashed var(--border-strong); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #52525b; }
pre { color: #a1a1aa; font-family: monospace; font-size: 0.85rem; white-space: pre-wrap; padding: 16px; background: var(--bg-base); border: 1px solid var(--border-subtle); border-radius: var(--radius); overflow-x: auto; }

/* Toast Notification */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; pointer-events: none; }
.toast { background: var(--bg-elevated); color: var(--text-primary); padding: 12px 24px; border-radius: var(--radius); border-left: 4px solid #10b981; box-shadow: 0 10px 25px rgba(0,0,0,0.5); font-size: 0.875rem; font-weight: 500; transform: translateX(120%); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease; opacity: 0; pointer-events: auto; }
.toast.show { transform: translateX(0); opacity: 1; }
.toast.error { border-left-color: var(--danger); }

/* Responsive Media Queries */
.mobile-top-nav { display: none; }
.hamburger-btn { display: none; background: none; border: none; color: var(--text-primary); cursor: pointer; padding: 4px; border-radius: 4px; }
.sidebar-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); z-index: 999; display: none; backdrop-filter: blur(2px); transition: opacity 0.3s; opacity: 0; }
.sidebar-overlay.open { display: block; opacity: 1; pointer-events: auto; }

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    
    .mobile-top-nav { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border-subtle); z-index: 50; }
    .hamburger-btn { display: block; }
    
    .sidebar { position: fixed; left: -100%; top: 0; height: 100vh; width: 280px; z-index: 1000; flex-direction: column; background: var(--bg-surface); transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1); border-right: 1px solid var(--border-subtle); padding: 0; box-shadow: 2px 0 16px rgba(0,0,0,0.5); }
    .sidebar.open { left: 0; }
    
    .desktop-brand { display: none; }
    .side-nav { flex-direction: column; display: flex; padding: 24px 16px; align-items: stretch; gap: 4px; }
    
    .nav-label { display: block; }
    .nav-item { white-space: normal; }
    .user-profile { display: flex; }
    
    .topbar { padding: 16px; flex-direction: column; align-items: flex-start; gap: 16px; position: static; background: transparent; backdrop-filter: none; border-bottom: none; height: auto; }
    
    .search-form { flex-direction: column; width: 100%; }
    .search-input-wrapper { width: 100%; }
    button#submitBtn { width: 100%; padding: 12px; }
    
    .dashboard-container { padding: 16px; }
    .db-header { flex-direction: column; align-items: flex-start; position: relative; }
    .expand-icon { position: absolute; right: 16px; top: 20px; }
    
    .toast-container { left: 16px; right: 16px; bottom: 16px; }
    .toast { transform: translateY(120%); }
    .toast.show { transform: translateY(0); }
}

/* --- Incognito toggle --- */
.incognito-toggle { display: flex; align-items: center; gap: 6px; padding: 0 12px; height: 40px; white-space: nowrap;
    font-size: 0.85rem; font-weight: 500; color: var(--text-muted); cursor: pointer; user-select: none;
    border: 1px solid var(--border-strong); border-radius: 8px; }
.incognito-toggle:has(input:checked) { color: #fbbf24; border-color: rgba(245, 158, 11, 0.5); background: rgba(245, 158, 11, 0.1); }
.incognito-toggle input { accent-color: #f59e0b; cursor: pointer; }

/* --- PDF export via the browser print dialog (Save as PDF) --- */
.print-only { display: none; }
@media print {
    .sidebar, .mobile-top-nav, .sidebar-overlay, .topbar, .toast-container,
    #paginationControls, #viewHistory, .expand-icon, .view-btn { display: none !important; }
    .app-layout, .main-wrapper, .dashboard-container { display: block !important; margin: 0; padding: 0; max-width: none; }
    .print-only { display: block; font-size: 0.8rem; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid #999; }
    /* every card prints fully expanded regardless of what is open on screen */
    .db-body { display: block !important; }
    .db-card { break-inside: avoid; page-break-inside: avoid; border: 1px solid #bbb !important; box-shadow: none !important; }
    .db-header { cursor: default; }
    body, .db-card, .db-header, .db-body, .kpi-widget, .db-info, .data-item {
        background: #fff !important; color: #000 !important; }
    .db-title, .data-key, .data-val, .kpi-title, .kpi-value, .print-only { color: #000 !important; }
    .data-val.hl { font-weight: 700; }
    @page { margin: 14mm; }
}
