/* =========================================================
   Tetra OS — Design System v2
   Midnight Blueprint · Precision Instrument Aesthetic
   ========================================================= */

/* Fonts loaded via <link> in base.html:
   DM Serif Display · Instrument Sans · JetBrains Mono  */

/* ── Dark theme (default) ───────────────────────────────── */
:root {
    --bg-base:        #111111;
    --bg-surface:     #191919;
    --bg-elevated:    #212121;
    --bg-hover:       #282828;
    --bg-active:      #2E2E2E;

    --border:         #2A2A2A;
    --border-light:   #363636;

    --text-primary:   #F0F0EE;
    --text-secondary: #A0A09E;
    --text-muted:     #606060;

    --accent:         #C69653;
    --accent-dim:     #5C4018;
    --accent-glow:    rgba(198, 150, 83, 0.10);

    --green:          #3DD68C;
    --red:            #F16A6A;
    --yellow:         #E8C547;
    --orange:         #E87B3A;
    --danger:         #F16A6A;

    --sidebar-width:  220px;
    --radius:         6px;
    --radius-lg:      10px;

    --font-display: 'Montserrat', 'Instrument Sans', system-ui, sans-serif;
    --font-sans:    'Instrument Sans', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Light theme ────────────────────────────────────────── */
[data-theme="light"] {
    --bg-base:        #F4F4F2;
    --bg-surface:     #FFFFFF;
    --bg-elevated:    #ECECEA;
    --bg-hover:       #E6E6E4;
    --bg-active:      #DFDEDD;

    --border:         #DEDEDC;
    --border-light:   #D4D4D2;

    --text-primary:   #1C1C1E;
    --text-secondary: #505056;
    --text-muted:     #90909A;

    --accent:         #B8922A;
    --accent-dim:     rgba(184, 146, 42, 0.25);
    --accent-glow:    rgba(184, 146, 42, 0.09);

    --green:          #15803D;
    --red:            #B91C1C;
    --yellow:         #92400E;
    --orange:         #C2410C;
    --danger:         #B91C1C;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }

/* ── Layout ─────────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* =========================================================
   Sidebar
   ========================================================= */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

/* Subtle gold gradient accent on right edge */
.sidebar::after {
    content: '';
    position: absolute;
    top: 0; right: -1px;
    width: 1px; height: 100%;
    background: linear-gradient(to bottom,
        transparent 0%,
        var(--accent) 25%,
        var(--accent) 75%,
        transparent 100%
    );
    opacity: 0.18;
    pointer-events: none;
    z-index: 1;
}

/* ── Collapsed sidebar ───────────────────────────────────── */
.sidebar.collapsed { width: 48px; }

.sidebar.collapsed .nav-label,
.sidebar.collapsed .logo-text,
.sidebar.collapsed .core-context,
.sidebar.collapsed .user-name { display: none; }

.sidebar.collapsed .sidebar-header {
    padding: 14px 8px;
    align-items: center;
    justify-content: center;
}
.sidebar.collapsed .sidebar-logo { justify-content: center; }

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 9px 0;
}

.sidebar-theme-btn { margin-left: auto; }
.sidebar.collapsed .sidebar-theme-btn { margin-left: 0; }

.sidebar-version {
    padding: 4px 16px 10px;
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: .04em;
    opacity: 0.6;
}
.sidebar.collapsed .sidebar-version {
    text-align: center;
    padding: 4px 0 10px;
}

.sidebar.collapsed .sidebar-footer {
    flex-direction: column;
    align-items: center;
    padding: 10px 0 12px;
    gap: 6px;
}

/* ── Sidebar header ──────────────────────────────────────── */
.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-mark {
    width: 30px;
    height: 28px;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.logo-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    letter-spacing: -0.1px;
}

.logo-sub {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

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

.nav-section {
    padding: 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 450;
    transition: background 0.12s, color 0.12s, box-shadow 0.12s;
    cursor: pointer;
    white-space: nowrap;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 550;
    box-shadow: inset 2px 0 0 var(--accent);
}


.nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.65;
    transition: opacity 0.12s;
}

.nav-item:hover .nav-icon { opacity: 0.88; }
.nav-item.active .nav-icon { opacity: 1; }

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 16px;
}

/* ── Main content ────────────────────────────────────────── */
.main-content {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-base);
    background-image:
        linear-gradient(rgba(198,150,83,0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(198,150,83,0.04) 1px, transparent 1px);
    background-size: 28px 28px;
}

.content-area {
    max-width: 1200px;
    padding: 32px 36px;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
    margin-bottom: 28px;
}

.page-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.page-subtitle {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
    color: var(--text-muted);
    font-size: 13px;
    padding: 48px 0;
}

/* =========================================================
   Cards
   ========================================================= */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.018) 0%, transparent 55%);
    pointer-events: none;
}

.card-title {
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
}

/* =========================================================
   Buttons
   ========================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    transition: background 0.12s, opacity 0.12s, box-shadow 0.12s, transform 0.08s;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    color: #111111;
    box-shadow: 0 1px 6px rgba(198, 150, 83, 0.22);
}
.btn-primary:hover {
    opacity: 0.90;
    box-shadow: 0 3px 10px rgba(198, 150, 83, 0.32);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-danger {
    background: transparent;
    color: var(--red);
    border: 1px solid rgba(241, 106, 106, 0.20);
}
.btn-danger:hover { background: rgba(241, 106, 106, 0.08); }

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

/* =========================================================
   Tables
   ========================================================= */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

thead th.th-sort { cursor: pointer; user-select: none; }
thead th.th-sort:hover { color: var(--text-secondary); }
.sort-ind { margin-left: 3px; opacity: 0.5; font-size: 10px; }

tbody td {
    padding: 10px 14px;
    color: var(--text-primary);
    vertical-align: middle;
}

/* ── Filter tabs ─────────────────────────────────────────── */
.filter-tabs {
    display: flex;
    gap: 4px;
}

.filter-tab {
    padding: 5px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    background: transparent;
    border: 1px solid transparent;
    transition: background 0.1s, color 0.1s;
}
.filter-tab:hover { background: var(--bg-elevated); color: var(--text-secondary); }
.filter-tab.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border);
}

/* ── Row states ──────────────────────────────────────────── */
.row-overdue td { color: var(--orange); }
.row-overdue td strong { color: var(--orange); }
.row-overdue:hover { background: rgba(232, 123, 58, 0.05) !important; }

.row-paid { opacity: 0.50; }
.row-paid:hover { opacity: 0.72; background: var(--bg-hover) !important; }

/* Invoice detail sub-table */
.detail-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-base);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.detail-table thead th {
    background: var(--bg-base);
    font-size: 10.5px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--border-light);
}
.detail-table tbody td {
    font-size: 12px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}
.detail-table tbody tr:last-child td { border-bottom: none; }

/* =========================================================
   Form controls
   ========================================================= */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="search"],
select,
textarea {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    padding: 8px 11px;
    width: 100%;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235a5a72' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

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

/* =========================================================
   Badges
   ========================================================= */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.badge-green  { background: rgba(61,  214, 140, 0.12); color: var(--green); }
.badge-red    { background: rgba(241, 106, 106, 0.12); color: var(--red); }
.badge-yellow { background: rgba(232, 197, 71,  0.12); color: var(--yellow); }
.badge-orange { background: rgba(232, 123, 58,  0.12); color: var(--orange); }
.badge-blue   { background: var(--accent-glow);         color: var(--accent); }
.badge-muted  { background: var(--bg-elevated);         color: var(--text-muted); }

/* =========================================================
   Utilities
   ========================================================= */

.mono { font-family: var(--font-mono); }
.text-muted      { color: var(--text-muted); }
.text-secondary  { color: var(--text-secondary); }
.text-accent     { color: var(--accent); }
.text-green      { color: var(--green); }
.text-red        { color: var(--red); }
.text-right      { text-align: right; }

.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.ml-2 { margin-left: 6px; }

/* =========================================================
   Intake Module
   ========================================================= */

.section-heading {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
}

/* Drop zone */
.drop-zone {
    border: 1.5px dashed var(--border-light);
    border-radius: var(--radius-lg);
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--bg-surface);
    margin-bottom: 16px;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.drop-icon svg {
    width: 28px;
    height: 28px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.drop-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Upload status log */
.upload-log {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.upload-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
}

.upload-name {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 320px;
}

/* Intake queue spinner */
@keyframes queue-spin { to { transform: rotate(360deg); } }
.queue-spinner {
    display: inline-block;
    width: 9px;
    height: 9px;
    border: 1.5px solid rgba(0,0,0,0.15);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: queue-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
    flex-shrink: 0;
}

/* ── Review page ─────────────────────────────────────────── */
.review-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}

/* Notice sections */
.notice-section {
    margin-bottom: 6px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.notice-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: var(--bg-elevated);
    color: var(--text-muted);
    text-align: left;
    letter-spacing: 0.03em;
}
.notice-toggle:hover { background: var(--bg-hover); }
.notice-toggle-warn { color: var(--orange); background: rgba(232, 123, 58, 0.07); }
.notice-toggle-warn:hover { background: rgba(232, 123, 58, 0.12); }

.notice-chevron {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    transition: transform 0.15s;
    opacity: 0.7;
}
.notice-toggle.open .notice-chevron { transform: rotate(180deg); }

.notice-body {
    display: none;
    flex-direction: column;
    gap: 3px;
    padding: 6px 8px;
    background: var(--bg-base);
}
.notice-body.open { display: flex; }

.notice-item {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: calc(var(--radius) - 1px);
    border-left: 3px solid transparent;
    line-height: 1.4;
}
.notice-green  { color: var(--green);  border-color: var(--green);  background: rgba(61,  214, 140, 0.06); }
.notice-yellow { color: var(--yellow); border-color: var(--yellow); background: rgba(232, 197, 71,  0.06); }
.notice-orange { color: var(--orange); border-color: var(--orange); background: rgba(232, 123, 58,  0.07); }
.notice-red    { color: var(--red);    border-color: var(--red);    background: rgba(241, 106, 106, 0.07); }

/* Read-only description cell */
.line-desc-static {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 6px;
    line-height: 1.4;
}

/* Split layout */
.review-split {
    display: flex;
    gap: 0;
    height: calc(100vh - 130px);
    min-height: 500px;
}

.review-resizer {
    width: 20px;
    flex-shrink: 0;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.02);
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    transition: background 0.15s, border-color 0.15s;
    position: relative;
}
.review-resizer::after {
    content: '';
    display: block;
    width: 3px;
    height: 40px;
    border-radius: 2px;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255,255,255,0.22) 0px,
        rgba(255,255,255,0.22) 3px,
        transparent 3px,
        transparent 7px
    );
}
.review-resizer:hover,
.review-resizer:active {
    background: rgba(198, 150, 83, 0.12);
    border-color: var(--accent);
}
.review-resizer:hover::after,
.review-resizer:active::after {
    background: repeating-linear-gradient(
        to bottom,
        var(--accent) 0px,
        var(--accent) 3px,
        transparent 3px,
        transparent 7px
    );
}

/* Vertical (stacked) layout toggle */
.review-split.split-vertical {
    flex-direction: column;
    height: calc(100vh - 130px);
}
.review-split.split-vertical .review-doc {
    flex: none !important;
    width: 100% !important;
    min-width: 0;
}
.review-split.split-vertical .review-resizer {
    width: 100%;
    height: 16px;
    cursor: row-resize;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.review-split.split-vertical .review-resizer::after {
    width: 40px;
    height: 3px;
    background: repeating-linear-gradient(
        to right,
        rgba(255,255,255,0.22) 0px,
        rgba(255,255,255,0.22) 3px,
        transparent 3px,
        transparent 7px
    );
}
.review-split.split-vertical .review-resizer:hover::after,
.review-split.split-vertical .review-resizer:active::after {
    background: repeating-linear-gradient(
        to right,
        var(--accent) 0px,
        var(--accent) 3px,
        transparent 3px,
        transparent 7px
    );
}
.review-split.split-vertical .review-form {
    flex: 1 1 0;
    min-height: 0;
    padding-left: 0;
}

.layout-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.layout-toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

@media (max-width: 1100px) {
    .review-split {
        flex-direction: column;
        height: auto;
    }
    .review-doc {
        flex: none !important;
        width: 100% !important;
        height: 45vh;
        min-height: 300px;
    }
    .review-resizer { display: none; }
    .review-form {
        overflow-y: visible;
        padding-right: 0;
    }
}

body:has(.review-split) .content-area {
    max-width: 100%;
    padding: 20px 24px;
}

.review-doc {
    flex: 0 0 44%;
    min-width: 320px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.doc-frame {
    width: 100%;
    flex: 1;
    border: none;
    background: #181818;
}

.doc-image-wrap {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12px;
    background: #181818;
}

.doc-image {
    max-width: 100%;
    border-radius: 4px;
}

.review-form {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-left: 16px;
    padding-right: 4px;
}

/* Form sections */
.form-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
}

.form-section-title {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
}

.field-grid .form-group { margin-bottom: 0; }

.field-grid input,
.field-grid select {
    font-size: 12px;
    padding: 6px 9px;
}

/* Totals */
.totals-row {
    display: flex;
    gap: 0;
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.total-cell {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    border-right: 1px solid var(--border);
    gap: 2px;
}

.total-cell:last-child { border-right: none; }
.total-cell-grand { background: var(--bg-elevated); }

.total-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    font-weight: 600;
}

.total-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Lines table */
.lines-table-wrap {
    overflow-x: auto;
    margin: 0 -2px;
}

.lines-table {
    font-size: 11.5px;
    width: auto;
    min-width: 860px;
}

.lines-table thead th {
    font-size: 10px;
    padding: 7px 8px;
    background: var(--bg-elevated);
}

.lines-table tbody td {
    padding: 5px 8px;
    vertical-align: middle;
}

.line-input {
    width: 100%;
    font-size: 11.5px;
    padding: 3px 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-primary);
    font-family: var(--font-sans);
}
.line-input:hover { border-color: var(--border); }
.line-input:focus { border-color: var(--accent-dim); background: var(--bg-elevated); box-shadow: none; outline: none; }

/* QB select */
.qb-select-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    position: relative;
}

.qb-select {
    font-size: 11px;
    padding: 3px 22px 3px 6px;
    border-radius: 4px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%235a5a72' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

/* Batch edit bar */
.batch-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--accent-glow);
    border: 1px solid rgba(198, 150, 83, 0.20);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.batch-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    margin-right: 4px;
}

.batch-qb-select {
    font-size: 12px;
    padding: 4px 28px 4px 8px;
    border-radius: var(--radius);
    min-width: 200px;
    flex: 1;
    max-width: 280px;
}

.source-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}

.source-sku { background: rgba(61,  214, 140, 0.12); color: var(--green); }
.source-po  { background: rgba(198, 150, 83,  0.12); color: var(--accent); }
.source-ai  { background: rgba(232, 197, 71,  0.10); color: var(--yellow); }

/* Confidence dot */
.conf-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin: 0 auto;
}
.conf-green  { background: var(--green); }
.conf-yellow { background: var(--yellow); }
.conf-red    { background: var(--red); }

/* Checkbox */
input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* =========================================================
   Intake cards (source monitors)
   ========================================================= */

.intake-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 28px;
}

.intake-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.intake-card-icon { color: var(--text-muted); flex-shrink: 0; }
.intake-card-body { flex: 1; }

.intake-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.intake-card-status {
    font-size: 11.5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-disconnected { color: var(--text-muted); }

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

/* =========================================================
   Search page
   ========================================================= */

.search-form { margin-bottom: 24px; }

.search-bar-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}

.search-main-input {
    flex: 1;
    font-size: 14px;
    padding: 9px 14px;
    border-radius: var(--radius);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-main-input:focus {
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.search-filters input,
.search-filters select {
    font-size: 12px;
    padding: 6px 10px;
    min-width: 130px;
}

.search-filters label { font-size: 10.5px; }

/* Search tabs */
.search-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.search-tab {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.12s, border-color 0.12s;
    cursor: pointer;
}
.search-tab:hover { color: var(--text-secondary); }
.search-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-count {
    font-size: 10px;
    font-weight: 700;
    background: var(--bg-elevated);
    color: var(--text-muted);
    border-radius: 99px;
    padding: 1px 6px;
}
.search-tab.active .tab-count {
    background: var(--accent-glow);
    color: var(--accent);
}

/* SharePoint notice */
.sp-notice {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.result-row-clickable:hover { background: var(--bg-hover); }

/* =========================================================
   Modals
   ========================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.60);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.modal-dialog {
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    box-shadow: 0 32px 80px rgba(0,0,0,.60);
    display: flex;
    flex-direction: column;
}

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

.modal-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-warn-box {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: rgba(232, 197, 71, .06);
    border: 1px solid rgba(232, 197, 71, .18);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.modal-warn-text {
    font-size: 12px;
    color: var(--yellow);
    line-height: 1.5;
}

/* COA inactive rows */
.opacity-50 { opacity: 0.45; }

/* =========================================================
   Sidebar extras
   ========================================================= */

.core-context {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    color: var(--text-muted);
    margin-top: 6px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #111111;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Theme toggle */
.theme-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.12s, background 0.12s;
}
.theme-toggle-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.theme-toggle-btn svg { width: 15px; height: 15px; }

/* =========================================================
   Light mode overrides
   ========================================================= */

[data-theme="light"] .main-content {
    background-image:
        linear-gradient(rgba(198,150,83,0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(198,150,83,0.07) 1px, transparent 1px);
    background-size: 28px 28px;
}

[data-theme="light"] .badge-green  { background: rgba(21, 128, 61,  0.09); }
[data-theme="light"] .badge-red    { background: rgba(185, 28, 28,  0.09); }
[data-theme="light"] .badge-yellow { background: rgba(146, 64,  14, 0.09); }
[data-theme="light"] .badge-orange { background: rgba(194, 65,  12, 0.09); }
[data-theme="light"] .badge-blue   { background: rgba(184, 146, 42, 0.10); }

[data-theme="light"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23909090' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

[data-theme="light"] .doc-frame,
[data-theme="light"] .doc-image-wrap { background: #e8e8e6; }

[data-theme="light"] .source-sku { background: rgba(21,  128, 61,  0.10); color: #15803d; }
[data-theme="light"] .source-po  { background: rgba(184, 146, 42,  0.10); color: #7a5a18; }
[data-theme="light"] .source-ai  { background: rgba(146, 64,  14,  0.10); color: #92400e; }

[data-theme="light"] .modal-overlay { background: rgba(0,0,0,.28); }

[data-theme="light"] .sidebar::after { opacity: 0.10; }

[data-theme="light"] .user-avatar,
[data-theme="light"] .os-user-avatar { color: #FFFFFF; }

[data-theme="light"] .card::before,
[data-theme="light"] .core-card::before { background: linear-gradient(135deg, rgba(0,0,0,0.01) 0%, transparent 55%); }

/* =========================================================
   Scrollbar
   ========================================================= */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =========================================================
   OS Dashboard
   ========================================================= */

.os-topbar {
    height: 52px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: var(--bg-surface);
    flex-shrink: 0;
}

.os-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.os-logo-mark {
    width: 32px;
    height: 30px;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.os-logo-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.os-logo-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.os-user {
    display: flex;
    align-items: center;
    gap: 9px;
}

.os-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #111111;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.os-user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.os-app-version {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: .04em;
    opacity: 0.6;
    font-family: var(--font-mono);
}

/* OS layout */
.os-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.os-content {
    flex: 1;
    overflow-y: auto;
    padding: 44px 36px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

/* Greeting */
.os-greeting { margin-bottom: 36px; }

.os-greeting-text {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.4px;
    line-height: 1.25;
}

.os-greeting-date {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Core grid */
.core-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 40px;
}

.core-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}

.core-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.018) 0%, transparent 55%);
    pointer-events: none;
}

a.core-card:hover {
    border-color: var(--accent-dim);
    background: var(--bg-elevated);
    box-shadow: 0 6px 24px rgba(0,0,0,.35);
}

a.core-card { border-top: 2px solid var(--accent); }

.core-card.inactive {
    opacity: 0.40;
    cursor: default;
    pointer-events: none;
}

.core-card-icon {
    color: var(--text-muted);
    width: 28px;
    height: 28px;
}

.core-card-name {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.core-card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    flex: 1;
}

/* Section label */
.os-section-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Stat tiles */
.stat-tiles {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.stat-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-tile-value {
    font-size: 26px;
    font-weight: 600;
    font-family: var(--font-mono);
    line-height: 1;
}

.stat-tile-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-tile-yellow .stat-tile-value { color: var(--yellow); }
.stat-tile-green  .stat-tile-value { color: var(--green); }
.stat-tile-muted  .stat-tile-value { color: var(--text-secondary); }

/* =========================================================
   Extraction Log Panel
   ========================================================= */

.ext-log-panel {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-surface);
    margin-bottom: 24px;
}
.ext-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.ext-log-header .ext-log-chevron {
    transition: transform 0.15s;
    color: var(--text-muted);
    flex-shrink: 0;
}
.ext-log-panel.collapsed .ext-log-header .ext-log-chevron { transform: rotate(-90deg); }
.ext-log-panel.collapsed .ext-log-body { display: none; }
.ext-log-body {
    max-height: 150px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ext-log-entry {
    display: flex;
    gap: 6px;
    font-size: 11.5px;
    line-height: 1.45;
    flex-wrap: wrap;
}
.ext-log-ts {
    color: var(--text-muted);
    font-family: var(--font-mono);
    flex-shrink: 0;
}
.ext-log-msg {
    color: var(--text-secondary);
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
}
.ext-log-msg.log-success { color: var(--green); }
.ext-log-msg.log-error   { color: var(--red); }
.ext-log-empty {
    font-size: 11.5px;
    color: var(--text-muted);
    padding: 4px 2px;
}
