/* Latin covers Indonesian; both fonts are self-hosted for the CSP and offline use. */
@font-face {
  font-family: "Carter One";
  src: url("/assets/fonts/carter-one.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: Bitter;
  src: url("/assets/fonts/bitter.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ─── Tokens ──────────────────────────────────────────────────────────── */
:root {
  --font-display: "Carter One", Bitter, Georgia, serif;
  --font-body: Bitter, Georgia, "Times New Roman", serif;
  --ink:       #171717;
  --paper:     #f4eddf;
  --surface:   #fffdf8;
  --accent:    #facc15;
  --danger:    #8f1d14;
  --danger-fg: #fffdf8;
  --link:      #075985;
  --border:    3px solid var(--ink);
  --radius:    2px;
  --shadow:    6px 6px 0 var(--accent);
  --shadow-sm: 4px 4px 0 var(--accent);

  /* Spacing scale (4-base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  color-scheme: light;
  font-family: var(--font-body);
  font-synthesis: none;
  color: var(--ink);
  background: var(--paper);
}

/* ─── Reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html   { overscroll-behavior: none; scroll-padding-top: 72px; }
body   { margin: 0; min-width: 280px; overscroll-behavior: none; }
p      { max-width: 65ch; margin-top: 0; }
h1, h2, h3 { margin-top: 0; }

button, a, select, input, label { font: inherit; }

/* ─── Typography ─────────────────────────────────────────────────────── */
/* Carter One ships one weight, so display text never asks for bold. */
h1, h2, .wordmark { font-family: var(--font-display); font-weight: 400; }
h1 {
  font-size: clamp(2.2rem, 7vw, 4.8rem);
  line-height: 1.02;
  letter-spacing: 0;
  margin-bottom: var(--sp-5);
  max-width: 18ch;
}
h2 {
  font-size: clamp(1.3rem, 3vw, 1.7rem);
  line-height: 1.15;
  margin-bottom: var(--sp-4);
}
h3 { font-size: 1.1rem; margin-bottom: var(--sp-3); }

.eyebrow {
  margin: 0 0 var(--sp-3);
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ─── Skip link ──────────────────────────────────────────────────────── */
.skip-link {
  position: fixed;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: 100;
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  border: var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform .15s;
}
.skip-link:focus { transform: none; }

/* ─── Site header ────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: 64px;
  padding: var(--sp-3) clamp(var(--sp-4), 5vw, var(--sp-16));
  background: var(--surface);
  border-bottom: var(--border);
}
.wordmark {
  color: var(--ink);
  font-size: 1.35rem;
  text-decoration: none;
}
.device-label {
  font-size: .85rem;
  font-weight: 700;
  padding: var(--sp-1) var(--sp-3);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
}

/* ─── Main / layout containers ───────────────────────────────────────── */
main { padding: clamp(var(--sp-8), 6vw, var(--sp-16)) clamp(var(--sp-4), 5vw, var(--sp-16)); }

.workstation,
.customer-shell {
  width: min(1080px, 100%);
  margin: 0 auto;
}

/* ─── Paper panel ────────────────────────────────────────────────────── */
.paper-panel {
  position: relative;
  padding: clamp(var(--sp-5), 4vw, var(--sp-10));
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
}
.paper-panel::after {
  content: "";
  position: absolute;
  inset: 8px -9px -9px 8px;
  z-index: -1;
  background: var(--accent);
  border: var(--border);
  border-radius: var(--radius);
}

/* ─── Buttons & interactive controls ─────────────────────────────────── */
button,
.action-link,
.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-5);
  border: var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  font-size: .95rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
}
button:hover,
.action-link:hover,
.file-picker:hover {
  transform: translate(-1px, -1px);
  box-shadow: var(--shadow-sm);
}
button:active,
.action-link:active,
.file-picker:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
.file-picker:focus-within {
  outline: 3px solid var(--link);
  outline-offset: 3px;
}

.primary   { background: var(--accent); }
.secondary { background: var(--surface); }
.danger    { background: var(--danger); color: var(--danger-fg); border-color: var(--danger); }
.danger-quiet { color: var(--danger); background: transparent; border-color: var(--danger); }
.danger:hover, .danger-quiet:hover { box-shadow: 4px 4px 0 var(--danger); }

button[disabled],
button[aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

/* ─── Notice / callout ───────────────────────────────────────────────── */
.notice {
  padding: var(--sp-4) var(--sp-5);
  border-left: 6px solid var(--ink);
  background: var(--accent);
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.5;
}

/* ─── Session heading row ────────────────────────────────────────────── */
.session-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-8);
  margin-bottom: var(--sp-8);
  flex-wrap: wrap;
}
.session-heading .meta { flex: 1; min-width: 0; }

.deadline {
  flex: none;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent);
  border: var(--border);
  border-radius: var(--radius);
  font-weight: 800;
  font-size: .95rem;
  white-space: nowrap;
}
.deadline.warning { background: var(--danger); color: var(--danger-fg); border-color: var(--danger); }

/* ─── Welcome / setup panel ──────────────────────────────────────────── */
.welcome {
  display: grid;
  gap: clamp(var(--sp-8), 5vw, var(--sp-16));
}
.intro { max-width: 680px; }
.intro p { font-size: 1.1rem; line-height: 1.6; color: #444; }

.setup-panel {
  display: grid;
  grid-template-columns: minmax(160px, 260px) 1fr;
  gap: clamp(var(--sp-6), 5vw, var(--sp-12));
  align-items: center;
}
.document-mark {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border: var(--border);
  border-radius: var(--radius);
  user-select: none;
}
.setup-content { display: grid; gap: var(--sp-4); }
.setup-content h2 { margin-bottom: var(--sp-2); }
.setup-content p  { font-size: .95rem; color: #555; margin: 0; }
.setup-content .action-link { justify-self: start; }

/* ─── Idle / QR panel ────────────────────────────────────────────────── */
.idle-workstation {
  display: grid;
  gap: var(--sp-8);
}

.qr-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(var(--sp-6), 5vw, var(--sp-12));
  align-items: start;
}
.qr-image-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}
.qr {
  display: block;
  width: clamp(160px, 28vw, 280px);
  border: var(--border);
  border-radius: var(--radius);
  image-rendering: pixelated;
}
.scan-note {
  font-size: .8rem;
  font-weight: 700;
  text-align: center;
  max-width: 200px;
  color: #555;
  margin: 0;
}

.qr-info { display: grid; gap: var(--sp-5); }
.qr-info h2 { margin-bottom: var(--sp-2); }
.qr-info p  { font-size: .95rem; color: #555; margin: 0; }

.claim-link {
  display: block;
  color: var(--link);
  font-size: .9rem;
  font-weight: 700;
  word-break: break-all;
  margin-top: var(--sp-2);
}

/* ─── Active session / file list ─────────────────────────────────────── */
.active-session {
  display: grid;
  gap: var(--sp-8);
}

.file-panel {
  min-height: 200px;
}
.file-panel .empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  text-align: center;
  color: #666;
}
.file-panel .empty-state p { margin: 0; font-size: .95rem; }

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}
.file-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) 0;
  border-bottom: 2px solid #e5e0d0;
}
.file-row:last-child { border-bottom: none; }
.file-row-info strong {
  display: block;
  font-size: 1rem;
  word-break: break-all;
}
.file-row-info span {
  display: block;
  margin-top: 2px;
  font-size: .85rem;
  color: #666;
}
.file-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  flex-shrink: 0;
}
.file-row-actions button {
  min-height: 36px;
  padding: var(--sp-1) var(--sp-3);
  font-size: .85rem;
}

.disclosure {
  font-size: .85rem;
  color: #666;
  margin: 0;
  padding: var(--sp-3) 0;
  border-top: 2px solid #e5e0d0;
}

.session-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: var(--sp-3);
}

/* ─── Expired / destroyed state ──────────────────────────────────────── */
.terminal-state {
  max-width: 640px;
  margin: 0 auto;
}
.terminal-state .paper-panel {
  display: grid;
  gap: var(--sp-5);
}
.terminal-state h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  margin-bottom: var(--sp-2);
}

/* ─── Customer: upload panel ─────────────────────────────────────────── */
.customer-shell {
  display: grid;
  gap: clamp(var(--sp-6), 4vw, var(--sp-10));
}

.upload-panel {
  display: grid;
  gap: var(--sp-5);
}
.upload-panel p { font-size: .9rem; color: #555; margin: 0; }

/* Visually hide the file input; show a styled label instead */
.file-picker-wrap { position: relative; }
input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  overflow: hidden;
}
.file-picker { background: var(--accent); width: fit-content; }

.selection-list {
  display: grid;
  gap: var(--sp-3);
}
.selection-item {
  padding: var(--sp-3) var(--sp-4);
  background: var(--paper);
  border: 2px solid #ccc;
  border-radius: var(--radius);
  font-size: .9rem;
}
.selection-item strong { display: block; word-break: break-all; }
.selection-item span   { color: #666; font-size: .85rem; }

.form-error:empty { padding: 0; border: 0; }
.form-error strong::after { content: ": "; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.upload-progress {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--paper);
  border: 2px dashed var(--ink);
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 700;
  margin: 0;
}
.upload-progress[hidden] { display: none; }
.upload-progress p { margin: 0; overflow-wrap: anywhere; }
.upload-progress progress {
  width: 100%;
  height: 20px;
  accent-color: var(--ink);
}

.uploaded-files-panel h2 { font-size: 1.05rem; margin-bottom: var(--sp-4); }

.uploaded-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) 0;
  border-bottom: 2px solid #e5e0d0;
}
.uploaded-row:last-child { border-bottom: none; }
.uploaded-info strong { display: block; word-break: break-all; font-size: .95rem; }
.uploaded-info span   { display: block; margin-top: 2px; font-size: .85rem; color: #666; }

/* ─── Customer: claim screen ─────────────────────────────────────────── */
.claim-shell {
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  gap: var(--sp-6);
}
.claim-status-panel {
  display: grid;
  gap: var(--sp-4);
  min-height: 160px;
  align-content: center;
}
.claim-status-panel h2 { margin-bottom: var(--sp-2); }
.claim-status-panel p  { font-size: .9rem; color: #666; margin: 0; }

/* ─── Customer: scan screen ──────────────────────────────────────────── */
.scan-shell {
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  gap: var(--sp-6);
}
.camera-panel { display: grid; gap: var(--sp-4); }
.camera-panel video {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--ink);
  border-radius: var(--radius);
  display: block;
  object-fit: cover;
}
.camera-status {
  font-size: .9rem;
  font-weight: 700;
  margin: 0;
}

/* ─── Errors ─────────────────────────────────────────────────────────── */
.form-error {
  padding: var(--sp-3) var(--sp-4);
  background: var(--danger);
  color: var(--danger-fg);
  border: var(--border);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: .9rem;
  line-height: 1.5;
}

/* ─── Network status bar ─────────────────────────────────────────────── */
.network-status {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 50;
  max-width: 360px;
  padding: var(--sp-3) var(--sp-5);
  background: var(--ink);
  color: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: .9rem;
  line-height: 1.4;
}

.deadline-warning {
  position: sticky;
  bottom: var(--sp-4);
  z-index: 20;
  width: min(100%, 640px);
  margin: var(--sp-6) auto 0;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent);
  color: var(--ink);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

::backdrop { background: rgb(23 23 23 / .65); }

dialog {
  width: min(640px, calc(100% - var(--sp-8)));
  max-height: calc(100dvh - var(--sp-8));
  padding: 0;
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dialog-card {
  padding: clamp(var(--sp-5), 5vw, var(--sp-10));
  overflow-y: auto;
  display: grid;
  gap: var(--sp-4);
}
.dialog-card h2 { margin-bottom: 0; }
.dialog-card p  { margin: 0; font-size: .95rem; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}

/* Preview dialog needs more room */
dialog.preview-dialog {
  width: min(900px, calc(100% - var(--sp-8)));
}
.preview-dialog .dialog-card { gap: var(--sp-3); }
.preview-content iframe {
  width: 100%;
  height: 60vh;
  border: var(--border);
  border-radius: var(--radius);
  display: block;
}
.preview-content img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  margin: 0 auto;
  border: var(--border);
  border-radius: var(--radius);
}
.preview-content pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: .9rem;
  line-height: 1.5;
  max-height: 60vh;
  overflow-y: auto;
  padding: var(--sp-4);
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
}
.preview-warning {
  padding: var(--sp-3) var(--sp-4);
  background: #fef9c3;
  border: 2px solid #8f5b00;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 700;
  margin: 0;
}
.preview-unavailable {
  padding: var(--sp-5);
  text-align: center;
  color: #555;
  font-size: .95rem;
}
.mt-12 { margin-top: var(--sp-3); }

/* ─── Misc utilities ─────────────────────────────────────────────────── */
[hidden] { display: none !important; }

/* ─── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .device-label { display: none; }

  /* Welcome panel: stack document-mark above text */
  .setup-panel {
    grid-template-columns: 1fr;
  }
  .document-mark {
    width: 96px;
    height: 96px;
  }

  /* QR panel: stack vertically, QR centred */
  .qr-panel {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .qr-image-wrap { width: 100%; }
  .qr { width: min(72vw, 280px); }

  /* Session heading stacks */
  .session-heading {
    flex-direction: column;
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
  }
  .deadline { align-self: flex-start; }

  /* File rows: stack info and actions */
  .file-row {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }
  .file-row-actions {
    width: 100%;
  }
  .file-row-actions button {
    flex: 1;
    min-height: 44px;
  }

  /* Session / dialog actions go full-width */
  .session-actions,
  .dialog-actions {
    flex-direction: column;
  }
  .session-actions button,
  .session-actions .action-link,
  .dialog-actions button { width: 100%; }

  /* Upload rows: stack */
  .uploaded-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-2);
  }
  .uploaded-row button { width: 100%; }

  .deadline-warning {
    bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  }
}

@media (min-width: 681px) and (max-width: 1024px) {
  .qr-panel {
    grid-template-columns: minmax(220px, .75fr) 1fr;
  }
  .file-row {
    grid-template-columns: minmax(0, 1fr);
  }
  .file-row-actions {
    justify-content: flex-start;
  }
}

/* ─── Print ──────────────────────────────────────────────────────────── */
@media print {
  .site-header,
  .session-actions,
  .dialog-actions,
  .deadline,
  .notice,
  .network-status,
  .skip-link { display: none; }

  .paper-panel { border: 0; }
  .paper-panel::after { display: none; }

  dialog[open] {
    position: static;
    width: 100%;
    max-height: none;
    border: 0;
    box-shadow: none;
  }
  .dialog-card { padding: 0; overflow: visible; }
  .preview-content iframe,
  .preview-content img { max-height: none; height: auto; }
}

/* ─── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ─── QR expiry overlay and heading actions ──────────────────────────── */
.qr-frame { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; }
.qr-expired {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4);
  text-align: center;
  background: rgb(255 253 248 / .94);
  border: var(--border);
}
.qr-expired[hidden] { display: none; }
.qr-expired p { margin: 0; font-weight: 800; }
.heading-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
.heading-actions form { margin: 0; }

/* Loading bar: a yellow slice travelling along the header's bottom border. */
.top-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 3px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.top-progress.active { opacity: 1; }
.top-progress-bar {
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .3s ease-out;
}
#main:focus { outline: none; }
