:root {
  --navy: #1c2b4a;
  --navy-dark: #0f1a30;
  --navy-light: #2c4270;
  --gold: #b8902e;
  --gold-light: #d4ab4a;
  --bg: #eef1f6;
  --card: #ffffff;
  --border: #e0e4ec;
  --text: #1c2333;
  --muted: #6b7280;
  --danger: #b3261e;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 55, 0.06), 0 1px 3px rgba(20, 30, 55, 0.08);
  --shadow-md: 0 4px 10px rgba(20, 30, 55, 0.08), 0 2px 4px rgba(20, 30, 55, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 26, 48, 0.18), 0 4px 12px rgba(15, 26, 48, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(1100px 500px at 12% -8%, rgba(28, 43, 74, 0.07), transparent 60%),
    radial-gradient(900px 460px at 100% 0%, rgba(184, 144, 46, 0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.topbar {
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  box-shadow: var(--shadow-md);
  border-bottom: 3px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.15rem; letter-spacing: 0.01em; }
.brand-logo { height: 42px; width: auto; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35)); }
.auth-logo { display: block; height: 100px; width: auto; margin: 0 auto 16px; filter: drop-shadow(0 4px 10px rgba(28, 43, 74, 0.25)); }

.userbox { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.userbox.hidden { display: none; }
.userbox .btn-ghost {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.45);
}
.userbox .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.7);
}

#app { max-width: 980px; margin: 0 auto; padding: 28px 20px 90px; }

.view.hidden { display: none; }

#authView {
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  margin-top: -28px;
  padding: 64px 20px 90px;
  min-height: calc(100vh - 68px);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1100px 620px at 18% -8%, rgba(212, 171, 74, 0.22), transparent 55%),
    radial-gradient(900px 520px at 100% 100%, rgba(44, 66, 112, 0.5), transparent 55%),
    linear-gradient(165deg, var(--navy) 0%, var(--navy-dark) 60%, #0a1428 100%);
}
#authView.hidden { display: none; }
#authView .auth-card { margin: 0; }

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 9px 17px;
  font-size: 0.92rem;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-primary {
  background: linear-gradient(135deg, var(--navy-light), var(--navy));
  color: white;
  box-shadow: 0 2px 6px rgba(28, 43, 74, 0.35);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--navy), var(--navy-dark)); box-shadow: 0 4px 12px rgba(28, 43, 74, 0.4); transform: translateY(-1px); }
.btn-primary:disabled { background: #9aa4b5; box-shadow: none; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--navy); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eceff3; border-color: #c7cedb; transform: translateY(-1px); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid #e3b5b2; }
.btn-danger:hover { background: #fbeceb; border-color: var(--danger); transform: translateY(-1px); }

.auth-card {
  max-width: 420px;
  margin: 56px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--navy), var(--gold), var(--navy));
}

.tabs { display: flex; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-family: inherit;
  transition: color 0.15s ease;
}
.tab:hover { color: var(--navy); }
.tab.active { color: var(--navy); border-bottom-color: var(--gold); }

.tab-panel { display: none; flex-direction: column; gap: 4px; }
.tab-panel.active { display: flex; }

form label { font-size: 0.82rem; font-weight: 700; color: var(--muted); margin-top: 10px; display: block; }
form input, form select, form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  margin-top: 4px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 144, 46, 0.18);
}
form textarea { resize: vertical; }
form button { margin-top: 18px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 144, 46, 0.18);
}

.error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: 0.82rem; margin: 4px 0 0; }

.stats-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
}
.stats-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stats-panel-head h2 { margin: 0; font-size: 1.02rem; color: var(--navy); font-weight: 800; letter-spacing: 0.01em; }
.live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #2a6b45;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2a9d5c;
  box-shadow: 0 0 0 0 rgba(42, 157, 92, 0.6);
  animation: live-pulse 1.8s infinite;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(42, 157, 92, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(42, 157, 92, 0); }
  100% { box-shadow: 0 0 0 0 rgba(42, 157, 92, 0); }
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
.stat-card {
  border: 1px solid var(--border);
  border-top: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
  text-align: center;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
  user-select: none;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card.active {
  box-shadow: 0 0 0 2px var(--navy), var(--shadow-md);
}
.stat-card .num { font-size: 1.65rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat-card .lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 3px; font-weight: 600; }
.stat-card.total { background: linear-gradient(160deg, #eef1f6, #e4e9f2); border-top-color: var(--navy); }
.stat-card.open { border-top-color: #2a9d5c; }
.stat-card.open .num { color: #2a6b45; }
.stat-card.pending { border-top-color: #d99a1c; }
.stat-card.pending .num { color: #92660c; }
.stat-card.ready { border-top-color: #7c4dc4; }
.stat-card.ready .num { color: #5b2fa0; }
.stat-card.filed { border-top-color: #2f6fd6; }
.stat-card.filed .num { color: #1c4fa0; }
.stat-card.rejected { border-top-color: var(--danger); }
.stat-card.rejected .num { color: var(--danger); }

.officer-stats { margin-top: 18px; }
.officer-stats h3 { font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 10px; font-weight: 700; }
.officer-stats table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
.officer-stats th, .officer-stats td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.officer-stats thead th { color: var(--navy); font-weight: 700; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 2px solid var(--border); }
.officer-stats tbody tr:nth-child(odd) { background: #f8f9fc; }
.officer-stats tbody tr:hover { background: #f0f3f9; }
.officer-stats td.num-cell { text-align: center; font-variant-numeric: tabular-nums; }
.officer-cell { display: flex; align-items: center; gap: 8px; }
.officer-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-light), var(--navy));
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.toolbar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

#needsAttentionBtn.has-attention { border-color: var(--danger); color: var(--danger); }
#needsAttentionBtn.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.attention-count {
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 4px;
}
#needsAttentionBtn.active .attention-count { background: #fff; color: var(--danger); }

.case-list { display: flex; flex-direction: column; gap: 10px; }
.case-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.case-card:hover { border-color: var(--gold); border-left-color: var(--gold); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.case-card .cn { font-weight: 700; color: var(--navy); font-size: 1.02rem; }
.status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 4px;
}
.status-open { background: #e6f0ea; color: #2a6b45; }
.status-pending { background: #fdf1d8; color: #92660c; }
.status-filed { background: #e3ecfb; color: #1c4fa0; }
.status-rejected { background: #fbeceb; color: var(--danger); }
.status-ready { background: #ece3fb; color: #5b2fa0; }
.case-card .sn { color: var(--muted); font-size: 0.9rem; }
.case-card .charges-preview { color: #92660c; font-style: italic; margin-top: 2px; }
.case-card .pending-preview { color: #92660c; margin-top: 2px; font-weight: 600; }

.case-group { display: flex; flex-direction: column; gap: 10px; }
.case-group + .case-group { margin-top: 24px; }
.case-group-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--navy);
  margin: 0;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--gold);
}
.case-group-count {
  background: var(--navy);
  color: #fff;
  border-radius: 10px;
  padding: 1px 9px;
  font-size: 0.75rem;
  font-weight: 700;
}
.case-card .count { font-size: 0.8rem; color: var(--muted); }
.empty {
  color: var(--muted);
  text-align: center;
  padding: 44px 20px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

.auth-heading { text-align: center; color: var(--navy); font-weight: 800; font-size: 1.2rem; margin: 0 0 18px; }
.auth-footnote { text-align: center; margin-top: 16px; }

.users-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.user-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
}
.user-row .user-name { font-weight: 700; color: var(--navy); font-size: 1.02rem; }
.user-row .user-sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.user-row .doc-actions { flex-shrink: 0; }
.user-row-inactive { border-left-color: var(--border); opacity: 0.65; }

.help-content { max-width: 760px; margin-top: 10px; }
.help-content h1 { margin-bottom: 4px; }
.help-content h2 {
  margin-top: 32px;
  margin-bottom: 8px;
  font-size: 1.08rem;
  color: var(--navy);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.help-content p { line-height: 1.55; color: var(--text); margin-bottom: 10px; }
.help-content p.hint { margin-top: 2px; }
.legend-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 18px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
}
.legend-item > span:first-child,
.legend-item > strong:first-child {
  flex-shrink: 0;
  min-width: 84px;
}
.legend-item span:last-child { color: var(--muted); font-size: 0.92rem; line-height: 1.45; }

.case-toprow { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.case-header {
  margin-bottom: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow-md);
}
.case-title-row { display: flex; align-items: center; gap: 12px; }
.case-header h1 { margin: 4px 0 2px; font-size: 1.45rem; color: var(--navy); font-weight: 800; }
.case-meta { color: var(--muted); font-size: 0.88rem; }

.case-info-edit {
  margin-top: 10px;
  padding: 14px;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.case-info-edit.hidden { display: none; }
.case-info-edit label { font-size: 0.78rem; font-weight: 700; color: var(--muted); display: block; margin-top: 8px; }
.case-info-edit input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
  font-family: inherit;
  font-size: 0.92rem;
}
.assign-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.88rem; }
.assign-row label { font-weight: 600; color: var(--muted); }
.assign-row select { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.assign-row .hidden { display: none; }

.charges-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 0.88rem; flex-wrap: wrap; }
.charges-row label { font-weight: 600; color: var(--muted); }
.charges-row input { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); flex: 1; min-width: 220px; }
.charges-list { display: flex; flex-wrap: wrap; gap: 6px; }
.charge-chip {
  background: #fdf1d8;
  color: #92660c;
  border: 1px solid #f0dba8;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}
.charges-empty { color: var(--muted); font-style: italic; }

.charges-editor {
  margin-top: 10px;
  padding: 14px;
  background: #fdfaf3;
  border: 1px solid #f0dba8;
  border-radius: var(--radius);
}
.charges-editor.hidden { display: none; }
.charges-add-row { display: flex; gap: 8px; margin-top: 10px; }
.charges-add-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.92rem;
}
.charge-chip.removable { display: inline-flex; align-items: center; gap: 6px; }
.chip-remove {
  background: none;
  border: none;
  color: #92660c;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  font-weight: 700;
}
.chip-remove:hover { color: var(--danger); }

.rejection-notice {
  background: #fbeceb;
  border: 1px solid #e3b5b2;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-top: 10px;
}
.rejection-notice.hidden { display: none; }

.pending-notice {
  background: #fdf1d8;
  border: 1px solid #ecd08f;
  color: #92660c;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-top: 10px;
}
.pending-notice.hidden { display: none; }

.ready-notice {
  background: #ece3fb;
  border: 1px solid #cdb8ee;
  color: #5b2fa0;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-top: 10px;
}
.ready-notice.hidden { display: none; }

.status-history-card {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 4px 14px 10px;
}
.status-history-card summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: 700;
  color: var(--navy);
  font-size: 0.88rem;
}
.status-history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.status-history-entry {
  border-left: 3px solid var(--border);
  padding: 4px 0 4px 10px;
}
.she-top { display: flex; align-items: center; gap: 10px; }
.she-date { color: var(--muted); font-size: 0.82rem; }
.she-detail { font-size: 0.85rem; margin-top: 3px; }
.she-by { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }

.ready-missing-list { display: flex; flex-direction: column; gap: 14px; margin: 16px 0; }
.ready-missing-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #fffcf3;
}
.ready-missing-item.resolved { background: #f4fbf7; border-color: #bfe0cd; }
.ready-missing-item .rm-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}
.ready-missing-item .rm-resolved-tag {
  color: #2a6b45;
  font-size: 0.8rem;
  font-weight: 700;
}
.ready-missing-item .rm-notes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.ready-missing-item textarea {
  width: 100%;
  resize: vertical;
  min-height: 54px;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-sizing: border-box;
}
.ready-missing-item .rm-add-row { display: flex; justify-content: flex-end; margin-top: 6px; }

.category-notes { margin: 8px 0 10px; display: flex; flex-direction: column; gap: 6px; }
.category-note {
  background: #f6f2fc;
  border: 1px solid #e0d3f5;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--text);
}
.category-note .cn-meta { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.category-note-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  margin: 4px 0 2px;
}

.admin-export-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.admin-export-row.hidden { display: none; }
.file-tools-row { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; }

.scan-intro h1 { color: var(--navy); font-size: 1.35rem; font-weight: 800; margin: 14px 0 4px; }

.scan-progress { margin: 16px 0; }
.scan-progress-bar {
  width: 100%;
  height: 8px;
  background: #e6e9ee;
  border-radius: 6px;
  overflow: hidden;
}
.scan-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--gold);
  transition: width 0.2s ease;
}
.scan-progress.hidden { display: none; }

.scan-results { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.scan-result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.scan-result-card h3 { margin: 0 0 6px; color: var(--navy); font-size: 1rem; }
.scan-result-card ul { margin: 6px 0 0; padding-left: 18px; font-size: 0.88rem; }
.scan-result-card.error { border-color: #e3b5b2; background: #fdf4f3; }

.upload-zone {
  border: 2px dashed #c3cbdb;
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: center;
  cursor: pointer;
  margin: 18px 0 28px;
  background: linear-gradient(160deg, #fbfcfe, #f2f4f9);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.upload-zone:hover { border-color: var(--gold); transform: translateY(-1px); }
.upload-zone.dragover { border-color: var(--gold); background: #fbf6ea; }
.upload-zone p { margin: 4px 0; }
.upload-zone strong { color: var(--navy); }

.category-sections { display: flex; flex-direction: column; gap: 14px; }
.category-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease;
}
.category-card:hover { box-shadow: var(--shadow-md); }
.category-sections .category-card:nth-child(1) { border-left-color: #1c2b4a; }
.category-sections .category-card:nth-child(2) { border-left-color: #2f6fd6; }
.category-sections .category-card:nth-child(3) { border-left-color: #0f8a8a; }
.category-sections .category-card:nth-child(4) { border-left-color: #b3261e; }
.category-sections .category-card:nth-child(5) { border-left-color: #6b4fa0; }
.category-sections .category-card:nth-child(6) { border-left-color: #4a5fc1; }
.category-sections .category-card:nth-child(7) { border-left-color: #a0651f; }
.category-sections .category-card:nth-child(8) { border-left-color: #2a9d5c; }
.category-sections .category-card:nth-child(9) { border-left-color: #d9720c; }
.category-sections .category-card:nth-child(10) { border-left-color: #546178; }
.category-sections .category-card:nth-child(11) { border-left-color: #8a2f4a; }

/* Missing/overdue states win the border-left tie-break by coming after the
   nth-child rules above (equal specificity, later source order wins). */
.category-sections .category-card.category-missing {
  border-left-color: #d9a91c;
  background: #fffcf3;
}
.category-sections .category-card.category-missing-overdue {
  border-left-color: var(--danger);
  background: #fdf3f2;
}
.missing-tag {
  background: #fdf1d8;
  color: #92660c;
  border-radius: 10px;
  padding: 1px 9px;
  font-size: 0.72rem;
  font-weight: 700;
}
.missing-tag.overdue { background: #fbeceb; color: var(--danger); }

.category-card summary {
  padding: 13px 16px;
  cursor: pointer;
  font-weight: 700;
  color: var(--navy);
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  transition: background 0.15s ease;
}
.category-card summary:hover { background: #f7f9fc; }
.category-card summary::-webkit-details-marker { display: none; }
.category-card summary .summary-right { display: flex; align-items: center; gap: 8px; }
.category-card summary .badge {
  background: #eef1f6;
  color: var(--muted);
  border-radius: 12px;
  padding: 1px 9px;
  font-size: 0.78rem;
  font-weight: 600;
}
.doc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.doc-row .doc-name { font-weight: 500; }
.doc-row .doc-sub { color: var(--muted); font-size: 0.78rem; }
.doc-row .doc-actions { display: flex; gap: 8px; }

.template-list { border: 1px solid var(--border); border-radius: var(--radius); margin-top: 14px; overflow: hidden; }
.template-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 0.92rem;
}
.template-row + .template-row { border-top: 1px solid var(--border); }
.template-row .template-name { font-weight: 600; color: var(--navy); }
.doc-row a { color: var(--navy); text-decoration: none; font-weight: 600; }
.doc-empty { padding: 12px 16px; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(12, 18, 34, 0.58);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: white;
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 92%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h2 { margin-top: 0; font-size: 1.15rem; color: var(--navy); font-weight: 800; }
.modal-wide { max-width: 560px; }

.preview-modal { max-width: 900px; width: 92%; height: 88vh; display: flex; flex-direction: column; }
.preview-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.preview-header h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-frame { flex: 1; width: 100%; border: 1px solid var(--border); border-radius: var(--radius); margin-top: 10px; }
.preview-frame.hidden { display: none; }
.preview-media { object-fit: contain; background: #14141a; }
.modal .filename { font-weight: 600; word-break: break-all; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal label { font-size: 0.82rem; font-weight: 700; color: var(--muted); margin-top: 10px; display: block; }
.modal input[type="text"], .modal select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  margin-top: 4px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.rename-input-row { display: flex; align-items: center; gap: 8px; }
.rename-input-row input { flex: 1; }
.rename-ext { color: var(--muted); font-weight: 600; margin-top: 4px; }
.guess {
  background: #eef6ee;
  border: 1px solid #c9e3c9;
  color: #2a5c2a;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.85rem;
  margin: 8px 0;
}
.guess.hidden { display: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--navy-light), var(--navy-dark));
  color: white;
  padding: 11px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
.toast.hidden { display: none; }
.toast.error { background: var(--danger); }

@media (max-width: 600px) {
  .case-card { flex-direction: column; align-items: flex-start; gap: 4px; }
}
