:root {
  --ink: #14221f;
  --dark-green: #093c32;
  --green: #12604d;
  --paper: #f4f0e5;
  --cream: #fffdf7;
  --lime: #dceb62;
  --orange: #ef7e35;
  --blue: #80c9d7;
  --red: #df514e;
  --muted: #62706a;
  --line: #c6cec1;
  --radius: 10px;
  /* Display and body faces. Nothing is downloaded (the UI makes no external
     requests), so Fraunces and Nunito render only where installed locally. */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ---------- Header ---------- */

.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--dark-green);
  color: var(--cream);
  border-bottom: 3px solid var(--ink);
}

.hdr-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.hdr-sub {
  font-size: 12.5px;
  color: var(--blue);
  margin-top: 2px;
}

.hdr-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.chip-green { background: rgba(18,96,77,0.18); color: #bfe7d6; border-color: rgba(191,231,214,0.35); }
.chip-red { background: rgba(223,81,78,0.2); color: #ffd7d5; border-color: rgba(255,215,213,0.4); }
.chip-orange { background: rgba(239,126,53,0.2); color: #ffdcc0; border-color: rgba(255,220,192,0.4); }
.chip-muted { background: rgba(255,255,255,0.08); color: #c7d0cc; border-color: rgba(255,255,255,0.15); }

/* ---------- Header auth control ---------- */

.hdr-auth {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.token-input {
  width: 168px;
  max-width: 40vw;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: var(--cream);
  font-size: 12px;
  font-family: inherit;
}
.token-input::placeholder { color: rgba(255,253,247,0.55); }
.token-input:focus { outline: none; border-color: var(--lime); background: rgba(255,255,255,0.14); }

.btn-token {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: var(--cream);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.btn-token:hover { background: rgba(255,255,255,0.2); }

.auth-chip-slot { display: inline-flex; }

.hdr-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.hdr-user[hidden], .token-panel[hidden], .token-toggle[hidden] { display: none; }

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  font-size: 12.5px;
  font-weight: 700;
}
.user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--lime);
  color: var(--dark-green);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.user-role {
  font-weight: 600;
  color: var(--blue);
  font-size: 11.5px;
}

.token-toggle {
  background: none;
  border: none;
  padding: 2px 4px;
  color: rgba(255,253,247,0.7);
  font-family: inherit;
  font-size: 11.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.token-toggle:hover { color: var(--cream); }

.token-panel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.process-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Login page ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 12% 18%, rgba(220,235,98,0.35) 0, rgba(220,235,98,0) 38%),
    radial-gradient(circle at 88% 82%, rgba(128,201,215,0.35) 0, rgba(128,201,215,0) 42%),
    var(--paper);
}

.login-wrap { width: 100%; max-width: 380px; }

.login-card {
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: 6px 6px 0 var(--dark-green);
  overflow: hidden;
}

.login-band {
  background: var(--dark-green);
  color: var(--cream);
  padding: 22px 24px 18px;
  border-bottom: 3px solid var(--ink);
}

.login-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.1;
}
.login-title::after {
  content: "";
  display: block;
  width: 42px;
  height: 4px;
  margin-top: 10px;
  border-radius: 2px;
  background: var(--lime);
}

.login-sub {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--blue);
}

.login-fields {
  display: flex;
  flex-direction: column;
  padding: 20px 24px 22px;
}

.login-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  margin: 10px 0 5px;
}
.login-label:first-child { margin-top: 0; }

.login-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
}
.login-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(18,96,77,0.18);
}

.login-error {
  margin: 14px 0 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(223,81,78,0.1);
  border: 1px solid rgba(223,81,78,0.45);
  color: #8f2522;
  font-size: 13px;
  font-weight: 600;
}
.login-error[hidden] { display: none; }

.login-fields .btn-block { margin-top: 18px; font-size: 14.5px; padding: 11px 16px; }

.login-foot {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.login-link {
  display: block;
  margin-top: 6px;
  color: var(--green);
  font-weight: 700;
}
.login-link[hidden] { display: none; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  padding: 18px 24px 40px;
  align-items: start;
}

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 700;
}

.section-label {
  margin: 18px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 700;
}

/* ---------- Input panel ---------- */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--paper);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, .dropzone:focus-visible, .dropzone.drag-over {
  border-color: var(--green);
  background: #fbf9f0;
  outline: none;
}

.dropzone-icon {
  font-size: 22px;
  color: var(--green);
  margin-bottom: 4px;
}

.dropzone-text { font-weight: 600; }
.dropzone-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

.selected-file {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12.5px;
}

.selected-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.link-btn {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 0;
  flex: none;
}
.link-btn:hover { text-decoration: underline; }

.samples-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.samples-empty { color: var(--muted); font-size: 12.5px; grid-column: 1 / -1; }

.sample-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  text-align: left;
  padding: 0;
}

.sample-card img {
  display: block;
  width: 100%;
  height: 58px;
  object-fit: cover;
  background: var(--paper);
}

.sample-card-label {
  font-size: 10px;
  padding: 4px 5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sample-card.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(18,96,77,0.25);
}

.field-row { margin-top: 14px; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
}

.toggle-row { display: flex; }

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 12.5px;
}

.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle-track {
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex: none;
  margin-top: 1px;
  transition: background 0.15s;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.toggle input:checked + .toggle-track { background: var(--green); }
.toggle input:checked + .toggle-track .toggle-thumb { left: 17px; }

.toggle.disabled { cursor: not-allowed; opacity: 0.5; }

.toggle-text { color: var(--ink); }

.btn {
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  padding: 10px 16px;
}

.btn-block { width: 100%; margin-top: 16px; }

.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--dark-green); }
.btn-primary:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }

/* ---------- Progress list ---------- */

.progress-list {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.progress-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 12.5px;
  color: var(--muted);
}

.progress-item.active { color: var(--ink); font-weight: 600; }
.progress-item.done { color: var(--green); }

.progress-marker {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line);
  position: relative;
}

.progress-item.active .progress-marker {
  border-color: var(--green);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.progress-item.done .progress-marker {
  border-color: var(--green);
  background: var(--green);
}
.progress-item.done .progress-marker::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0px;
  width: 3px;
  height: 7px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(40deg);
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress-time {
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Result panel ---------- */

.result-panel { min-height: 480px; }

.tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 8px;
}

.tab-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}

.tab-btn:hover { background: var(--paper); }

.tab-btn.active {
  background: var(--dark-green);
  color: var(--cream);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* `hidden` must win over any display rule below. `.error-state` sets
   `display: flex`, which beats the user-agent `[hidden] { display: none }` on
   specificity alone, so the error banner painted on every result. */
[hidden] { display: none !important; }

.empty-state, .error-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  max-width: 520px;
  margin: 0 auto;
}

.error-state {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  background: rgba(223,81,78,0.08);
  border: 1px solid rgba(223,81,78,0.35);
  border-radius: var(--radius);
  padding: 16px;
  max-width: none;
}

.error-state-icon { font-size: 22px; color: var(--red); flex: none; }
.error-title { margin: 0 0 4px; font-weight: 700; color: var(--red); }
.error-detail { margin: 0; color: var(--ink); font-size: 13px; }

.empty-state-icon { font-size: 30px; color: var(--line); margin-bottom: 8px; }

/* ---------- Before / After ---------- */

.ba-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 640px) { .ba-grid { grid-template-columns: 1fr; } }

.ba-col { position: relative; }

.ba-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: repeating-conic-gradient(#efece1 0% 25%, #f7f5ec 0% 50%) 50% / 16px 16px;
  height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.ba-frame img, .ba-frame embed {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ba-caption {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}

.badge-count {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--dark-green);
  color: var(--cream);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
}

.page-selector {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 8px;
}

.page-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11.5px;
  cursor: pointer;
}
.page-btn.active { background: var(--green); color: #fff; border-color: var(--green); }

/* ---------- Classification ---------- */

.cls-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.cls-doctype { font-size: 26px; font-weight: 800; }
.cls-conf { font-size: 16px; color: var(--green); font-weight: 700; }
.cls-classifier { font-size: 12px; color: var(--muted); }

.dist-row {
  display: grid;
  grid-template-columns: 120px 1fr 50px;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 12.5px;
}

.dist-bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
}

.dist-bar-fill { height: 100%; background: var(--green); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-orange { background: rgba(239,126,53,0.15); color: #b95c1e; border: 1px solid rgba(239,126,53,0.4); }
.badge-green { background: rgba(18,96,77,0.12); color: var(--green); border: 1px solid rgba(18,96,77,0.35); }

/* ---------- Tables ---------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.4px;
  font-weight: 700;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.table-wrap .data-table { border: none; }
.table-wrap .data-table th, .table-wrap .data-table td { white-space: nowrap; }

.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  background: var(--lime);
  color: var(--dark-green);
}

.pill-token { background: var(--blue); color: var(--dark-green); font-family: ui-monospace, monospace; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }

.struck { text-decoration: line-through; color: var(--muted); }

.note {
  font-size: 12px;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 10px;
}

.section-heading {
  font-size: 13px;
  font-weight: 700;
  margin: 18px 0 8px;
}
.section-heading:first-child { margin-top: 0; }

/* ---------- Redacted text ---------- */

.redacted-pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  max-height: 460px;
  overflow-y: auto;
}

.ph {
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 700;
  background: var(--lime);
  color: var(--dark-green);
}
.ph-PERSON { background: var(--lime); }
.ph-PHONE_ID, .ph-PHONE_NUMBER { background: var(--blue); }
.ph-LOCATION, .ph-ADDRESS { background: #f6d9a4; }
.ph-ID_NUMBER, .ph-NIK { background: #f2b8b6; }

/* ---------- Evidence / KV grid ---------- */

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.kv-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--paper);
}

.kv-key { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); font-weight: 700; }
.kv-val { font-size: 14px; font-weight: 700; margin-top: 2px; word-break: break-word; }

/* ---------- Audit trail ---------- */

.audit-timeline { border-left: 2px solid var(--line); padding-left: 14px; }

.audit-item { position: relative; padding-bottom: 16px; }
.audit-item::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--cream);
}

.audit-stage { font-weight: 700; font-size: 13px; text-transform: capitalize; }
.audit-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.audit-detail {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  margin-top: 5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Raw JSON ---------- */

.raw-json {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--ink);
  color: #d7e9df;
  border-radius: 8px;
  padding: 14px;
  max-height: 520px;
  overflow: auto;
}

.copy-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}
.copy-btn:hover { background: var(--paper); }
