:root {
  --bg: #000000;
  --surface: #0c0c0c;
  --surface-2: #151515;
  --line: #242424;
  --line-2: #333333;
  --text: #f4f4f2;
  --muted: #8d8d88;
  --faint: #5c5c58;

  --new: #8fb3ff;
  --wait: #f2b84b;
  --move: #c69cff;
  --here: #ff8a5b;
  --pay: #ff6b8a;
  --done: #63d68f;
  --danger: #ff5a5f;
  --money: #e9f5c9;

  --r: 16px;
  --r-sm: 10px;
  --tap: 52px;
  --gutter: 16px;
  font-synthesis: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* never below 16px: iOS zooms */
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(0,0,0,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 800; letter-spacing: -.02em; font-size: 18px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 6px; }
.sync { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--done); display: inline-block; }
.dot.stale { background: var(--wait); }
.dot.err { background: var(--danger); }

.search {
  margin-top: 10px; display: flex; gap: 8px;
}
.search input {
  flex: 1; min-width: 0; height: var(--tap);
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 0 16px; outline: none;
}
.search input:focus { border-color: var(--text); }
.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px;
  cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- layout ---------- */
main { padding: 14px var(--gutter) 24px; max-width: 760px; margin: 0 auto; }
h2.section {
  font-size: 13px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700; margin: 26px 0 10px;
  display: flex; align-items: baseline; gap: 8px;
}
h2.section .count { color: var(--text); }

/* ---------- money strip ---------- */
.money {
  display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px;
}
@media (min-width: 620px) { .money { grid-template-columns: repeat(4, minmax(0,1fr)); } }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; min-width: 0; text-align: left; cursor: pointer;
}
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 750; letter-spacing: -.02em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .n { font-size: 12px; color: var(--faint); margin-top: 2px; }
.tile.alert .v { color: var(--pay); }
.tile.warn .v { color: var(--wait); }

/* ---------- pipeline ---------- */
.pipe {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter);
}
.pipe::-webkit-scrollbar { display: none; }
.stage {
  flex: none; min-width: 104px; padding: 10px 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; text-align: left;
}
.stage .c { font-size: 24px; font-weight: 800; line-height: 1.1; }
.stage .l { font-size: 12px; color: var(--muted); white-space: nowrap; }
.stage.on { border-color: var(--text); background: var(--surface-2); }
.stage[data-s="new"] .c { color: var(--new); }
.stage[data-s="pickup"] .c { color: var(--wait); }
.stage[data-s="transit"] .c { color: var(--move); }
.stage[data-s="warehouse"] .c { color: var(--here); }
.stage[data-s="settle"] .c { color: var(--pay); }
.stage[data-s="done"] .c { color: var(--done); }

/* ---------- case cards ---------- */
.cards { display: grid; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; display: grid; grid-template-columns: 56px 1fr; gap: 12px;
  cursor: pointer; position: relative; text-align: left; width: 100%;
}
.card:active { transform: scale(.992); }
.card .thumb {
  width: 56px; height: 70px; border-radius: 10px; background: var(--surface-2) center/cover no-repeat;
}
.card .body { min-width: 0; }
.card .l1 { display: flex; gap: 8px; align-items: baseline; }
.card .order { font-weight: 800; font-size: 17px; }
.card .who { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.card .amt { margin-left: auto; font-weight: 700; white-space: nowrap; }
.card .l2 { font-size: 14px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .next {
  margin-top: 8px; font-size: 14px; font-weight: 650;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap;
}
.pill.new { color: var(--new); border-color: color-mix(in srgb, var(--new) 40%, transparent); }
.pill.pickup { color: var(--wait); border-color: color-mix(in srgb, var(--wait) 40%, transparent); }
.pill.transit { color: var(--move); border-color: color-mix(in srgb, var(--move) 40%, transparent); }
.pill.warehouse { color: var(--here); border-color: color-mix(in srgb, var(--here) 40%, transparent); }
.pill.settle { color: var(--pay); border-color: color-mix(in srgb, var(--pay) 40%, transparent); }
.pill.done { color: var(--done); border-color: color-mix(in srgb, var(--done) 40%, transparent); }
.pill.flag { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.card .edge { position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; }

.empty {
  border: 1px dashed var(--line-2); border-radius: var(--r); padding: 22px; text-align: center; color: var(--muted);
}

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(0,0,0,.94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.nav button {
  background: none; border: 0; height: 58px; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; align-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 650;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--text); }
.nav .scan-btn { color: var(--bg); }
.nav .scan-btn span.ring {
  width: 54px; height: 44px; border-radius: 14px; background: var(--text); display: grid; place-items: center;
}

/* ---------- sheet (case detail / dialogs) ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.66); z-index: 40;
  animation: fade .15s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: #0a0a0a; border-top: 1px solid var(--line-2);
  border-radius: 22px 22px 0 0;
  padding: 8px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  animation: up .22s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 760px) {
  .sheet { left: 50%; width: 720px; transform: translateX(-50%); animation: none; }
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 4px auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .4 } to { transform: none; opacity: 1 } }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.d-head { display: flex; gap: 14px; align-items: flex-start; }
.d-head .thumb { width: 78px; height: 98px; border-radius: 12px; background: var(--surface-2) center/cover no-repeat; flex: none; }
.d-head h3 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.d-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.close-x { margin-left: auto; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; margin-top: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-top: 12px; }
.box h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.line-item { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.line-item:first-of-type { border-top: 0; padding-top: 0; }
.line-item .thumb { width: 44px; height: 55px; border-radius: 8px; background: var(--surface-2) center/cover no-repeat; flex: none; }
.line-item .t { min-width: 0; flex: 1; }
.line-item .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-item .t span { font-size: 14px; color: var(--muted); }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { position: relative; padding: 0 0 14px 22px; font-size: 15px; }
.tl li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); }
.tl li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.tl li:last-child::after { display: none; }
.tl li.ok::before { background: var(--done); }
.tl li.now::before { background: var(--here); box-shadow: 0 0 0 4px color-mix(in srgb, var(--here) 25%, transparent); }
.tl li.bad::before { background: var(--danger); }
.tl li small { display: block; color: var(--muted); font-size: 13px; }

/* actions */
.actions { display: grid; gap: 10px; margin-top: 16px; }
.btn {
  height: var(--tap); border-radius: 14px; border: 1px solid var(--line-2);
  background: var(--surface-2); font-weight: 700; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; width: 100%;
}
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.good { background: var(--done); color: #00170a; border-color: var(--done); }
.btn.warn { background: var(--wait); color: #1d1300; border-color: var(--wait); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* hold-to-confirm for money */
.hold { position: relative; overflow: hidden; }
.hold .fill { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: rgba(0,0,0,.18); pointer-events: none; }
.hold.holding .fill { transition: transform 1.1s linear; transform: scaleX(1); }
.hold span { position: relative; }

/* forms */
.field { display: grid; gap: 6px; margin-top: 12px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 650; }
.field input, .field select, .field textarea {
  height: var(--tap); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 12px; padding: 0 14px; outline: none; width: 100%;
}
.field textarea { height: 90px; padding: 12px 14px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--text); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; border: 1px solid var(--line-2); }
.seg button { height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--text); color: var(--bg); }

.big-amt { font-size: 40px; font-weight: 800; letter-spacing: -.03em; margin: 6px 0 2px; }
.note { font-size: 14px; color: var(--muted); margin-top: 8px; }
.warnbox { border: 1px solid color-mix(in srgb, var(--wait) 45%, transparent); background: color-mix(in srgb, var(--wait) 8%, transparent); color: #ffe1a6; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.errbox { border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); background: color-mix(in srgb, var(--danger) 9%, transparent); color: #ffc2c4; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); font-weight: 700; padding: 12px 18px; border-radius: 14px; max-width: calc(100vw - 32px);
  animation: up .2s ease;
}
.toast.err { background: var(--danger); color: #fff; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.login form { width: 100%; max-width: 360px; }
.login h1 { font-size: 30px; letter-spacing: -.03em; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 18px; }
.who-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.who-pick button { height: 64px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 750; cursor: pointer; }
.who-pick button.on { border-color: var(--text); background: var(--surface-2); }

/* scanner */
.scanner { position: fixed; inset: 0; z-index: 70; background: #000; display: grid; grid-template-rows: auto 1fr auto; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 10%; right: 10%; top: 38%; height: 22%; border: 2px solid var(--text); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); pointer-events: none; }
.scanner .bar { padding: calc(14px + env(safe-area-inset-top)) var(--gutter) 14px; display: flex; align-items: center; gap: 10px; position: relative; z-index: 2; }
.scanner .foot { padding: 14px var(--gutter) calc(18px + env(safe-area-inset-bottom)); position: relative; z-index: 2; }
.scanner .stage-wrap { position: relative; overflow: hidden; }

/* activity */
.act { display: grid; gap: 2px; }
.act-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.act-row small { color: var(--muted); grid-column: 1 / -1; font-size: 13px; }

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

/* ---------- to-do home ---------- */
.summary { margin: 6px 0 4px; }
.summary .big { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.summary .muted { font-size: 14px; margin-top: 4px; }
.grp h2.section { align-items: center; }
.gsub { color: var(--muted); font-size: 14px; margin: -4px 0 12px; }
.tasks { display: grid; gap: 10px; }
.task { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; transition: opacity .2s; }
.task.busy, .box.busy { opacity: .5; }
.task-main { display: grid; grid-template-columns: 52px 1fr; gap: 12px; width: 100%; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.task .thumb { width: 52px; height: 64px; border-radius: 10px; background: var(--surface-2) center/cover no-repeat; }
.tb { min-width: 0; }
.tt { font-weight: 750; font-size: 17px; line-height: 1.25; letter-spacing: -.01em; }
.ts { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td { font-size: 14px; color: #c9c9c4; margin-top: 4px; overflow-wrap: anywhere; }
.tbtns { display: flex; gap: 8px; margin-top: 12px; }
.tbtns .btn { flex: 1; min-width: 0; height: 50px; font-size: 15px; padding: 0 10px; text-decoration: none; }
.tbtns .btn:not(:only-child) em { display: none; }
.btn em { font-style: normal; font-size: 10px; font-weight: 800; opacity: .5; text-transform: uppercase; letter-spacing: .08em; position: relative; }
.btn.hold:not(.primary):not(.good):not(.warn) .fill { background: rgba(255,255,255,.14); }
.btn.danger.hold .fill { background: rgba(255,90,95,.22); }
.grp-act { margin-left: auto; width: auto; height: 36px; font-size: 13px; padding: 0 12px; text-transform: none; letter-spacing: 0; }
.waiting { width: 100%; text-align: left; background: none; border: 1px dashed var(--line-2); color: var(--muted); border-radius: var(--r); padding: 14px 16px; font-size: 15px; line-height: 1.4; cursor: pointer; margin-top: 28px; }
.todo-box { border-color: var(--line-2); }
details.more { margin-top: 12px; }
details.more summary { color: var(--muted); font-size: 14px; cursor: pointer; padding: 8px 2px; list-style: none; }
details.more summary::before { content: "+ "; }
details.more[open] summary::before { content: "− "; }
a.btn { text-decoration: none; }
.tbtns { flex-wrap: wrap; }
.tbtns .btn { flex: 1 1 calc(50% - 4px); }
