:root {
  --navy: #0a1d3d;
  --navy-2: #16386f;
  --gold: #c99a3b;
  --gold-hi: #ecc56d;
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #0f1b2d;
  --muted: #5d6b80;
  --line: #dde3ec;
  --ok: #1d8a4e;
  --bad: #c0392b;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07111f;
    --card: #0f1f38;
    --text: #e8eef8;
    --muted: #93a3bb;
    --line: #22385a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
html { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
/* No double-tap zoom or long-press callouts on controls */
button, label, input, textarea, .chip { touch-action: manipulation; }
button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* While the PIN screen is up the page underneath must not scroll or bounce */
body.locked { position: fixed; inset: 0; overflow: hidden; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.block { display: block; }

/* boot */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--navy); }
.boot img { border-radius: 18px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* lock */
.lock {
  position: fixed; inset: 0; height: 100dvh; overflow: hidden; touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #fff; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
}
.lock button { touch-action: none; }
.lock-inner { width: 100%; max-width: 320px; text-align: center; }
.lock-logo { border-radius: 16px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.lock h1 { margin: 14px 0 4px; font-size: 24px; }
.lock .muted { color: #b9c6dc; min-height: 22px; }
.lock .muted.err { color: #ffb4a8; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: min(22px, 3dvh) 0 min(28px, 4dvh); min-height: 16px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--gold-hi); }
.pin-dots span.on { background: var(--gold-hi); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: min(14px, 2dvh); }
.keypad button {
  /* Sized from the screen height too, so the whole PIN screen fits without scrolling */
  width: min(72px, 20vw, 9.5dvh); aspect-ratio: 1; border-radius: 50%; border: 0; margin: 0 auto; padding: 0;
  background: rgba(255,255,255,.1); color: #fff; font-size: 26px; font-weight: 500;
  transition: background .08s;
}
.keypad button:active, .keypad button.pressed { background: rgba(255,255,255,.28); }
.keypad .key-ok { background: var(--gold); color: var(--navy); }

/* app shell */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--navy); color: #fff;
  padding: calc(10px + var(--safe-t)) 16px 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; }
.brand img { border-radius: 9px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 13px; color: #b9c6dc; }
.demo-badge { margin-left: 8px; background: var(--gold); color: var(--navy); font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 6px; }
.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1; background: none; border: 0; color: #b9c6dc; padding: 10px 0 12px;
  font-weight: 600; border-bottom: 3px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: var(--gold-hi); }

.view { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 14px 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(10,29,61,.06); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-label { display: block; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.big-input, .input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: transparent; color: var(--text);
  font: inherit; padding: 12px 14px; outline: none;
}
.big-input { font-size: 26px; font-weight: 600; letter-spacing: .02em; padding: 12px 14px; font-variant-numeric: tabular-nums; }
.input { margin-top: 10px; font-size: 16px; resize: vertical; }
.big-input:focus, .input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,154,59,.2); }
.big-input.invalid { border-color: var(--bad); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; scrollbar-width: none; }
.chips:empty { display: none; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 14px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.chip b { font-weight: 600; }

.add-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 10px; margin-top: 6px; }
.add-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1.5px dashed var(--line); border-radius: 14px; padding: 14px 6px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.add-btn svg { width: 28px; height: 28px; }
.add-btn.primary-add { background: var(--navy); color: #fff; border: 0; }
.add-btn.primary-add svg { color: var(--gold-hi); }
@media (prefers-color-scheme: dark) {
  .add-btn.primary-add { background: var(--gold); color: var(--navy); }
  .add-btn.primary-add svg { color: var(--navy); }
}
.add-btn:active { transform: scale(.97); }

.pages { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.page { display: flex; gap: 12px; align-items: center; border: 1.5px solid var(--line); border-radius: 14px; padding: 8px; }
.page .thumb {
  width: 64px; height: 84px; flex: none; border-radius: 8px; background: #f3f5f9 center/cover no-repeat;
  border: 1px solid var(--line); display: grid; place-items: center; color: var(--bad); font-weight: 800; font-size: 13px;
}
.page .meta { flex: 1; min-width: 0; }
.page .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page .sub { font-size: 13px; color: var(--muted); }
.page .tools { display: flex; gap: 2px; margin-top: 6px; flex-wrap: wrap; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); line-height: 0; }
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.danger { color: var(--bad); }
.filter-btn { border: 1.5px solid var(--line); background: none; border-radius: 8px; font-size: 12px; font-weight: 700; padding: 4px 8px; margin-right: 4px; }
.page.busy .thumb { opacity: .4; }

.empty { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0 2px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch-row .field-label { margin-bottom: 2px; }
.switch { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .2s; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--gold); }
.switch:checked::after { transform: translateX(20px); }

.spacer { height: calc(90px + var(--safe-b)); }

.sendbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
}
.send-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 608px; margin: 0 auto; height: 58px; border: 0; border-radius: 16px;
  background: var(--gold); color: var(--navy); font-size: 18px; font-weight: 800;
  box-shadow: 0 6px 18px rgba(201,154,59,.35);
}
.send-btn:disabled { background: var(--line); color: var(--muted); box-shadow: none; }
.send-btn:not(:disabled):active { transform: scale(.98); }

/* history */
.history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.link-btn { background: none; border: 0; color: var(--gold); font-weight: 700; padding: 6px 0; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hist { background: var(--card); border-radius: 14px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; }
.hist .meta { flex: 1; min-width: 0; }
.hist .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist .sub { font-size: 13px; color: var(--muted); }
.hist .reason { font-size: 13px; color: var(--bad); margin-top: 2px; }
.pill { font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 999px; white-space: nowrap; background: #e8edf5; color: #45556e; }
.pill.ok { background: #dff3e7; color: var(--ok); }
.pill.bad { background: #fbe3e0; color: var(--bad); }
.pill.wip { background: #fff1d6; color: #8a6418; }
.signout { display: block; margin: 26px auto 8px; color: var(--muted); }
.app-version { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.lock .app-version { color: rgba(255,255,255,.45); margin-top: min(18px, 2.5dvh); }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(5,12,25,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px; background: var(--card); border-radius: 22px 22px 0 0;
  padding: 26px 22px calc(22px + var(--safe-b)); text-align: center; animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 10px 0 4px; font-size: 22px; }
.status-icon { width: 64px; height: 64px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: #fff1d6; color: #8a6418; }
.status-icon svg { width: 34px; height: 34px; stroke-width: 2.4; }
.status-icon.ok { background: #dff3e7; color: var(--ok); }
.status-icon.bad { background: #fbe3e0; color: var(--bad); }
.status-icon .spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { list-style: none; padding: 0; margin: 18px auto 6px; max-width: 280px; text-align: left; }
.steps li { position: relative; padding: 6px 0 6px 30px; color: var(--muted); }
.steps li::before { content: ""; position: absolute; left: 4px; top: 10px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); }
.steps li.active { color: var(--text); font-weight: 700; }
.steps li.active::before { border-color: var(--gold); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps li.done { color: var(--text); }
.steps li.done::before { background: var(--ok); border-color: var(--ok); }
.steps li.failed { color: var(--bad); font-weight: 700; }
.steps li.failed::before { background: var(--bad); border-color: var(--bad); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px auto 0; max-width: 280px; }
.progress div { height: 100%; width: 0; background: var(--gold); transition: width .2s; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.sheet-actions button { height: 52px; border-radius: 14px; border: 0; font-weight: 700; font-size: 17px; }
.sheet-actions .primary { background: var(--gold); color: var(--navy); }
.sheet-actions .secondary { background: var(--line); color: var(--text); }

/* live scanner */
.scanner {
  position: fixed; inset: 0; z-index: 24; background: #000; color: #fff;
  display: flex; flex-direction: column; height: 100dvh; touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
.scan-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#scanVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#scanSvg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#scanPoly { fill: rgba(236,197,109,.18); stroke: var(--gold-hi); stroke-width: 3; stroke-linejoin: round; transition: opacity .15s; }
#scanPoly.steady { fill: rgba(29,138,78,.25); stroke: #4cd68a; }
.scan-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scan-flash.on { opacity: .85; transition: none; }
.scan-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.scan-fallback .crop-btn { flex: none; width: 100%; max-width: 300px; }
.scan-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 14px 20px calc(16px + var(--safe-b));
}
.scan-bar .crop-link { justify-self: start; }
.scan-count { justify-self: end; font-size: 13px; color: #b9c6dc; }
.shutter {
  width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 5px; touch-action: manipulation;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .4; }

/* crop editor */
.cropper {
  position: fixed; inset: 0; z-index: 25; background: #05090f; color: #fff;
  display: flex; flex-direction: column; height: 100dvh; touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
.crop-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
}
.crop-hint { font-size: 13px; color: #b9c6dc; text-align: center; flex: 1; }
.crop-link { background: none; border: 0; color: var(--gold-hi); font-weight: 700; font-size: 15px; padding: 8px 4px; white-space: nowrap; }
.crop-stage { position: relative; flex: 1; min-height: 0; margin: 0 14px; }
.crop-stage canvas#cropCanvas { position: absolute; }
#cropSvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#cropShade { fill: rgba(0,0,0,.55); }
#cropPoly { fill: rgba(236,197,109,.12); stroke: var(--gold-hi); stroke-width: 2.5; stroke-linejoin: round; }
.crop-handle {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; touch-action: none; cursor: grab;
}
.crop-handle::after {
  content: ""; position: absolute; inset: 11px; border-radius: 50%;
  background: rgba(236,197,109,.35); border: 3px solid var(--gold-hi); box-shadow: 0 0 0 1px rgba(0,0,0,.4);
}
.crop-loupe {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 3px solid var(--gold-hi); box-shadow: 0 6px 20px rgba(0,0,0,.6); pointer-events: none; background: #000;
}
.crop-bar { display: flex; gap: 10px; padding: 12px 14px calc(12px + var(--safe-b)); }
.crop-btn { flex: 1; height: 52px; border-radius: 14px; border: 0; font-weight: 800; font-size: 16px; }
.crop-btn.primary { background: var(--gold); color: var(--navy); }
.crop-btn.secondary { background: rgba(255,255,255,.12); color: #fff; }

.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; background: #fff; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 40;
  background: #1b2a42; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
