:root {
  --navy: #0b1f33;
  --navy-mid: #14324f;
  --crimson: #b42318;
  --crimson-dark: #8f1a12;
  --amber: #c47a11;
  --sand: #f3efe6;
  --sand-dark: #e5dfd0;
  --ink: #1a2330;
  --muted: #5c6b7a;
  --line: #d5d0c4;
  --white: #ffffff;
  --ok: #1f6b45;
  --warn: #9a5b00;
  --info: #1a5f8a;
  --radius: 6px;
  --shadow: 0 10px 30px rgba(11, 31, 51, 0.12);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(180, 35, 24, 0.08), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(20, 50, 79, 0.1), transparent 50%),
    linear-gradient(180deg, #f7f4ed 0%, var(--sand) 100%);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
a { color: var(--crimson); }

/* ── Login ─────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}
.login-hero {
  background:
    linear-gradient(160deg, rgba(11, 31, 51, 0.92), rgba(180, 35, 24, 0.55)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  color: white;
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
  overflow: hidden;
}
.login-hero::before {
  content: "";
  position: absolute;
  inset: auto -20% -30% auto;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.12), transparent 70%);
}
.brand-mark {
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 18px;
}
.login-hero h1 {
  font-family: var(--display);
  font-size: clamp(2.4rem, 4vw, 3.6rem);
  line-height: 1.1;
  max-width: 12ch;
  margin-bottom: 18px;
  position: relative;
}
.login-hero p {
  max-width: 36ch;
  opacity: 0.88;
  line-height: 1.55;
  position: relative;
}
.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 36px;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}
.login-card h2 {
  font-family: var(--display);
  font-size: 1.7rem;
  margin-bottom: 6px;
}
.login-card .sub { color: var(--muted); margin-bottom: 28px; font-size: 0.95rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ── Shell ─────────────────────────────────────────── */
.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.shell-head { display: flex; flex-direction: column; flex-shrink: 0; }
.topbar {
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  height: 64px;
  border-bottom: 3px solid var(--crimson);
}
.topbar .logo {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.topbar .logo span { color: #f0b4ae; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.72);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.nav button:hover, .nav button.active {
  background: rgba(255,255,255,0.1);
  color: white;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
}
.user-chip .role {
  background: rgba(255,255,255,0.12);
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}
.user-chip button.ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.main { padding: 28px; max-width: 1280px; margin: 0 auto; width: 100%; }

/* ── Forms ─────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfaf7;
  border-radius: var(--radius);
  padding: 11px 12px;
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(180, 35, 24, 0.25);
  border-color: var(--crimson);
  background: white;
}
.field textarea { min-height: 100px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.btn {
  appearance: none;
  border: none;
  background: var(--crimson);
  color: white;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.btn:hover { background: var(--crimson-dark); }
.btn:active { transform: scale(0.98); }
.btn.secondary {
  background: var(--navy-mid);
}
.btn.ghost {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line);
}
.btn.sm { padding: 7px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.error {
  background: #fde8e6;
  color: var(--crimson-dark);
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.ok-msg {
  background: #e6f4ec;
  color: var(--ok);
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.demo-accounts {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}
.demo-accounts summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.demo-accounts table { width: 100%; margin-top: 10px; border-collapse: collapse; }
.demo-accounts td { padding: 4px 0; }
.demo-accounts code {
  background: var(--sand-dark);
  padding: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
}

/* ── Cards / panels ────────────────────────────────── */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 22px;
  animation: rise 0.35s ease both;
}
.page-head h1 {
  font-family: var(--display);
  font-size: 1.85rem;
}
.page-head p { color: var(--muted); margin-top: 4px; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  animation: rise 0.4s ease both;
}
.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }
.stat:nth-child(4) { animation-delay: 0.15s; }
.stat .label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat .value { font-family: var(--display); font-size: 1.8rem; margin-top: 6px; }
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  animation: rise 0.4s ease both;
}
.panel h3 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* ── Tables ────────────────────────────────────────── */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 640px;
}
table.data th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.data td {
  padding: 12px 10px;
  border-bottom: 1px solid #eeeae0;
  vertical-align: middle;
}
table.data tr { cursor: pointer; transition: background 0.12s; }
table.data tr:hover { background: #faf7f0; }
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.row-actions .btn { flex: 0 0 auto; white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--sand-dark);
  color: var(--navy);
}
.badge.evidence_gathering, .badge.draft { background: #e8f1f8; color: var(--info); }
.badge.pending_review, .badge.under_scrutiny { background: #fff3d9; color: var(--warn); }
.badge.approved_for_prosecution, .badge.disclosure, .badge.summons_issued { background: #fde8e6; color: var(--crimson); }
.badge.plea_entered, .badge.pre_trial, .badge.trial { background: #efe6f8; color: #5b2d8e; }
.badge.case_closed { background: #e6f4ec; color: var(--ok); }
.badge.disciplinary { background: #f5e6d8; color: #8a4b12; }
.badge.further_investigation { background: #fff3d9; color: var(--warn); }

.alert {
  background: #fff6e8;
  border-left: 4px solid var(--amber);
  padding: 12px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 14px;
  font-size: 0.92rem;
}
.alert.danger {
  background: #fde8e6;
  border-left-color: var(--crimson);
}
.muted { color: var(--muted); font-size: 0.9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.timeline { list-style: none; }
.timeline li {
  position: relative;
  padding: 0 0 18px 22px;
  border-left: 2px solid var(--line);
}
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--crimson);
}
.timeline .when { font-size: 0.78rem; color: var(--muted); }
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.toolbar input, .toolbar select {
  border: 1px solid var(--line);
  background: white;
  border-radius: var(--radius);
  padding: 9px 12px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 51, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 50;
  padding: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: white;
  border-radius: 12px;
  width: min(560px, 100%);
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
  margin: auto 0;
}
.modal h2 { font-family: var(--display); margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 500; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  background: none;
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 560;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.active {
  color: var(--crimson);
  border-bottom-color: var(--crimson);
}
.readonly-banner {
  background: var(--navy);
  color: white;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--white);
}
.lang-switch button {
  border: 0;
  background: transparent;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.lang-switch button.active {
  background: var(--navy);
  color: white;
}

.portal-banner {
  background: linear-gradient(90deg, #1a5f8a, #14324f);
  color: white;
  text-align: center;
  padding: 4px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.3;
  flex: 0 0 auto;
  height: auto;
  min-height: 0;
}
.portal-banner.defense {
  background: linear-gradient(90deg, #8f1a12, #0b1f33);
}

.pipeline-panel { margin-bottom: 16px; }
.pipeline {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.pipe-stage {
  flex: 1;
  min-width: 100px;
  background: linear-gradient(160deg, var(--navy-mid), var(--navy));
  color: white;
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
  animation: rise 0.45s ease both;
}
.pipe-count {
  font-family: var(--display);
  font-size: 1.8rem;
  line-height: 1;
  margin-bottom: 6px;
}
.pipe-label { font-size: 0.78rem; opacity: 0.9; }
.pipe-arrow {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 1.2rem;
}

.sla-list { display: flex; flex-direction: column; gap: 8px; }
.sla-item {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--white);
  transition: transform 0.15s ease, border-color 0.15s;
}
.sla-item:hover { border-color: var(--crimson); transform: translateY(-1px); }
.sla-item.critical { border-left: 4px solid var(--crimson); }
.sla-item.warning { border-left: 4px solid var(--amber); }
.sla-days {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--crimson);
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }

/* ── Redaction review (3-step workflow) ── */
.redact-modal {
  width: min(1100px, 100%);
  max-height: calc(100vh - 24px);
  height: auto;
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  min-height: 0;
}
.rx-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-shrink: 0;
}
.rx-head h2 { margin: 0 0 4px; font-size: clamp(1.1rem, 2.5vw, 1.45rem); }
.rx-head .muted {
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}
.rx-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
}
.rx-steps li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--muted);
  background: #f7f9fb;
}
.rx-steps li.active {
  border-color: var(--navy, #0b1f33);
  color: var(--ink);
  background: #eef4fa;
  font-weight: 600;
}
.rx-steps li.done {
  border-color: #1a7a4c;
  color: #1a7a4c;
  background: #eef8f2;
}
.rx-stats { display: flex; flex-wrap: wrap; gap: 8px; flex-shrink: 0; }
.rx-chip {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.rx-chip.pending { background: #fff7e6; color: #9a6700; border-color: #f0c36d; }
.rx-chip.ok { background: #eef8f2; color: #1a7a4c; border-color: #8fd0ad; }
.rx-chip.no { background: #f8eeee; color: #8a2b2b; border-color: #e0a8a8; }
.rx-chip.ready { background: #0b1f33; color: #fff; border-color: #0b1f33; }
.rx-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.rx-body {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
  min-height: 180px;
}
.rx-preview {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
  background: #0b1f33;
  position: relative;
  max-height: min(48vh, 420px);
}
.rx-text {
  margin: 0;
  padding: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #e8eef5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.rx-hit {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 2px;
}
.rx-hit.rx-pending { background: rgba(240, 195, 109, 0.55); color: #1a1200; outline: 1px dashed #f0c36d; }
.rx-hit.rx-ok { background: #000; color: #fff; outline: 2px solid #1a7a4c; }
.rx-hit.rx-no { background: transparent; color: inherit; text-decoration: line-through; opacity: 0.55; outline: 1px solid #e0a8a8; }
.rx-canvas-wrap {
  position: relative;
  display: block;
  width: 100%;
  cursor: crosshair;
  user-select: none;
}
.rx-canvas-wrap img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}
.rx-overlay { position: absolute; inset: 0; }
.rx-box {
  position: absolute;
  border: 2px solid #f0c36d;
  background: rgba(240, 195, 109, 0.25);
  cursor: pointer;
  box-sizing: border-box;
}
.rx-box span {
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 1px 4px;
  border-radius: 2px;
  pointer-events: none;
}
.rx-box.rx-ok {
  border-color: #111;
  background: #000;
}
.rx-box.rx-ok span { background: #1a7a4c; }
.rx-box.rx-no {
  border-color: #e0a8a8;
  background: transparent;
  border-style: dashed;
  opacity: 0.55;
}
.rx-draw {
  position: absolute;
  border: 2px dashed #fff;
  background: rgba(0,0,0,0.55);
  pointer-events: none;
  box-sizing: border-box;
}
.rx-draw-hint { margin: 8px 10px; color: #c5d0db; font-size: 0.8rem; }
.rx-sidebar {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  overflow: visible;
  background: #fff;
  min-width: 0;
}
.rx-sidebar h3 { margin: 0 0 10px; font-size: 0.95rem; }
.rx-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rx-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fafbfc;
}
.rx-list li.rx-ok { border-left: 4px solid #1a7a4c; }
.rx-list li.rx-no { border-left: 4px solid #8a2b2b; opacity: 0.75; }
.rx-list li.rx-pending { border-left: 4px solid #f0c36d; }
.rx-label { font-weight: 600; font-size: 0.86rem; margin-bottom: 2px; overflow-wrap: anywhere; }
.rx-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 8px; }
.rx-row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.rx-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  background: #fff;
}
.rx-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 0;
  gap: 8px;
}
.rx-actions .btn { flex: 0 1 auto; }
.rx-note { margin: 8px 0 0; font-size: 0.78rem; line-height: 1.4; }

@media (max-width: 960px) {
  .redact-modal {
    width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 12px;
    gap: 8px;
    border-radius: 10px;
  }
  .rx-steps {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .rx-steps li { padding: 7px 9px; font-size: 0.74rem; }
  .rx-body {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .rx-preview { max-height: min(36vh, 280px); }
  .rx-sidebar { max-height: none; }
  .rx-actions .btn { width: 100%; justify-content: center; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tabs button { flex: 0 0 auto; }
}

html[lang="zh-Hant"] body,
html[lang="zh-Hans"] body {
  font-family: "Noto Sans TC", "Noto Sans SC", var(--font);
}

@media (max-width: 960px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { min-height: 280px; padding: 36px; }
  .stats, .grid-2, .grid-3, .row { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 10px; }
  .main { padding: 16px; }
  .kv { grid-template-columns: 1fr; }
  .sla-item { grid-template-columns: 1fr 1fr; }
  .pipe-arrow { display: none; }
  .actions { flex-wrap: wrap; }
  .toolbar { flex-wrap: wrap; }
}
