/* ============================================
   Fraud-174 Review — blind gold-eval annotation
   Dark theme, matches DAT Workspace design language
   (adapted from bloodgas-service viewer)
   ============================================ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-input: #2a2e3f;
    --border: #2e3348;
    --text-primary: #f5f6fa;
    --text-secondary: #cdd1e0;
    --text-muted: #a0a4b8;
    --accent: #6c8cff;
    --accent-hover: #8ba4ff;
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --gold: #fbbf24;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);

    --header-height: 52px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ---------- Header ---------- */
.header {
    background: rgba(15, 17, 23, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(108, 140, 255, 0.1);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 100;
}

.header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.header__back:hover { background: rgba(108, 140, 255, 0.15); color: var(--text-primary); }
.header__back svg { width: 20px; height: 20px; }

.header__title {
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--gold) 0%, hsla(40, 90%, 60%, 1) 40%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.header__group { display: flex; align-items: center; gap: 8px; }
.header__group--grow { flex: 1; min-width: 220px; }
.header__label { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }

.header__input,
.header__select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.header__select { min-width: 130px; cursor: pointer; }
.header__select--case { flex: 1; min-width: 0; max-width: 520px; }
.header__input { width: 130px; }

.header__input:focus,
.header__select:focus { outline: none; border-color: var(--accent); }

.header__nav { display: flex; gap: 4px; margin-left: auto; }

/* ---------- Buttons ---------- */
.btn {
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.2s, opacity 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

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

.btn--primary {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-secondary);
    border: 1px solid rgba(108, 140, 255, 0.2);
}
.btn--primary:hover:not(:disabled) { background: rgba(108, 140, 255, 0.25); color: var(--text-primary); }

.btn--success {
    background: rgba(74, 222, 128, 0.2);
    color: var(--green);
    border: 1px solid rgba(74, 222, 128, 0.25);
}
.btn--success:hover:not(:disabled) { background: rgba(74, 222, 128, 0.3); }

.btn__icon { font-size: 1rem; }

/* ---------- Main Layout ---------- */
.main { display: flex; height: calc(100vh - var(--header-height)); }

.panel { display: flex; flex-direction: column; overflow: hidden; }

.panel__header {
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.panel__title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.panel__progress {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    white-space: nowrap;
}
.panel__progress--done { color: var(--green); border-color: rgba(74, 222, 128, 0.3); }

.panel__placeholder {
    flex: 1;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 10px;
    text-align: center;
    padding: 20px;
}
.panel__placeholder.is-visible { display: flex; }
.panel__placeholder small { opacity: 0.7; }
.panel__icon { width: 48px; height: 48px; opacity: 0.3; }

.panel__loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 40px;
    color: var(--text-muted);
}
.panel__loading.is-visible { display: flex; }

.panel__iframe { display: none; flex: 1; border: none; background: #111318; }
.panel__iframe.is-visible { display: block; }

/* ---------- PDF Panel ---------- */
.panel--pdf { flex: 1; min-width: 42%; background: #111318; }

/* ---------- Data Panel ---------- */
.panel--data {
    flex: 1;
    min-width: 58%;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
}

/* ---------- Auto-save status ---------- */
.save-status {
    font-size: 0.78rem;
    white-space: nowrap;
    min-width: 70px;
    text-align: right;
}
.save-status--saving { color: var(--text-muted); }
.save-status--saved { color: var(--green); }
.save-status--pending { color: var(--text-muted); opacity: 0.8; }
.save-status--error { color: var(--red); }

/* ---------- Status Messages ---------- */
.status { padding: 8px 16px; font-size: 0.85rem; display: none; border-bottom: 1px solid transparent; }
.status.is-visible { display: block; }
.status--success { background: rgba(74, 222, 128, 0.1); color: var(--green); border-color: rgba(74, 222, 128, 0.2); }
.status--error { background: rgba(248, 113, 113, 0.1); color: var(--red); border-color: rgba(248, 113, 113, 0.2); }

/* ---------- Worksheet (two sections: case-level + per-defendant) ---------- */
.table-container { flex: 1; overflow: auto; }

.worksheet { display: none; padding: 0 0 60px; }
.worksheet.is-visible { display: block; }

.w-section { margin-bottom: 8px; }
.w-section__title {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 10px 12px 6px;
    border-bottom: 1px solid var(--border);
}

.w-table { border-collapse: collapse; font-size: 0.85rem; width: 100%; }
.w-table th,
.w-table td {
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    vertical-align: top;
}
.w-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Field-name column — sticky left */
.w-th-field, .w-td-field {
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-secondary);
    position: sticky;
    left: 0;
    z-index: 5;
    width: 210px;
    min-width: 210px;
    max-width: 210px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.w-th-field { z-index: 15; }
.w-td-field { font-weight: 500; color: var(--text-secondary); font-size: 0.8rem; }

.w-table tbody tr:hover td { background: rgba(108, 140, 255, 0.04); }
.w-table tbody tr:hover td.w-td-field { background: var(--bg-card); }

/* Group separator rows */
.w-group td {
    background: var(--bg-card);
    color: var(--gold);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 5px 12px;
    position: sticky;
    left: 0;
}

/* Value + source stacked in one cell */
.w-cell { min-width: 170px; }
.w-cell input, .w-cell select { display: block; width: 100%; }

.w-val, .w-src, .w-notes {
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    font-family: inherit;
    background: transparent;
    color: var(--text-primary);
    transition: border-color 0.15s, background 0.15s;
}
.w-val { font-size: 0.85rem; font-weight: 500; color-scheme: dark; }
/* Constrained value controls (dropdowns + date picker) */
select.w-val { cursor: pointer; appearance: none; -webkit-appearance: none; padding-right: 18px;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: right 7px center, right 3px center; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
select.w-val:hover, select.w-val:focus { background-color: var(--bg-input); }
input[type="date"].w-val { min-width: 130px; }
.w-src {
    margin-top: 3px;
    font-size: 0.72rem;
    font-style: italic;
    color: var(--text-muted);
    border-color: rgba(46, 51, 72, 0.6);
    border-style: dashed;
}
.w-src::placeholder { color: rgba(160, 164, 184, 0.5); font-style: italic; }
.w-val::placeholder { color: rgba(160, 164, 184, 0.45); font-weight: 400; }
.w-notes { font-size: 0.8rem; }
/* Fallback: every text input's placeholder is muted grey (filter box, defendant name, notes…) */
input::placeholder, textarea::placeholder { color: rgba(160, 164, 184, 0.45); opacity: 1; }
/* empty/placeholder option of a dropdown shows the example hint in muted */
select.w-val option[value=""] { color: var(--text-muted); }
/* grey the dropdown's "vd:" hint while nothing is selected */
select.w-val:has(option[value=""]:checked) { color: var(--text-muted); }

.w-val:hover, .w-src:hover, .w-notes:hover { border-color: var(--border); background: var(--bg-input); }
.w-val:focus, .w-src:focus, .w-notes:focus {
    outline: none;
    border-style: solid;
    border-color: var(--accent);
    background: var(--bg-input);
    box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.15);
}
.is-modified {
    background: rgba(250, 204, 21, 0.1) !important;
    border-color: rgba(250, 204, 21, 0.4) !important;
    color: var(--yellow) !important;
}

/* ---------- Spinner ---------- */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Defendant tabs + single-defendant form ---------- */
.def-head {
    position: sticky; top: 0; z-index: 18;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}
.def-head .w-section__title { position: static; }
.def-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 12px 10px; }
.def-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--bg-input); color: var(--text-secondary);
    font-size: 0.78rem; font-family: inherit; cursor: pointer;
    max-width: 220px; white-space: nowrap;
}
.def-tab:hover { border-color: var(--accent); color: var(--text-primary); }
.def-tab--active { border-color: var(--accent); background: rgba(108, 140, 255, 0.18); color: var(--text-primary); }
.def-tab--done { border-color: rgba(74, 222, 128, 0.4); }
.def-tab__name { overflow: hidden; text-overflow: ellipsis; }
.def-tab__count { color: var(--text-muted); font-size: 0.68rem; }
.def-tab--done .def-tab__count { color: var(--green); }
.def-add {
    padding: 4px 12px; border: 1px dashed var(--accent); border-radius: 999px;
    background: transparent; color: var(--accent); font-size: 0.78rem; font-weight: 600;
    font-family: inherit; cursor: pointer;
}
.def-add:hover { background: rgba(108, 140, 255, 0.12); }

.def-form__head { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 8px 12px; }
.def-name {
    flex: 1; min-width: 0;
    padding: 6px 10px; font-size: 0.9rem; font-weight: 600; font-family: inherit;
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.def-name:focus { outline: none; border-color: var(--accent); }
.def-remove {
    flex-shrink: 0; padding: 5px 10px; font-size: 0.75rem; font-family: inherit;
    background: transparent; color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.3); border-radius: 6px; cursor: pointer;
}
.def-remove:hover { background: rgba(248, 113, 113, 0.12); }
.def-empty { padding: 24px; text-align: center; color: var(--text-muted); }

/* ---------- Ghost button (field definitions) ---------- */
.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 5px 10px;
}
.btn--ghost:hover { background: rgba(108, 140, 255, 0.12); color: var(--text-primary); border-color: var(--accent); }

/* ---------- Modal (field definitions) ---------- */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(7, 9, 14, 0.7); backdrop-filter: blur(3px); }
.modal__panel {
    position: relative;
    width: min(900px, 94vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}
.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.modal__title { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.modal__close {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 1.6rem; line-height: 1;
    width: 32px; height: 32px; border-radius: 6px;
}
.modal__close:hover { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.modal__body { padding: 14px 18px 24px; overflow: auto; }

.defs-hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 12px; }
.defs-group {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
    color: var(--gold); margin: 16px 0 6px;
}
.defs-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.defs-table th {
    text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.4px;
    color: var(--text-muted); font-weight: 600; padding: 5px 10px; border-bottom: 1px solid var(--border);
}
.defs-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.defs-field { width: 230px; color: var(--text-primary); font-weight: 500; }
.defs-key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.68rem; color: var(--text-muted); margin-top: 2px; }
.defs-val { width: 130px; color: var(--accent); }
.defs-eg { font-size: 0.7rem; color: var(--text-muted); margin-top: 3px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.defs-desc { color: var(--text-secondary); line-height: 1.45; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .header { flex-wrap: wrap; height: auto; padding: 10px 15px; gap: 8px; }
    .header__group--grow { order: 10; flex-basis: 100%; }
    .header__select--case { max-width: none; }
    .main { flex-direction: column; height: calc(100vh - 120px); }
    .panel--pdf, .panel--data { min-width: 100%; height: 50%; }
}
@media (max-width: 640px) {
    .defs-field { width: auto; }
    .defs-val { width: auto; }
}
