/* Marksheet Extraction Panel
   Palette drawn from the source documents: seal maroon, stamp teal,
   tinted security paper. Type: Zilla Slab (headings) / IBM Plex Sans (UI)
   / IBM Plex Mono (identifiers and dates). */

:root {
  --ground: #e8e9e3;
  --surface: #ffffff;
  --surface-2: #f4f4ef;
  --ink: #17211f;
  --ink-2: #5a6360;
  --ink-3: #8b928f;
  --seal: #7a1f2b;
  --seal-soft: #f3e4e6;
  --stamp: #0f5c4e;
  --stamp-soft: #e2efeb;
  --flag: #b5651d;
  --flag-soft: #fbeddd;
  --rule: #d3d5cd;
  --rule-soft: #e4e5df;

  --sp: 8px;
  --radius: 3px;
  --shadow: 0 1px 2px rgba(23, 33, 31, .07), 0 8px 24px rgba(23, 33, 31, .06);
}

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

body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: var(--ground);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Zilla Slab', Georgia, serif; font-weight: 600; }
.sub { color: var(--ink-2); font-size: 12px; }
.error { color: var(--seal); font-size: 13px; }

:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }

/* Class-level display rules beat the UA [hidden] rule, so state it loudly.
   Without this the verify pane stays laid out and eats every click. */
[hidden] { display: none !important; }

/* Class-level display rules beat the UA [hidden] rule, so state it loudly.
   Without this the verify pane stays laid out and eats every click. */
[hidden] { display: none !important; }

/* --- seal ---------------------------------------------------------------- */

.seal {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--seal); color: #fff;
  display: grid; place-items: center;
  font-family: 'Zilla Slab', serif; font-size: 22px; font-weight: 700;
  box-shadow: inset 0 0 0 2px var(--seal), inset 0 0 0 4px #fff;
  flex: none;
}
.seal.small { width: 34px; height: 34px; font-size: 16px; box-shadow: inset 0 0 0 1px var(--seal), inset 0 0 0 3px #fff; }

/* --- sign in ------------------------------------------------------------- */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin-card {
  background: var(--surface); width: 100%; max-width: 340px;
  padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 3px solid var(--seal);
}
.signin-card h1 { font-size: 20px; margin-top: 16px; }
.signin-card .sub { margin-bottom: 24px; }
.signin-card label {
  display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-2); margin-bottom: 5px;
}
.signin-card input { width: 100%; margin-bottom: 16px; }
.signin-card .btn { width: 100%; }
.signin-card .error { margin-top: 12px; }

/* --- inputs & buttons ---------------------------------------------------- */

input, select {
  font: inherit; color: var(--ink);
  padding: 8px 10px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius);
}
input:focus { border-color: var(--stamp); outline: none; box-shadow: 0 0 0 2px var(--stamp-soft); }

.btn {
  font: inherit; font-weight: 500; cursor: pointer;
  padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--seal); border-color: var(--seal); color: #fff; }
.btn-primary:hover { background: #641822; }
.btn-quiet { background: transparent; }
.btn-link { border: none; background: none; color: var(--stamp); padding: 4px; text-decoration: underline; }

/* --- layout -------------------------------------------------------------- */

#app { max-width: 1440px; margin: 0 auto; padding: 20px; }

.topbar {
  position: relative;   /* anchors the usage popover below the chip */
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; line-height: 1.2; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  color: var(--ink-2); background: var(--surface-2);
  padding: 3px 8px; border-radius: var(--radius);
}

/* --- queue rail (signature) ---------------------------------------------- */

.rail-wrap { margin: 20px 0; }
.rail-head {
  display: flex; align-items: baseline; gap: 16px;
  flex-wrap: wrap; margin-bottom: 8px;
}
.rail-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-2); font-weight: 600;
}
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--ink-2); }
.legend span { display: flex; align-items: center; gap: 5px; }
.sw { width: 9px; height: 9px; border-radius: 1px; display: inline-block; }
.sw-extracted { background: var(--stamp); }
.sw-pending   { background: var(--rule); }
.sw-failed    { background: var(--seal); }
.sw-flagged   { background: var(--flag); }
.rail-summary {
  margin-left: auto; font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; color: var(--ink-2);
}

.rail {
  display: flex; flex-wrap: wrap; gap: 2px;
  padding: 10px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius);
  min-height: 46px; max-height: 116px; overflow-y: auto;
}
.tick {
  width: 7px; height: 22px; border-radius: 1px;
  background: var(--rule); flex: none;
  transition: background .3s ease;
}
.tick.extracted { background: var(--stamp); }
.tick.done      { background: var(--stamp); }
.tick.verified  { background: var(--stamp); }
.tick.failed    { background: var(--seal); }
.tick.flagged   { background: var(--flag); }
.tick.pending   { background: var(--rule); }
.rail-empty { color: var(--ink-3); font-size: 12px; padding: 4px; }

/* --- controls ------------------------------------------------------------ */

.controls {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 16px; margin-bottom: 20px;
}
.drop {
  border: 1.5px dashed var(--rule); border-radius: var(--radius);
  padding: 22px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--stamp); background: var(--stamp-soft); }
.drop strong { display: block; font-family: 'Zilla Slab', serif; font-size: 15px; }
.drop span { font-size: 12px; color: var(--ink-2); }

.actions {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-top: 14px;
}
.spacer { flex: 1; }
.limit { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.limit input { width: 74px; padding: 6px 8px; font-family: 'IBM Plex Mono', monospace; }

.runstate {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; padding: 10px 12px;
  background: var(--stamp-soft); border-left: 3px solid var(--stamp);
  font-size: 13px;
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--stamp); animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.log {
  margin-top: 12px; padding: 12px; max-height: 260px; overflow: auto;
  background: var(--ink); color: #d8dedb; border-radius: var(--radius);
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.notice {
  margin-top: 12px; padding: 10px 12px; font-size: 13px;
  border-left: 3px solid var(--flag); background: var(--flag-soft);
}
.notice.good { border-color: var(--stamp); background: var(--stamp-soft); }
.notice.bad  { border-color: var(--seal); background: var(--seal-soft); }

/* --- results ------------------------------------------------------------- */

.results {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.filters {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 16px; border-bottom: 1px solid var(--rule); flex-wrap: wrap;
}
.tab {
  font: inherit; font-size: 13px; cursor: pointer;
  padding: 6px 12px; border: none; background: none;
  color: var(--ink-2); border-radius: var(--radius);
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.is-active { background: var(--ink); color: #fff; }
.filters #search { margin-left: auto; min-width: 260px; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2);
  background: var(--surface-2); padding: 9px 12px;
  border-bottom: 1px solid var(--rule); white-space: nowrap;
}
tbody td {
  padding: 9px 12px; border-bottom: 1px solid var(--rule-soft);
  vertical-align: top; max-width: 260px;
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.flagged td:first-child { box-shadow: inset 3px 0 0 var(--flag); }
tbody tr.failed  td:first-child { box-shadow: inset 3px 0 0 var(--seal); }
td.mono, th.mono { font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
td .missing { color: var(--ink-3); font-style: italic; }

.pill {
  display: inline-block; font-size: 10.5px; font-weight: 500;
  padding: 2px 7px; border-radius: 10px; white-space: nowrap;
  text-transform: uppercase; letter-spacing: .04em;
}
.pill-extracted { background: var(--stamp-soft); color: var(--stamp); }
.pill-failed    { background: var(--seal-soft);  color: var(--seal); }
.pill-pending   { background: var(--surface-2);  color: var(--ink-2); }
.pill-flagged   { background: var(--flag-soft);  color: var(--flag); }

.empty { padding: 40px 16px; text-align: center; color: var(--ink-2); }
.pager {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 12px; border-top: 1px solid var(--rule);
  font-size: 12px; color: var(--ink-2);
}

/* --- verify pane --------------------------------------------------------- */

.scrim {
  position: fixed; inset: 0; background: rgba(23, 33, 31, .34);
  z-index: 40;
}
.verify {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(1040px, 94vw); background: var(--surface);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(23, 33, 31, .18);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }

.verify-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--rule);
}
.verify-head h2 { font-size: 17px; }
.verify-body { flex: 1; display: grid; grid-template-columns: 1fr 400px; overflow: hidden; }

.scan {
  background: var(--ground); overflow: auto; padding: 16px;
  display: grid; place-items: start center;
}
.scan img { max-width: 100%; box-shadow: var(--shadow); background: #fff; }
.scan-missing { color: var(--ink-2); font-size: 13px; padding: 40px 16px; text-align: center; }

.fields { overflow-y: auto; padding: 16px 20px; border-left: 1px solid var(--rule); }
.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-2); margin-bottom: 4px;
}
.field input { width: 100%; }
.field.is-flagged input { border-color: var(--flag); background: var(--flag-soft); }
.field .why { font-size: 11px; color: var(--flag); margin-top: 3px; }
.field.readonly input { background: var(--surface-2); color: var(--ink-2); }

.verify-foot {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-top: 1px solid var(--rule); background: var(--surface-2);
}
.verify-foot .hint { margin-left: auto; font-size: 11.5px; color: var(--ink-2); }

/* --- responsive ---------------------------------------------------------- */

@media (max-width: 900px) {
  #app { padding: 12px; }
  .verify-body { grid-template-columns: 1fr; }
  .scan { max-height: 40vh; }
  .fields { border-left: none; border-top: 1px solid var(--rule); }
  .filters #search { margin-left: 0; width: 100%; }
  .legend { display: none; }
  .verify-foot .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* --- document types ------------------------------------------------------ */

.uploadtype {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px; flex-wrap: wrap;
}
.uploadtype label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-2); font-weight: 600;
}
.uploadtype select { font-size: 13px; min-width: 210px; }
.hint-inline { font-size: 11.5px; color: var(--ink-3); }

.type-filter { font-size: 13px; margin-right: 8px; min-width: 160px; }

.typechip {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 10px; background: var(--surface-2);
  color: var(--ink-2); white-space: nowrap;
}
.typechip.unsure {
  background: var(--flag-soft); color: var(--flag);
}

.verify-type {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-2); font-weight: 600;
}
.verify-type select { font-size: 12px; text-transform: none; letter-spacing: 0; }

.extra-head {
  margin: 18px 0 6px; padding-top: 12px;
  border-top: 1px solid var(--rule-soft);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-2); font-weight: 600;
}
.extra-line { font-size: 12px; color: var(--ink-2); margin-bottom: 3px; }

/* --- types drawer -------------------------------------------------------- */

.types-drawer { width: min(760px, 94vw); }
.types-body {
  flex: 1; display: grid; grid-template-columns: 280px 1fr; overflow: hidden;
}
.types-list {
  list-style: none; overflow-y: auto; padding: 12px;
  background: var(--surface-2); border-right: 1px solid var(--rule);
}
.type-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius);
  margin-bottom: 7px;
}
.type-item > div { flex: 1; min-width: 0; }
.type-item strong { display: block; font-size: 13px; }
.type-meta { font-size: 11px; color: var(--ink-3); }
.type-item .btn { padding: 4px 9px; font-size: 12px; }

.type-editor { overflow-y: auto; padding: 16px 20px; }
.type-editor h3 { font-size: 15px; margin-bottom: 12px; }
.type-editor > label {
  display: block; margin-top: 12px; margin-bottom: 4px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-2);
}
.type-editor > input { width: 100%; }

.tfields { margin-bottom: 10px; }
.tfield {
  display: grid; grid-template-columns: 1.1fr 1.3fr auto auto auto;
  gap: 6px; align-items: center; margin-bottom: 6px;
}
.tfield input[type="text"], .tfield input:not([type]), .tfield select {
  font-size: 12px; padding: 6px 8px; min-width: 0;
}
.tf-key { font-family: 'IBM Plex Mono', monospace; }
.tf-req {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--ink-2);
}
.tf-req input { margin: 0; }

.type-editor-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule);
}
.type-editor-foot .error { flex: 1; }

@media (max-width: 900px) {
  .types-body { grid-template-columns: 1fr; }
  .types-list { border-right: none; border-bottom: 1px solid var(--rule); max-height: 34vh; }
  .tfield { grid-template-columns: 1fr 1fr; }
}

/* --- usage chip ----------------------------------------------------------- */

.usage {
  display: flex; align-items: baseline; gap: 7px;
  font: inherit; cursor: pointer;
  padding: 5px 11px; border-radius: var(--radius);
  border: 1px solid var(--rule); background: var(--surface);
  transition: border-color .12s ease, background .12s ease;
}
.usage:hover { border-color: var(--stamp); background: var(--stamp-soft); }
.usage-label {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-2); font-weight: 600;
}
.usage-inr {
  font-family: 'IBM Plex Mono', monospace; font-size: 13px;
  font-weight: 500; color: var(--seal);
}
.usage-tok {
  font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; color: var(--ink-3);
}
.usage-panel {
  position: absolute; top: 100%; right: 0; z-index: 30; margin-top: 2px;
  width: 268px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.usage-panel h3 { font-size: 13px; margin-bottom: 10px; }
.usage-grid {
  display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; font-size: 12px;
}
.usage-grid dt { color: var(--ink-2); }
.usage-grid dd {
  font-family: 'IBM Plex Mono', monospace; text-align: right; color: var(--ink);
}
.usage-grid dt:last-of-type, .usage-grid dd:last-of-type {
  padding-top: 7px; margin-top: 3px; border-top: 1px solid var(--rule-soft);
  font-weight: 600;
}
.usage-grid dd:last-of-type { color: var(--seal); }
.usage-note {
  margin-top: 10px; font-size: 10.5px; color: var(--ink-3); line-height: 1.5;
}
td.cost { font-family: 'IBM Plex Mono', monospace; font-size: 12px;
          color: var(--seal); white-space: nowrap; }
td.tokens { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px;
            color: var(--ink-3); white-space: nowrap; }

td.stamp {
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px;
  color: var(--ink-3); white-space: nowrap;
}

/* --- duplicates & deleted ------------------------------------------------- */

.tabcount {
  display: inline-block; margin-left: 5px; padding: 1px 6px;
  border-radius: 9px; font-size: 10.5px;
  background: var(--flag-soft); color: var(--flag);
  font-family: 'IBM Plex Mono', monospace;
}
.tab.is-active .tabcount { background: rgba(255,255,255,.2); color: #fff; }

.bulkbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; font-size: 13px;
  background: var(--flag-soft); border-bottom: 1px solid var(--rule);
}
.bulkbar .spacer { flex: 1; }

.btn-danger { border-color: var(--seal); color: var(--seal); background: transparent; }
.btn-danger:hover { background: var(--seal-soft); }

tbody tr.is-deleted td { opacity: .55; }
tbody tr.is-deleted td:first-child { box-shadow: inset 3px 0 0 var(--ink-3); }
tbody tr.duplicate td:first-child { box-shadow: inset 3px 0 0 var(--flag); }

.dupechip {
  display: inline-block; font-size: 10.5px; padding: 1px 7px;
  border-radius: 9px; background: var(--flag-soft); color: var(--flag);
  margin-left: 6px; white-space: nowrap;
}
.delchip {
  display: inline-block; font-size: 10.5px; padding: 1px 7px;
  border-radius: 9px; background: var(--surface-2); color: var(--ink-3);
  margin-left: 6px; white-space: nowrap;
}
