/* ===== DESIGN TOKENS ===== */

/* --- Light Theme (default) --- */
:root {
    --bg: #F5F5F5;
    --bg-card: #FFFFFF;
    --bg-sidebar: #FFFFFF;
    --bg-secondary: #F0F0F0;
    --bg-accent: #E8E8EC;
    --fg: #1A1A1A;
    --fg-muted: #9CA3AF;
    --fg-secondary: #404040;
    --primary: #D97706;
    --primary-dim: #FEF3C7;
    --primary-fg: #FFFFFF;
    --green: #16A34A;
    --green-dim: #BBF7D0;
    --red: #DC2626;
    --red-dim: #FECACA;
    --cyan: #2563EB;
    --amber: #D97706;
    --border: #E0E0E0;
    --border-light: #D0D0D0;
    --radius: 6px;
    --radius-lg: 10px;
    --font: 'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    /* Severity colors */
    --sev-critical: #DC2626;
    --sev-critical-bg: rgba(220,38,38,0.08);
    --sev-high: #EA580C;
    --sev-high-bg: rgba(234,88,12,0.08);
    --sev-medium: #CA8A04;
    --sev-medium-bg: rgba(202,138,4,0.08);
    --sev-low: #16A34A;
    --sev-low-bg: rgba(22,163,74,0.08);
    --sev-none: #16A34A;
    --sev-none-bg: rgba(22,163,74,0.05);
    /* Lightbox */
    --lightbox-bg: rgba(0,0,0,0.7);
    /* Noise overlay opacity */
    --noise-opacity: 0.015;
    color-scheme: light;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
    --bg: #0C0C0F;
    --bg-card: #141419;
    --bg-sidebar: #111115;
    --bg-secondary: #1C1C24;
    --bg-accent: #1F1F2A;
    --fg: #D4D4D8;
    --fg-muted: #71717A;
    --fg-secondary: #A1A1AA;
    --primary: #D97706;
    --primary-dim: #92400E;
    --primary-fg: #0C0C0F;
    --green: #22C55E;
    --green-dim: #166534;
    --red: #EF4444;
    --red-dim: #991B1B;
    --cyan: #67E8F9;
    --amber: #D97706;
    --border: #27272E;
    --border-light: #32323A;
    --sev-critical: #EF4444;
    --sev-critical-bg: rgba(239,68,68,0.12);
    --sev-high: #F97316;
    --sev-high-bg: rgba(249,115,22,0.12);
    --sev-medium: #EAB308;
    --sev-medium-bg: rgba(234,179,8,0.12);
    --sev-low: #22C55E;
    --sev-low-bg: rgba(34,197,94,0.12);
    --sev-none: #22C55E;
    --sev-none-bg: rgba(34,197,94,0.08);
    --lightbox-bg: rgba(0,0,0,0.92);
    --noise-opacity: 0.02;
    color-scheme: dark;
}

/* ===== RESET & BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--fg);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Subtle noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    opacity: var(--noise-opacity, 0.015);
    pointer-events: none;
    z-index: 0;
}

body > * { position: relative; z-index: 1; }

/* ===== HEADER ===== */
header {
    background: var(--bg-sidebar);
    color: var(--fg);
    padding: 0 24px;
    height: 48px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
header h1 {
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.02em;
}
.brand-logo {
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    flex-shrink: 0;
    display: block;
}
.header-stats {
    display: flex;
    gap: 24px;
    align-items: center;
}
.header-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0px;
}
.header-stat .stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}
.header-stat .stat-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fg-muted);
    font-weight: 500;
}
.user-badge {
    font-size: 0.6rem;
    padding: 3px 10px;
    border-radius: 3px;
    background: var(--primary-dim);
    color: var(--primary);
    font-weight: 600;
    font-family: var(--font);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ===== APP LAYOUT ===== */
#app-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: calc(100vh - 48px);
}

/* ===== SIDEBAR ===== */
#sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100vh - 49px);
    position: sticky;
    top: 49px;
}
#sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg-muted);
    font-weight: 600;
}
#sidebar-filter {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.filter-chip {
    font-size: 0.6rem;
    padding: 3px 10px;
    border-radius: 3px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--fg-muted);
    cursor: pointer;
    font-weight: 600;
    font-family: var(--font);
    transition: all 150ms ease;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.filter-chip:hover {
    border-color: var(--border-light);
    color: var(--fg-secondary);
    background: var(--bg-secondary);
}
.filter-chip.active {
    background: var(--primary-dim);
    border-color: var(--primary);
    color: var(--primary);
}
.filter-chip.sev-critical { border-color: var(--border); }
.filter-chip.sev-critical.active { background: var(--sev-critical-bg); border-color: var(--sev-critical); color: var(--sev-critical); }
.filter-chip.sev-high { border-color: var(--border); }
.filter-chip.sev-high.active { background: var(--sev-high-bg); border-color: var(--sev-high); color: var(--sev-high); }
.filter-chip.sev-medium { border-color: var(--border); }
.filter-chip.sev-medium.active { background: var(--sev-medium-bg); border-color: var(--sev-medium); color: var(--sev-medium); }
.filter-chip.sev-low { border-color: var(--border); }
.filter-chip.sev-low.active { background: var(--sev-low-bg); border-color: var(--sev-low); color: var(--sev-low); }

/* Sidebar list */
#sidebar-list {
    overflow-y: auto;
    flex: 1;
}
#sidebar-list::-webkit-scrollbar { width: 4px; }
#sidebar-list::-webkit-scrollbar-track { background: transparent; }
#sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#sidebar-list::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.72rem;
    position: relative;
    transition: background 150ms ease;
    border-left: 3px solid transparent;
}
.sidebar-item:hover { background: var(--bg-secondary); }
.sidebar-item.active {
    background: var(--bg-accent);
    border-left-color: var(--primary);
}
.sidebar-item img {
    width: 56px;
    height: 38px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    opacity: 0.85;
}
.sidebar-item.active img { opacity: 1; }
.sidebar-label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    overflow: hidden;
    flex: 1;
}
.sidebar-name {
    font-size: 0.72rem;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}
.sidebar-meta {
    display: flex;
    gap: 6px;
    align-items: center;
}
.defect-count-badge {
    font-size: 0.55rem;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--primary);
    font-family: var(--font);
}
.defect-count-badge.zero {
    background: var(--sev-none-bg);
    color: var(--sev-none);
}

/* Severity pills */
.severity-pill {
    font-size: 0.5rem;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font);
    display: inline-block;
}
.severity-pill.critical { background: var(--sev-critical-bg); color: var(--sev-critical); }
.severity-pill.high { background: var(--sev-high-bg); color: var(--sev-high); }
.severity-pill.medium { background: var(--sev-medium-bg); color: var(--sev-medium); }
.severity-pill.low { background: var(--sev-low-bg); color: var(--sev-low); }
.severity-pill.none { background: var(--sev-none-bg); color: var(--sev-none); }

/* ===== MAIN CONTENT ===== */
#main-content {
    overflow-y: auto;
    height: calc(100vh - 48px);
}
#content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
}

/* Card base */
#image-panel, #attributes-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    position: relative;
}

/* Dark mode: amber glow line on cards */
[data-theme="dark"] #image-panel::before,
[data-theme="dark"] #attributes-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(217,119,6,0.3), transparent);
    border-radius: var(--radius) var(--radius) 0 0;
}

/* Dark mode: subtle amber hover on interactive rows */
[data-theme="dark"] .defect-card:hover { background: rgba(217,119,6,0.04); }
[data-theme="dark"] .tier2-det:hover { background: rgba(217,119,6,0.04); }
[data-theme="dark"] .sidebar-item:hover { background: rgba(217,119,6,0.04); }

/* ===== IMAGE PANEL ===== */
#image-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
#image-view-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}
.view-btn {
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: transparent;
    color: var(--fg-muted);
    font-size: 0.65rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 150ms;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.view-btn:hover {
    background: var(--bg-secondary);
    color: var(--fg-secondary);
}
.view-btn.active {
    background: var(--primary);
    color: var(--primary-fg);
    border-color: var(--primary);
}

#image-container {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    background: var(--bg);
    border: 1px solid var(--border);
}
#main-image {
    width: 100%;
    display: block;
    border-radius: var(--radius);
}

/* Bbox overlay */
#bbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
#bbox-overlay rect, #lightbox-bbox-overlay rect {
    fill: none;
    stroke-width: 3;
    pointer-events: visibleStroke;
}
#bbox-overlay text, #lightbox-bbox-overlay text {
    font-family: var(--font);
    font-size: 14px;
    font-weight: 700;
}
#bbox-overlay .bbox-label-bg, #lightbox-bbox-overlay .bbox-label-bg { opacity: 0.92; }
#bbox-overlay .bbox-confirmed rect, #lightbox-bbox-overlay .bbox-confirmed rect { stroke: var(--green); stroke-width: 3; }
#bbox-overlay .bbox-confirmed .bbox-label-bg, #lightbox-bbox-overlay .bbox-confirmed .bbox-label-bg { fill: var(--green); }
#bbox-overlay .bbox-confirmed text, #lightbox-bbox-overlay .bbox-confirmed text { fill: #000; }
#bbox-overlay .bbox-rejected rect, #lightbox-bbox-overlay .bbox-rejected rect { stroke: var(--amber); stroke-width: 3; }
#bbox-overlay .bbox-rejected .bbox-label-bg, #lightbox-bbox-overlay .bbox-rejected .bbox-label-bg { fill: var(--amber); }
#bbox-overlay .bbox-rejected text, #lightbox-bbox-overlay .bbox-rejected text { fill: #000; }
#bbox-overlay .bbox-unverified rect, #lightbox-bbox-overlay .bbox-unverified rect { stroke: var(--fg-muted); stroke-width: 2; }
#bbox-overlay .bbox-unverified .bbox-label-bg, #lightbox-bbox-overlay .bbox-unverified .bbox-label-bg { fill: var(--fg-muted); }
#bbox-overlay .bbox-unverified text, #lightbox-bbox-overlay .bbox-unverified text { fill: #fff; }
#bbox-overlay .bbox-highlight rect { stroke-width: 5; }

/* Bbox legend */
#bbox-legend, #lightbox-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 8px 2px 2px;
    font-size: 0.65rem;
}
#lightbox-legend {
    justify-content: center;
    padding: 10px 20px;
}
.bbox-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 3px;
    font-weight: 600;
    cursor: default;
    transition: opacity 150ms;
    border: 1px solid var(--border);
    font-family: var(--font);
}
.bbox-legend-item:hover { opacity: 0.85; }
.bbox-legend-item.bbox-confirmed {
    background: rgba(34,197,94,0.15);
    color: var(--green);
    border-color: var(--green-dim);
}
.bbox-legend-item.bbox-rejected {
    background: rgba(217,119,6,0.15);
    color: var(--amber);
    border-color: var(--primary-dim);
}
.bbox-legend-item.bbox-unverified {
    background: var(--bg-secondary);
    color: var(--fg-muted);
}
.bbox-legend-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.bbox-confirmed .bbox-legend-dot { background: var(--green); }
.bbox-rejected .bbox-legend-dot { background: var(--amber); }
.bbox-unverified .bbox-legend-dot { background: var(--fg-muted); }
.bbox-legend-status {
    font-size: 0.5rem;
    text-transform: uppercase;
    opacity: 0.6;
    margin-left: 2px;
    letter-spacing: 0.04em;
}

/* ===== ATTRIBUTES PANEL ===== */
#attributes-panel {
    max-height: calc(100vh - 48px - 32px);
    overflow-y: auto;
}
#attributes-panel::-webkit-scrollbar { width: 4px; }
#attributes-panel::-webkit-scrollbar-track { background: transparent; }
#attributes-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Crop detail panel in lightbox */
.crop-detail {
    background: var(--bg-card);
    color: var(--fg);
    border-radius: var(--radius);
    padding: 12px 20px;
    margin: 10px auto;
    max-width: 700px;
    text-align: left;
    border: 1px solid var(--border);
}
.crop-detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.crop-detail-type { font-weight: 700; font-size: 0.85rem; }
.crop-detail-meta { font-size: 0.68rem; color: var(--fg-muted); margin-top: 4px; }
.crop-detail-reasoning {
    font-size: 0.72rem;
    color: var(--fg-secondary);
    margin-top: 6px;
    line-height: 1.5;
}

/* ===== DEFECT SUMMARY ===== */
#defect-summary {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
#defect-summary h3 {
    font-size: 0.8rem;
    margin-bottom: 6px;
    color: var(--fg);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.severity-distribution {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.sev-chip {
    font-size: 0.6rem;
    padding: 3px 10px;
    border-radius: 3px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sev-chip.critical { background: var(--sev-critical-bg); color: var(--sev-critical); }
.sev-chip.high { background: var(--sev-high-bg); color: var(--sev-high); }
.sev-chip.medium { background: var(--sev-medium-bg); color: var(--sev-medium); }
.sev-chip.low { background: var(--sev-low-bg); color: var(--sev-low); }

/* ===== DEFECT CARDS ===== */
.defect-card {
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    transition: background 150ms ease;
    background: var(--bg-secondary);
}
.defect-card:hover { background: var(--bg-accent); }
.defect-card.sev-critical { border-left-color: var(--sev-critical); }
.defect-card.sev-high { border-left-color: var(--sev-high); }
.defect-card.sev-medium { border-left-color: var(--sev-medium); }
.defect-card.sev-low { border-left-color: var(--sev-low); }
.defect-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.defect-card-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--fg);
}
.defect-card-badges {
    display: flex;
    gap: 6px;
    align-items: center;
}
.source-badge {
    font-size: 0.5rem;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--bg-accent);
    color: var(--primary);
    border: 1px solid var(--primary-dim);
    font-family: var(--font);
}
.confidence-badge {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--fg-muted);
    font-family: var(--font);
}
.defect-card-desc {
    font-size: 0.72rem;
    color: var(--fg-secondary);
    line-height: 1.5;
    margin-top: 4px;
}

/* ===== TIER SECTIONS ===== */
.tier-section {
    border-top: 1px solid var(--border);
    margin-top: 12px;
}
.tier-section summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    padding: 10px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    color: var(--fg-secondary);
    border-left: 3px solid var(--primary);
    transition: color 150ms;
}
.tier-section summary:hover { color: var(--fg); }
.tier-section summary::-webkit-details-marker { display: none; }
.tier-section summary::after {
    content: "+";
    font-size: 0.85rem;
    color: var(--fg-muted);
    margin-left: 12px;
    font-weight: 400;
}
.tier-section[open] summary::after { content: "\2212"; }
.tier-section-body { padding: 8px 0; }

.tier-item {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--fg-secondary);
}
.tier-item:last-child { border-bottom: none; }
.tier-item strong { font-weight: 600; color: var(--fg); }

/* Tier 2 detection hover */
.tier2-det {
    cursor: pointer;
    transition: background 150ms ease;
    border-radius: 3px;
}
.tier2-det:hover { background: var(--bg-accent); }

/* ===== VERIFICATION CARDS ===== */
.verification-card {
    display: flex;
    gap: 10px;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
}
.verification-card img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    cursor: pointer;
    border: 1px solid var(--border);
}
.verification-info { flex: 1; min-width: 0; }
.verdict {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 3px;
    display: inline-block;
    margin-bottom: 4px;
    font-family: var(--font);
    letter-spacing: 0.06em;
}
.verdict.confirmed {
    background: rgba(34,197,94,0.15);
    color: var(--green);
    border: 1px solid var(--green-dim);
}
.verdict.rejected {
    background: rgba(239,68,68,0.12);
    color: var(--red);
    border: 1px solid var(--red-dim);
}
.verdict.error {
    background: rgba(234,179,8,0.12);
    color: var(--amber);
    border: 1px solid var(--primary-dim);
}
.verification-reasoning {
    font-size: 0.68rem;
    color: var(--fg-muted);
    line-height: 1.5;
    margin-top: 4px;
}

/* ===== EVENT JSON ===== */
.event-json {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.7rem;
    color: var(--fg-secondary);
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    font-family: var(--font);
}
.event-json::-webkit-scrollbar { width: 4px; height: 4px; }
.event-json::-webkit-scrollbar-track { background: transparent; }
.event-json::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== EMPTY STATE ===== */
.empty-state {
    color: var(--fg-muted);
    padding: 40px;
    text-align: center;
    font-size: 0.85rem;
}

/* ===== LIGHTBOX ===== */
#lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--lightbox-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    cursor: pointer;
    overflow: auto;
    padding: 40px;
    text-align: center;
}
#lightbox.active { display: block; animation: fadeIn 200ms ease; padding-bottom: 80px; }
#lightbox-container {
    position: relative;
    display: inline-block;
    text-align: left;
}
#lightbox-container img {
    display: block;
    max-width: 85vw;
    max-height: 85vh;
    border-radius: var(--radius);
    cursor: zoom-in;
    border: 1px solid var(--border);
}
#lightbox-container.zoomed img {
    width: 250vw;
    max-width: none;
    max-height: none;
    height: auto;
    cursor: zoom-out;
}
#lightbox.panning #lightbox-container.zoomed img { cursor: grabbing; }
#lightbox-bbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
#lightbox-close {
    position: fixed;
    top: 16px;
    right: 24px;
    color: var(--fg-muted);
    font-size: 2rem;
    cursor: pointer;
    z-index: 1001;
    line-height: 1;
    transition: color 150ms;
}
#lightbox-close:hover { color: var(--fg); }
#lightbox-hint {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--fg-muted);
    font-size: 0.72rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: var(--radius);
    font-family: var(--font);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== GLOSSARY BUTTON ===== */
.glossary-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 5px 14px;
    font-size: 0.68rem;
    font-weight: 600;
    font-family: var(--font);
    color: var(--fg-muted);
    cursor: pointer;
    transition: all 150ms ease;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.glossary-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
    color: var(--primary);
}
.glossary-btn-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    background: var(--primary);
    color: var(--primary-fg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ===== GLOSSARY MODAL ===== */
#glossary-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 24px;
}
#glossary-modal.active { display: flex; animation: fadeIn 200ms ease; }
.glossary-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 680px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 0;
}
.glossary-header {
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 1;
}
.glossary-header h2 {
    font-size: 0.9rem;
    color: var(--fg);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.glossary-close {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    border-radius: var(--radius);
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--fg-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 150ms ease;
}
.glossary-close:hover {
    background: var(--bg-accent);
    color: var(--fg);
    border-color: var(--border-light);
}
.glossary-body { padding: 16px 24px 24px; }
.glossary-section { margin-bottom: 20px; }
.glossary-section:last-child { margin-bottom: 0; }
.glossary-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.glossary-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: var(--radius);
    transition: background 150ms ease;
}
.glossary-item:hover { background: var(--bg-secondary); }
.glossary-term {
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 90px;
    flex-shrink: 0;
    color: var(--fg);
}
.glossary-def {
    font-size: 0.72rem;
    color: var(--fg-muted);
    line-height: 1.55;
    font-family: var(--font-sans);
}
.glossary-sev-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
}
.glossary-sev-dot.critical { background: var(--sev-critical); }
.glossary-sev-dot.high { background: var(--sev-high); }
.glossary-sev-dot.medium { background: var(--sev-medium); }
.glossary-sev-dot.low { background: var(--sev-low); }
.glossary-sev-dot.clean { background: var(--sev-none); }

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 5px 12px;
    font-size: 0.6rem;
    font-weight: 600;
    font-family: var(--font);
    color: var(--fg-muted);
    cursor: pointer;
    transition: all 150ms ease;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}
.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-secondary);
}
.theme-toggle-icon {
    font-size: 0.8rem;
    line-height: 1;
}

/* ===== LOGOUT BUTTON ===== */
.logout-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 5px 12px;
    font-size: 0.6rem;
    font-weight: 600;
    font-family: var(--font);
    color: var(--fg-muted);
    cursor: pointer;
    transition: all 150ms ease;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
    text-decoration: none;
}
.logout-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-secondary);
}

/* ===== MOBILE NAV (<=900px) ===== */
#mobile-nav { display: none; }

@media (min-width: 901px) {
    #mobile-nav { display: none; }
    #image-counter { display: none; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    #app-layout { grid-template-columns: 1fr; }
    #sidebar { display: none !important; }
    #content { grid-template-columns: 1fr; }
    #main-content { padding-bottom: 88px; }
    .header-stats { gap: 12px; }
    .header-stat .stat-value { font-size: 0.85rem; }
    .filter-chip { padding: 6px 12px; }
    #lightbox-close { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; }
    #lightbox { padding: 16px; }
    #lightbox.active { padding-bottom: 40px; }
    #lightbox-container img { max-width: 95vw; }

    /* Mobile nav bar */
    #mobile-nav {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 500;
        background: var(--bg-sidebar);
        border-top: 1px solid var(--border);
        backdrop-filter: blur(12px);
    }

    /* Filter row (collapsible) */
    #mobile-filter-row {
        padding: 8px 12px;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        border-bottom: 1px solid var(--border);
        transition: max-height 200ms ease, opacity 200ms ease, padding 200ms ease;
        max-height: 120px;
        overflow: hidden;
    }
    #mobile-filter-row.mobile-filter-hidden {
        max-height: 0;
        padding: 0 12px;
        opacity: 0;
        border-bottom: none;
    }

    /* Bottom bar */
    #mobile-nav-bar {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 6px 10px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
        height: 72px;
    }

    #mobile-filter-toggle {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: transparent;
        color: var(--fg-muted);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 150ms;
    }
    #mobile-filter-toggle.active {
        background: var(--primary-dim);
        border-color: var(--primary);
        color: var(--primary);
    }

    /* Thumbnail strip */
    #mobile-thumbstrip {
        flex: 1;
        display: flex;
        gap: 6px;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 4px 0;
    }
    #mobile-thumbstrip::-webkit-scrollbar { display: none; }

    .mobile-thumb {
        width: 52px;
        height: 52px;
        flex-shrink: 0;
        scroll-snap-align: center;
        border-radius: var(--radius);
        border: 2px solid var(--border);
        overflow: hidden;
        cursor: pointer;
        transition: border-color 150ms, transform 150ms;
        position: relative;
    }
    .mobile-thumb img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }
    .mobile-thumb.active {
        border-color: var(--primary);
        transform: scale(1.08);
        box-shadow: 0 0 0 2px var(--primary-dim);
    }
    .mobile-thumb .thumb-sev {
        position: absolute;
        bottom: 2px;
        right: 2px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        border: 1.5px solid var(--bg-sidebar);
    }
    .thumb-sev.critical { background: var(--sev-critical); }
    .thumb-sev.high { background: var(--sev-high); }
    .thumb-sev.medium { background: var(--sev-medium); }
    .thumb-sev.low { background: var(--sev-low); }
    .thumb-sev.none { background: var(--sev-none); }

    /* Counter pill */
    #mobile-counter {
        flex-shrink: 0;
        font-size: 0.6rem;
        font-weight: 700;
        font-family: var(--font);
        color: var(--fg-muted);
        background: var(--bg-secondary);
        padding: 4px 10px;
        border-radius: 10px;
        letter-spacing: 0.04em;
        white-space: nowrap;
    }

    /* Image counter overlay */
    #image-counter {
        display: block;
        position: absolute;
        top: 28px;
        right: 8px;
        font-size: 0.6rem;
        font-weight: 700;
        font-family: var(--font);
        color: var(--fg);
        background: var(--bg-card);
        border: 1px solid var(--border);
        padding: 3px 10px;
        border-radius: 10px;
        z-index: 10;
        opacity: 0.85;
    }
}

/* Hide mouse-centric hint on touch devices */
@media (hover: none) and (pointer: coarse) {
    #lightbox-hint { display: none; }
}

/* ===== RESPONSIVE: 600px (phone) ===== */
@media (max-width: 600px) {
    header h1 span { display: none; }
    header { padding: 0 12px; }
    .glossary-btn { padding: 5px 8px; }
    .glossary-btn-text { display: none; }
    .theme-toggle { padding: 5px 8px; }
    #theme-label { display: none; }
    .logout-btn { padding: 5px 8px; font-size: 0.55rem; }
    .user-badge { display: none; }
    .header-stats { gap: 8px; }
    .header-stat .stat-value { font-size: 0.78rem; }
    .header-stat .stat-label { font-size: 0.48rem; }
    #glossary-modal { padding: 12px; }
    .glossary-content { max-height: 92vh; }
    .glossary-body { padding: 12px 16px 16px; }
    .glossary-header { padding: 14px 16px 10px; }
    .glossary-item { flex-direction: column; gap: 4px; padding: 6px 8px; }
    .glossary-term { min-width: unset; }
}
@media (max-width: 380px) {
    .header-stats { display: none; }
}

/* ===== LIGHT THEME ADJUSTMENTS ===== */
:root .sidebar-item img {
    opacity: 1;
}
:root .bbox-legend-item.bbox-confirmed {
    background: rgba(22,163,74,0.1);
    color: var(--green);
    border-color: rgba(22,163,74,0.3);
}
:root .bbox-legend-item.bbox-rejected {
    background: rgba(217,119,6,0.1);
    color: var(--amber);
    border-color: rgba(217,119,6,0.3);
}
:root .verdict.confirmed {
    background: rgba(22,163,74,0.1);
    border: 1px solid rgba(22,163,74,0.3);
}
:root .verdict.rejected {
    background: rgba(220,38,38,0.08);
    border: 1px solid rgba(220,38,38,0.2);
}
:root .verdict.error {
    background: rgba(217,119,6,0.08);
    border: 1px solid rgba(217,119,6,0.2);
}
:root #image-panel, :root #attributes-panel {
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
}
:root .glossary-content {
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
@media (max-width: 900px) {
    :root #mobile-nav {
        box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
    }
}
