:root {
    --bg: #0b1120;
    --bg-panel: #131b2e;
    --bg-panel-alt: #17203a;
    --bg-input: #0f1626;
    --border: #253150;
    --text: #e7ecf7;
    --text-muted: #8b95ac;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --green: #22c55e;
    --green-soft: rgba(34, 197, 94, 0.15);
    --yellow: #eab308;
    --yellow-soft: rgba(234, 179, 8, 0.15);
    --red: #ef4444;
    --red-soft: rgba(239, 68, 68, 0.15);
    --radius: 10px;
    --shadow: 0 4px 24px rgba(0,0,0,0.35);
}

[data-theme="light"] {
    --bg: #f3f5fa;
    --bg-panel: #ffffff;
    --bg-panel-alt: #f8f9fc;
    --bg-input: #ffffff;
    --border: #dde2ee;
    --text: #16213a;
    --text-muted: #667085;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --shadow: 0 4px 20px rgba(20,30,60,0.08);
}

/* Color schemes — layered on top of light/dark, just swaps the accent hue */
[data-scheme="emerald"] { --accent: #10b981; --accent-hover: #059669; --accent-soft: rgba(16, 185, 129, 0.15); }
[data-theme="light"][data-scheme="emerald"] { --accent-soft: rgba(16, 185, 129, 0.1); }
[data-scheme="violet"] { --accent: #8b5cf6; --accent-hover: #7c3aed; --accent-soft: rgba(139, 92, 246, 0.15); }
[data-theme="light"][data-scheme="violet"] { --accent-soft: rgba(139, 92, 246, 0.1); }

/* Image theme — a fixed photo background behind translucent, blurred UI panels.
   Pick one of the five photos via data-image-theme on <html>; defaults to the ocean shot. */
[data-style="image"] .app-shell { position: relative; }
[data-style="image"] .app-shell::before {
    content: "";
    position: fixed; inset: 0; z-index: 0;
    background-image: url('/assets/img/theme-ocean.jpg');
    background-size: cover; background-position: center; background-attachment: fixed;
}
[data-style="image"][data-image-theme="southern_utah"] .app-shell::before { background-image: url('/assets/img/theme-southern-utah.jpg'); }
[data-style="image"][data-image-theme="oregon_coast_1"] .app-shell::before { background-image: url('/assets/img/theme-oregon-coast-1.jpg'); }
[data-style="image"][data-image-theme="oregon_coast_2"] .app-shell::before { background-image: url('/assets/img/theme-oregon-coast-2.jpg'); }
[data-style="image"][data-image-theme="oregon_coast_3"] .app-shell::before { background-image: url('/assets/img/theme-oregon-coast-3.jpg'); }
[data-style="image"][data-theme="dark"] .app-shell::before { background-color: rgba(4,10,22,0.62); background-blend-mode: darken; }
[data-style="image"][data-theme="light"] .app-shell::before { background-color: rgba(255,255,255,0.4); background-blend-mode: lighten; }
[data-style="image"] .sidebar,
[data-style="image"] .topbar,
[data-style="image"] .page { position: relative; z-index: 1; }
[data-style="image"] .sidebar { background: color-mix(in srgb, var(--bg-panel) 72%, transparent); backdrop-filter: blur(14px); }
[data-style="image"] .topbar { background: color-mix(in srgb, var(--bg-panel) 72%, transparent); backdrop-filter: blur(14px); }
[data-style="image"] .card,
[data-style="image"] .table-wrap,
[data-style="image"] .stat-card,
[data-style="image"] .modal { background: color-mix(in srgb, var(--bg-panel) 82%, transparent); backdrop-filter: blur(10px); }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

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

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

/* Sidebar — grows to fit its own content (all nav items visible, no inner scrollbar);
   scrolls along with the page rather than staying pinned on long pages. */
.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    min-height: 100vh;
}
.brand { padding: 4px 8px 20px; }
.brand-logo { display: block; max-width: 100%; height: auto; }
.brand-logo-dark { display: none; }
[data-theme="dark"] .brand-logo-light { display: none; }
[data-theme="dark"] .brand-logo-dark { display: block; }
.nav-group { margin-bottom: 18px; }
.nav-group-label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.08em; padding: 0 10px 6px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 8px; color: var(--text);
    font-size: 14px; margin-bottom: 2px;
}
.nav-link:hover { background: var(--bg-panel-alt); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
/* Used to push nav-footer to the bottom via flex:1, but with the sidebar now growing to
   its full natural height (see .sidebar above), that meant "the bottom" on a long page
   could be thousands of pixels down. Footer nav now just follows the last nav-group. */
.nav-spacer { height: 8px; }
.nav-footer { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 20px; }
.brand-logo { flex: 1; min-width: 0; }
.sidebar-collapse-toggle {
    background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted);
    width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; margin-left: auto; padding: 0;
}
.sidebar-collapse-toggle:hover { background: var(--bg-panel-alt); color: var(--text); }
.sidebar-collapse-toggle svg { width: 14px; height: 14px; transition: transform 0.2s ease; }

.sidebar-toggle-mobile {
    display: none; background: none; border: 1px solid var(--border); border-radius: 6px;
    width: 32px; height: 32px; align-items: center; justify-content: center;
    color: var(--text); cursor: pointer; margin-right: 12px; flex-shrink: 0; padding: 0;
}
.sidebar-toggle-mobile svg { width: 18px; height: 18px; }
.sidebar-backdrop { display: none; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--bg-panel);
}
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.page { padding: 28px; max-width: 1400px; }

/* Collapsed sidebar — desktop only (icon-only rail). Scoped to min-width so this never
   fights the mobile off-canvas drawer or the light/dark logo toggle on small screens.
   Placed after the base rules above so it reliably wins at matching specificity. */
@media (min-width: 861px) {
    [data-sidebar-collapsed="1"] .sidebar { width: 64px; }
    [data-sidebar-collapsed="1"] .sidebar .brand { justify-content: center; padding-left: 0; padding-right: 0; }
    [data-sidebar-collapsed="1"] .sidebar .brand-logo { display: none; }
    [data-sidebar-collapsed="1"] .sidebar .nav-label,
    [data-sidebar-collapsed="1"] .sidebar .nav-group-label { display: none; }
    [data-sidebar-collapsed="1"] .sidebar .nav-link { justify-content: center; }
    [data-sidebar-collapsed="1"] .sidebar-collapse-toggle svg { transform: rotate(180deg); }
}

@media (max-width: 860px) {
    .sidebar-toggle-mobile { display: inline-flex; }
    .sidebar-collapse-toggle { display: none; }
    /* Matches [data-style="image"] .sidebar's specificity too — that rule sets
       position:relative (to sit above the fixed background image) and would otherwise
       win over a plain .sidebar selector here and keep the sidebar in normal flow. */
    .sidebar,
    [data-style="image"] .sidebar {
        position: fixed; top: 0; left: 0; z-index: 60;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,0.25);
    }
    #app-shell.sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
        z-index: 55; opacity: 0; pointer-events: none; transition: opacity 0.22s ease;
    }
    #app-shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    .page { padding: 18px; }
    .topbar { padding: 12px 16px; flex-wrap: wrap; row-gap: 8px; }
    .topbar-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
    .topbar-right { gap: 8px; flex-wrap: wrap; flex-basis: 100%; justify-content: flex-end; }
    .topbar-user-label { display: none; }
}

.theme-toggle {
    background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
    border-radius: 20px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}

/* Breadcrumb / page header */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { margin: 0 0 4px; font-size: 24px; }
.page-header p { margin: 0; color: var(--text-muted); }
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.breadcrumb a { color: var(--text-muted); }

/* Cards / panels */
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h2, .card h3 { margin-top: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.06em; }
.stat-card .value { font-size: 32px; font-weight: 700; margin-top: 6px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }

/* Forms */
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=url], select, textarea {
    width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text); font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; }
.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.company-echo { font-size: 12px; color: var(--accent); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.copy-notice { font-size: 12px; color: var(--green); font-weight: 600; }
.save-notice { font-size: 12px; color: var(--green); font-weight: 600; margin-left: 8px; align-self: center; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.dash-table { table-layout: fixed; }
.dash-table .col-name { width: 40%; }
.dash-table .col-secondary { width: 25%; }
.dash-table .col-status { width: 15%; }
.dash-table .col-when { width: 20%; }
.dash-table td, .dash-table th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link { font-weight: 600; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Filters / search */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=text] { max-width: 320px; }
.status-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.status-tab { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); color: var(--text-muted); font-size: 13px; }
.status-tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: var(--green-soft); color: var(--green); }
.flash-error { background: var(--red-soft); color: var(--red); }

/* Collapsible */
.collapsible-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.collapsible-body { margin-top: 14px; }
.collapsible-body.collapsed { display: none; }
.chevron { transition: transform 0.15s; }
.collapsible.open .chevron { transform: rotate(90deg); }

/* Chips (tags) */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.chip-focus { background: var(--green-soft); color: var(--green); }
.chip-negative { background: var(--red-soft); color: var(--red); }
.chip-brand { background: var(--accent-soft); color: var(--accent); }
.chip button { background: none; border: none; color: inherit; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; }
.chip-list summary { list-style: none; }
.chip-list summary::-webkit-details-marker { display: none; }
.chip-list details[open] summary { margin-bottom: 8px; }
.chip-form { display: flex; gap: 8px; margin-bottom: 18px; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(5,8,16,0.6);
    display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 420px; max-width: 90vw; box-shadow: var(--shadow); }
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.empty-state { color: var(--text-muted); padding: 30px; text-align: center; }
.star-display { color: var(--yellow); font-size: 18px; letter-spacing: 1px; white-space: nowrap; }

.quicklink-box { background: var(--bg-panel-alt); border: 1px dashed var(--border); border-radius: 8px; padding: 14px; font-family: monospace; font-size: 13px; word-break: break-all; }

.ai-loading-overlay { position: fixed; inset: 0; background: rgba(5,8,16,0.6); display: none; align-items: center; justify-content: center; z-index: 200; }
.ai-loading-overlay.open { display: flex; }
.ai-loading-box { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 40px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 16px; }
.ai-loading-spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: ai-loading-spin 0.8s linear infinite; }
.ai-loading-text { font-weight: 600; color: var(--text); }
@keyframes ai-loading-spin { to { transform: rotate(360deg); } }
.ai-loading-box:has(.ai-loading-log:not([hidden])) { width: 560px; max-width: 90vw; align-items: stretch; }
.ai-loading-log { width: 100%; max-height: 280px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0; font-size: 12px; font-family: monospace; white-space: pre-wrap; color: var(--text-muted); text-align: left; }

.term-group-card { padding: 0; }
.term-group-card > summary { list-style: none; cursor: pointer; padding: 20px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.term-group-card > summary::-webkit-details-marker { display: none; }
.term-group-card > summary::before { content: '▸'; display: inline-block; margin-right: 10px; color: var(--text-muted); transition: transform 0.15s; }
.term-group-card[open] > summary::before { transform: rotate(90deg); }
.term-group-title { font-weight: 700; font-size: 15px; }
.term-group-body { padding: 0 20px 20px; }
.term-block-subcard { background: var(--bg-panel-alt); border-left: 3px solid var(--accent-soft); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
