/* Phone-first, high contrast, big targets: used in a warehouse, often one-handed.
   Mirabella brand: plum #6D2F48, blush #EBDAD2, mist #E9E5E8, white; Amiri + Montserrat.
   Green / red / amber stay for scan results: they mean "done", "wrong", "look". */
@font-face { font-family: "Montserrat"; src: url("/fonts/Montserrat-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Amiri"; src: url("/fonts/Amiri-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }

:root {
  --plum: #6D2F48;
  --blush: #EBDAD2;
  --mist: #E9E5E8;
  --bg: var(--mist);
  --panel: #ffffff;
  --line: #d6cad0;
  --text: #2b1621;
  --muted: #6b5862;
  --accent: var(--plum);    /* plum: the "do this" color */
  --on-accent: #ffffff;
  --ok: #13834a;
  --bad: #c62828;
  --warn: #a86a00;
  --radius: 14px;
  --tap: 52px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --font: "Montserrat", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-display: "Amiri", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1217; --panel: #281a21; --line: #45313b; --text: #f6eef1; --muted: #bba8b1;
    --accent: var(--blush); --on-accent: #4a1f31; --ok: #3ccf7a; --bad: #ff6b6b; --warn: #f2b33d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1217; --panel: #281a21; --line: #45313b; --text: #f6eef1; --muted: #bba8b1;
  --accent: var(--blush); --on-accent: #4a1f31; --ok: #3ccf7a; --bad: #ff6b6b; --warn: #f2b33d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.4 var(--font);
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  -webkit-tap-highlight-color: transparent;
}
h2 { font: 400 1.45rem/1.2 var(--font-display); margin: 0 0 .5rem; }
strong, b { font-weight: 700; }
code, .mono { font-family: var(--font-mono); }

/* ---------------------------------------------------------------- launch screen */
.splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-content: center; justify-items: center; gap: 20px;
  background: var(--plum);
  transition: opacity 280ms var(--ease-out);
}
.splash-mark { width: min(62vw, 300px); height: auto; animation: splash-in 600ms var(--ease-out) both; }
.splash-disc { fill: #ffffff; }
/* The logo is one shape (the swash joins the rings), so it stays whole; the arc around it is what moves. */
.splash-logo { fill: var(--plum); transform-box: fill-box; transform-origin: 50% 100%; animation: splash-rise 700ms var(--ease-out) 180ms both; }
/* Constant motion while waiting on the network: linear, so it reads as "working", not as an event. */
.splash-orbit {
  fill: none; stroke: var(--blush); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 18 82;
  transform-box: view-box; transform-origin: 400px 400px;
  animation: splash-turn 1.6s linear infinite, splash-fade 400ms var(--ease-out) 300ms both;
}
.splash-status {
  margin: 0; color: var(--blush); font: 400 .78rem var(--font);
  letter-spacing: .32em; text-transform: uppercase; text-indent: .32em;
  animation: splash-fade 400ms var(--ease-out) 500ms both;
}
.splash.done { opacity: 0; pointer-events: none; }

@keyframes splash-in   { from { opacity: 0; transform: scale(.94); } }
@keyframes splash-rise { from { opacity: 0; transform: translateY(6%); } }
@keyframes splash-fade { from { opacity: 0; } }
@keyframes splash-turn { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .splash-mark { animation-name: splash-fade; }
  .splash-logo { animation-name: splash-fade; }
  .splash-orbit { stroke-dasharray: none; opacity: .5; animation: splash-pulse 1.2s ease-in-out infinite alternate; }
}
@keyframes splash-pulse { to { opacity: .15; } }

/* ----------------------------------------------------------------------- top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 8px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.brand-name { font: 400 1.35rem/1.05 var(--font-display); color: var(--text); }
.brand-name span { color: var(--muted); }
.sync { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.sync.ok .dot { background: var(--ok); }
.sync.pending .dot { background: var(--warn); }
.sync.offline .dot { background: var(--bad); }

.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 14px; }
.modes button {
  min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); font: inherit; font-size: .86rem; font-weight: 700;
}
.modes button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.scan label { display: block; font-weight: 700; font-size: 1.1rem; color: var(--text); margin-bottom: 6px; }
.scan-row { display: flex; gap: 8px; }
#scan {
  flex: 1; min-width: 0; height: 64px; padding: 0 16px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--panel); color: var(--text);
  font: 600 1.4rem var(--font-mono); letter-spacing: .04em;
}
#scan:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 1.3rem;
}
.icon-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.who {
  min-height: var(--tap); max-width: 9.5em; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 700; font-size: .9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --------------------------------------------------------------- lock screen (lock.js) */
.lock {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.lock[hidden] { display: none; }
.lock-card { max-width: 480px; margin: 0 auto; display: grid; gap: 12px; }
.lock-card h2 { font-size: 1.8rem; text-align: center; margin: 12px 0 0; }
.lock-card > .hint { text-align: center; margin: 0; }
.lock-msg { min-height: 1.4em; margin: 0; text-align: center; font-weight: 700; color: var(--muted); }
.lock-msg.bad { color: var(--bad); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  min-height: 64px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-weight: 700; font-size: 1.05rem; line-height: 1.2;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.tile:active, .keypad button:active { background: var(--accent); color: var(--on-accent); }
.dots { display: flex; justify-content: center; gap: 14px; margin: 4px 0; }
.dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); }
.dots span.on { background: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  min-height: 64px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: 600 1.6rem var(--font);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.keypad .key-text { font-size: 1rem; color: var(--muted); }
@media (hover: hover) {
  .tile:hover, .keypad button:hover { border-color: var(--accent); }
}

.flash {
  margin: 12px 0; padding: 14px 16px; border-radius: var(--radius); font-weight: 700;
  border: 2px solid var(--line); background: var(--panel);
}
.flash.ok { border-color: var(--ok); }
.flash.bad { border-color: var(--bad); }
.flash .big { display: block; font: 800 2rem var(--font-mono); letter-spacing: .03em; margin-top: 2px; }

.warn-bar {
  margin: 10px 0 0; padding: 10px 14px; border-radius: var(--radius); font-weight: 700; font-size: .95rem;
  border: 2px solid var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--panel));
}

section { margin-top: 14px; }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0 10px; }
.small { font-size: .8rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.card.warn { border-color: var(--warn); }
.card.bad { border-color: var(--bad); }
.card h3 { margin: 0 0 4px; font-size: 1.1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 8px 0 0; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); margin-bottom: 8px;
}
.list li .meta { color: var(--muted); font-size: .85rem; }
.list li.voided { opacity: .5; text-decoration: line-through; }
.list.pick li { cursor: pointer; min-height: var(--tap); }
.list.pick li:active { border-color: var(--accent); }

.pill { font-size: .76rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.pill.warn { color: var(--warn); border-color: var(--warn); }

label { display: block; color: var(--muted); font-size: .88rem; }
input, select {
  width: 100%; min-height: var(--tap); margin-top: 4px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; }
.row select { flex: 1; }
.row.end { justify-content: flex-end; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

button { font: inherit; cursor: pointer; }
button.primary, button.ghost, a.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; font-weight: 700;
}
button.primary, a.btn.primary { background: var(--accent); color: var(--on-accent); border: 0; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost.small { min-height: 44px; padding: 0 12px; margin-top: 4px; }
button.danger { border-color: var(--bad); color: var(--bad); }
button:disabled { opacity: .5; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text);
  width: min(92vw, 420px); padding: 18px;
}
dialog::backdrop { background: color-mix(in srgb, var(--plum) 55%, transparent); }
dialog label { margin-bottom: 12px; }

/* Area name under a shelf/unit code, and the one-card-per-level unit view. */
.area { font-weight: 700; color: var(--accent); margin: 2px 0 4px; }
.card.level { padding: 4px 12px 8px; }
.card.level .list { margin-top: 2px; }
.card.level .list li { margin-bottom: 6px; }
.level-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%;
  min-height: var(--tap); padding: 0; background: none; border: 0; color: inherit; text-align: left;
}
.level-head .meta { color: var(--muted); font-size: .85rem; }
