@font-face {
  font-family: 'Duplet Variable'; src: url('/fonts/Duplet-Variable.woff2') format('woff2');
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter'; src: url('/fonts/Inter-latin.woff2') format('woff2');
  font-weight: 400 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Source Code Pro'; src: url('/fonts/SourceCodePro-latin.woff2') format('woff2');
  font-weight: 400 600; font-style: normal; font-display: swap;
}

/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #F8F9FF;
  --surface:   #FFFFFF;
  --surface2:  #F8F8F8;
  --border:    #C8D4D1;
  --accent:    #005FEA;
  --accent2:   #FF7900;
  --warn:      #0549AD;
  --danger:    #B42318;
  --text:      #242424;
  --text-dim:  #555955;
  --font-mono: 'Inter', system-ui, sans-serif;
  --font-title: 'Duplet Variable', Arial, Helvetica, sans-serif;
  --font-label: 'Source Code Pro', monospace;
  --font-body: 'Inter', system-ui, sans-serif;
  --radius:    16px;
  --radius-sm: 8px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  min-height: 100svh;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  overflow-x: clip;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(0,95,234,.045) 0%, transparent 70%);
}

/* ── Header ────────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 680px; margin: 0 auto;
  padding: .9rem max(1.2rem, env(safe-area-inset-right)) .9rem max(1.2rem, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
  min-width: 0;
}
.logo { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; text-decoration: none; color: var(--text); }
.logo-image { display: block; width: 168px; height: auto; }
.app-name { font-family: var(--font-title); font-size: 1.1rem; font-weight: 600; line-height: 1; color: #003C97; }

.header-right {
  display: flex; align-items: center; gap: .75rem;
}
.btn-reset-header {
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--text-dim); border-radius: var(--radius-sm);
  opacity: .6; transition: opacity .15s, color .15s;
}
.btn-reset-header svg { width: 16px; height: 16px; }
.btn-reset-header:hover { opacity: 1; color: var(--accent); }

.header-help-link {
  font-size: .75rem; font-weight: 600; color: var(--text-dim);
  text-decoration: none; letter-spacing: .04em;
}
.header-help-link:hover { color: var(--accent); }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 0 0 transparent;
  transition: background .3s, box-shadow .3s;
}
.status-dot.ok {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(0,95,234,.6);
  animation: pulse 2s infinite;
}
.status-dot.err { background: var(--danger); }

@keyframes pulse {
  0%,100% { box-shadow: 0 0 6px rgba(0,95,234,.5); }
  50%      { box-shadow: 0 0 14px rgba(0,95,234,.9); }
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  max-width: 680px;
  margin: 1.25rem auto;
  width: calc(100% - 2rem);
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  animation: slideUp .3s ease;
  min-width: 0;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-label {
  font-family: var(--font-label);
  font-size: .7rem; font-weight: 400;
  color: var(--accent); letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: .5rem;
}
.card h2 {
  font-family: var(--font-title); line-height: 1.1;
  font-size: 1.15rem; font-weight: 600;
  margin-bottom: 1.1rem; color: var(--text);
}

/* ── Stap 1: Scan / Lijst ──────────────────────────────────────── */
.fetch-mode-tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
}
.fetch-mode-tab {
  flex: 1;
  padding: .65rem 1rem;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fetch-mode-tab.active {
  background: rgba(0,95,234,.12);
  border-color: var(--accent);
  color: var(--accent);
}

.open-shipments-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-height: min(55vh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: .75rem;
}
.open-shipments-list.loading {
  opacity: .55;
  pointer-events: none;
}
.open-shipment-item .line-nbr {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
}
.open-shipment-item .line-desc {
  font-size: .85rem;
  color: var(--text-dim);
}
.line-status {
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 600;
  color: var(--warn);
  background: #DDEAFD;
  padding: .15rem .5rem;
  border-radius: 20px;
  border: 1px solid #B3CFF9;
}
.list-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 5rem;
  color: var(--text-dim);
  font-size: .88rem;
  text-align: center;
  padding: 1rem;
}
.list-placeholder-error { color: var(--danger); }
.btn-refresh-list {
  width: 100%;
  margin-top: 0;
}

/* ── Inputs & Buttons ──────────────────────────────────────────── */
.input-row {
  display: flex; gap: .6rem; align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}
.input-row > input[type="text"] {
  min-width: 0;
  flex: 1 1 10rem;
}
input[type="text"] {
  flex: 1; padding: .75rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono); font-size: .88rem;
  outline: none; transition: border-color .2s;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-dim); }

.btn-primary {
  padding: .75rem 1.2rem;
  background: var(--accent); color: #FFFFFF;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font-label); font-size: .85rem; font-weight: 400;
  cursor: pointer; white-space: nowrap;
  transition: opacity .2s, transform .1s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-secondary {
  padding: .75rem 1.2rem;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-label); font-size: .85rem; font-weight: 400;
  cursor: pointer; transition: background .2s;
}
.btn-secondary:hover { background: var(--border); }

.btn-success {
  padding: .75rem 1.4rem;
  background: #FF7900;
  color: #242424; border: none; border-radius: var(--radius-sm);
  font-family: var(--font-label); font-size: .85rem; font-weight: 400;
  cursor: pointer; flex: 1;
  transition: opacity .2s, transform .1s;
  box-shadow: 0 3px 10px rgba(36,36,36,.08);
}
.btn-success:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }
.btn-success:not(:disabled):active { transform: scale(.98); }

.btn-scan-small,
.btn-keyboard-small {
  padding: .7rem; aspect-ratio: 1;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color .2s, border-color .2s;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-scan-small svg,
.btn-keyboard-small svg { width: 20px; height: 20px; }
.btn-scan-small:hover { color: var(--accent); border-color: var(--accent); }
.btn-keyboard-small:hover { color: var(--accent2); border-color: var(--accent2); }

/* ── Shipment Info ─────────────────────────────────────────────── */
.shipment-meta {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
  margin-bottom: 1rem;
  display: flex; flex-wrap: wrap; gap: .5rem 1.4rem;
  font-size: .82rem;
}
.meta-item { display: flex; flex-direction: column; gap: .15rem; }
.meta-key { color: var(--text-dim); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.meta-val {
  font-family: var(--font-mono); font-weight: 700; color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ── Lines List ────────────────────────────────────────────────── */
.lines-list { display: flex; flex-direction: column; gap: .5rem; }

.line-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: .75rem;
  min-width: 0;
}
.line-item:hover { border-color: var(--accent); background: rgba(0,95,234,.05); }
.line-item:active { transform: scale(.99); }

.line-left {
  display: flex; flex-direction: column; gap: .25rem;
  min-width: 0;
  flex: 1 1 auto;
}
.line-nbr { font-family: var(--font-mono); font-size: .8rem; color: var(--text-dim); }
.line-desc {
  font-size: .95rem; font-weight: 500;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.line-inv { font-size: .8rem; color: var(--text-dim); }

.line-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: .25rem;
  flex-shrink: 0;
  text-align: right;
}
.line-qty { font-family: var(--font-mono); font-weight: 700; font-size: 1rem; color: var(--accent); }
.line-serials {
  font-size: .72rem; color: var(--text-dim);
  background: var(--surface); padding: .15rem .5rem;
  border-radius: 20px; border: 1px solid var(--border);
}

/* ── Scan Methods ──────────────────────────────────────────────── */
.scan-methods {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: 1rem;
}
.scan-methods-primary { width: 100%; }
.scan-methods-alt {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}
.btn-method {
  padding: .6rem .5rem;
  background: var(--surface2); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: .8rem; font-weight: 500;
  cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: .3rem;
  transition: all .2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-method svg { width: 18px; height: 18px; }
.btn-method-primary {
  width: 100%;
  flex-direction: row;
  justify-content: center;
  gap: .5rem;
  min-height: 48px;
  padding: .75rem 1rem;
  font-size: .95rem;
  font-weight: 600;
}
.btn-method-primary svg { width: 22px; height: 22px; }
.btn-method-alt {
  flex: 1 1 40%;
  min-width: 0;
  min-height: 44px;
  padding: .45rem .35rem;
  font-size: .72rem;
  opacity: .9;
  gap: .2rem;
}
.btn-method-alt svg { width: 16px; height: 16px; }
.btn-method.active {
  background: rgba(0,95,234,.12);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-method-alt:not(.active) {
  color: var(--text-dim);
  border-color: var(--border);
}

/* ── Camera ────────────────────────────────────────────────────── */
.camera-container {
  position: relative;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 4/3;
  margin-bottom: 1rem;
}
#videoElement {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.scan-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.35);
}
.scan-frame {
  position: relative;
  width: 70%; max-width: 280px;
  aspect-ratio: 2.5/1;
}
.corner {
  position: absolute; width: 22px; height: 22px;
  border-color: var(--accent); border-style: solid; opacity: .9;
}
.corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; }
.corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
.corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; }

.scan-line {
  position: absolute; top: 0; left: 8px; right: 8px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 8px var(--accent);
  animation: scanLine 2s ease-in-out infinite;
}
@keyframes scanLine {
  0%, 100% { top: 0; }
  50% { top: calc(100% - 2px); }
}
.camera-error {
  position: absolute; inset: 0;
  background: rgba(7,35,85,.94);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: .9rem; text-align: center;
  padding: 1rem;
}

/* ── Scanner waiting ───────────────────────────────────────────── */
.scanner-waiting {
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 2rem 1rem;
  text-align: center;
  margin-bottom: 1rem;
}
.scanner-icon {
  width: 48px; height: 48px; margin: 0 auto .8rem;
  color: var(--accent);
}
.scanner-icon svg { width: 100%; height: 100%; }
.scanner-hint { font-size: .82rem; color: var(--text-dim); margin-top: .4rem; }
.scanner-hidden-input {
  position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px;
}

/* ── Selected line info ────────────────────────────────────────── */
.selected-line-info {
  background: rgba(0,95,234,.08);
  border: 1px solid rgba(0,95,234,.25);
  border-radius: var(--radius-sm);
  padding: .7rem 1rem;
  margin-bottom: 1rem;
  font-size: .85rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.selected-line-info strong { color: var(--accent); }

/* ── Serials List ──────────────────────────────────────────────── */
.serials-section { margin-top: 1.2rem; }
.default-qty-toolbar {
  display: flex; align-items: center; justify-content: flex-end; gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .5rem; font-size: .8rem; color: var(--text-dim);
}
.default-qty-toolbar label { white-space: nowrap; }
.default-qty-toolbar input {
  width: 4.2rem; padding: .35rem .5rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-family: var(--font-mono); font-size: .85rem;
  text-align: center;
}
.serials-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .6rem;
  font-size: .82rem; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .06em;
}
.serial-count {
  background: var(--accent); color: #FFFFFF;
  font-family: var(--font-mono); font-size: .75rem; font-weight: 700;
  padding: .15rem .5rem; border-radius: 20px;
  min-width: 24px; text-align: center;
}
.serials-list {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 80px;
  max-height: min(40vh, 220px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.serials-empty {
  display: flex; align-items: center; justify-content: center;
  height: 80px; color: var(--text-dim); font-size: .85rem;
}
.serial-item {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  animation: fadeIn .2s ease;
}
.serial-item:last-child { border-bottom: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.serial-item-main {
  display: flex; align-items: center; gap: .65rem; flex: 1; min-width: 0;
}
.serial-qty-input {
  width: 3.5rem; flex-shrink: 0; padding: .3rem .35rem; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-family: var(--font-mono); font-size: .8rem;
}
.serial-nbr { font-family: var(--font-mono); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }
.line-art {
  font-family: var(--font-mono); font-size: .78rem; font-weight: 600;
  color: var(--accent); display: block; margin: .15rem 0;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.line-left .line-desc { display: block; font-size: .8rem; color: var(--text-dim); }
.serial-time { font-size: .72rem; color: var(--text-dim); }
.btn-remove {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: .2rem; border-radius: 4px;
  transition: color .2s;
}
.btn-remove:hover { color: var(--danger); }
.btn-remove svg { width: 16px; height: 16px; }

/* ── Actions ───────────────────────────────────────────────────── */
.action-row {
  display: flex; gap: .6rem; margin-top: 1.2rem;
  flex-wrap: wrap;
  min-width: 0;
}
.action-row .btn-secondary,
.action-row .btn-success {
  flex: 1 1 8rem;
  min-height: 44px;
}

/* ── Errors & Messages ─────────────────────────────────────────── */
.error-msg {
  background: #FEF3F2;
  border: 1px solid #FECDCA;
  border-radius: var(--radius-sm);
  padding: .7rem 1rem;
  color: var(--danger); font-size: .85rem;
  margin-top: .8rem;
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: max(1.5rem, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1.4rem;
  font-size: .9rem; font-weight: 500;
  box-shadow: 0 8px 32px rgba(7,35,85,.14);
  z-index: 1000;
  transition: opacity .3s, transform .3s;
  white-space: normal;
  line-height: 1.35;
  max-width: min(94vw, 22rem);
  text-align: center;
}
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error   { border-color: var(--danger); color: var(--danger); }
.toast.hidden  { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(10px); }

/* ── Loading ───────────────────────────────────────────────────── */
.loading { opacity: .5; pointer-events: none; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle; margin-right: .4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Helpers ───────────────────────────────────────────────────── */
.hidden { display: none !important; }

@media (max-width: 480px) {
  .card {
    margin: .7rem max(0.5rem, env(safe-area-inset-left)) .7rem max(0.5rem, env(safe-area-inset-right));
    padding: 1.1rem .85rem;
  }
  .scan-methods { gap: .4rem; }
  .btn-method-alt { font-size: .68rem; }
  .line-item {
    flex-direction: column;
    align-items: stretch;
  }
  .line-right {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    text-align: left;
  }
}
.report-actions { margin: 12px 0 20px; display: flex; flex-wrap: wrap; gap: 10px; }

/* AccountOne brand details shared by the scanner and document viewer. */
body { line-height: 1.5; }
h1, h2, h3 { font-family: var(--font-title); font-weight: 600; }
.header-inner { flex-wrap: wrap; }
.header-right { gap: .5rem; flex-wrap: wrap; }
.header-help-link { background: none; border: none; font-family: var(--font-body); cursor: pointer; min-height: 32px; display: inline-flex; align-items: center; letter-spacing: 0; }
.btn-reset-header { min-width: 32px; min-height: 32px; opacity: 1; }
.status-dot { flex-shrink: 0; }
.status-dot.ok { box-shadow: none; animation: none; }
.card { box-shadow: 0 4px 20px rgba(7,35,85,.035); }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid #B3CFF9; outline-offset: 3px; }
.btn-primary:not(:disabled):hover { background: #0053CE; }
.btn-success:not(:disabled):hover { background: #FF9230; }
.btn-secondary[aria-pressed="true"] { color: #003C97; border-color: #005FEA; background: #DDEAFD; }
.report-actions button { max-width: 100%; font-size: .8rem; overflow-wrap: anywhere; white-space: normal; }
.btn-method { font-family: var(--font-label); font-weight: 400; }
.camera-error { color: #FFFFFF; }
@media (min-width: 681px) { .card { margin-left: auto; margin-right: auto; } }
@media (max-width: 480px) {
  .header-inner { padding-left: 1rem; padding-right: 1rem; }
  .logo-image { width: 128px; }
  .app-name { font-size: .95rem; }
  .header-right { margin-left: auto; gap: .35rem; }
  .header-help-link { font-size: .7rem; }
  .btn-reset-header { min-width: 28px; }
  .card { width: calc(100% - 1rem); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
