:root {
  --bg: #000;
  --s1: #0c0c0c;
  --s2: #151515;
  --s3: #1f1f1f;
  --line: #262626;
  --line2: #333;
  --text: #ededed;
  --muted: #8c8c8c;
  --dim: #5c5c5c;
  --white: #fff;
  --st-pending: #6b6b6b;
  --st-transit: #b5b5b5;
  --st-ofd: #f2c14e;
  --st-pickup: #7fb6ff;
  --st-fail: #ff9f5a;
  --st-done: #5fd38d;
  --st-bad: #ff6b6b;
  --r: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--text); }

/* ---------- layout ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px calc(110px + var(--safe-b)); }
header.top {
  position: sticky; top: 0; z-index: 5; background: rgba(0,0,0,.86);
  backdrop-filter: saturate(140%) blur(14px); -webkit-backdrop-filter: saturate(140%) blur(14px);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 0 10px; border-bottom: 1px solid var(--line);
  margin: 0 -16px 14px; padding-left: 16px; padding-right: 16px;
}
.toprow { display: flex; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.2px; flex: 1; }
.brand svg { width: 26px; height: 26px; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line); background: var(--s1);
  display: grid; place-items: center; color: var(--muted);
}
.iconbtn:hover { color: var(--text); border-color: var(--line2); }
.iconbtn svg { width: 19px; height: 19px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.seg { display: flex; background: var(--s1); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-top: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 0; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--s3); color: var(--text); }
.chips { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: none; color: var(--muted); padding: 5px 12px;
  border-radius: 99px; font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--text); color: #000; border-color: var(--text); font-weight: 600; }

.summary { display: flex; gap: 8px; margin: 4px 0 14px; flex-wrap: wrap; }
.sum { background: var(--s1); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.sum b { color: var(--text); font-size: 16px; margin-right: 4px; }

/* ---------- cards ---------- */
.list { display: grid; gap: 10px; }
.card {
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 14px 12px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-align: left; width: 100%;
}
.card:hover { border-color: var(--line2); background: #0f0f0f; }
.card .name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; grid-column: 1 / -1; }
.card .last { grid-column: 1 / -1; color: #c8c8c8; font-size: 13.5px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .when { color: var(--dim); font-size: 12px; grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.badge { border: 1px solid var(--line2); border-radius: 6px; padding: 1px 7px; font-size: 12px; color: #cfcfcf; background: var(--s2); }
.dir { font-size: 12px; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600;
  padding: 3px 10px 3px 8px; border-radius: 99px; background: var(--s2); border: 1px solid var(--line);
  white-space: nowrap; align-self: start;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--st-transit)); }
.st-pending, .st-info_received, .st-expired { --c: var(--st-pending); }
.st-in_transit { --c: var(--st-transit); }
.st-out_for_delivery { --c: var(--st-ofd); }
.st-ready_for_pickup { --c: var(--st-pickup); }
.st-failed_attempt { --c: var(--st-fail); }
.st-delivered { --c: var(--st-done); }
.st-exception, .st-returned { --c: var(--st-bad); }
.warn { color: var(--st-fail); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty svg { width: 54px; height: 54px; color: var(--dim); margin-bottom: 10px; }

.fab {
  position: fixed; right: max(20px, calc(50% - 360px)); bottom: calc(22px + var(--safe-b)); z-index: 6;
  height: 54px; padding: 0 22px 0 18px; border-radius: 27px; border: 0; background: var(--text); color: #000;
  font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
.fab svg { width: 20px; height: 20px; }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--s1);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(22px + var(--safe-b)); animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; border-bottom: 1px solid var(--line); padding-bottom: 22px; }
}
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line2); margin: 4px auto 10px; }
.sheet h2 { margin: 4px 0 14px; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.sheet h2 .x { margin-left: auto; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line2); border-radius: 11px; padding: 11px 12px;
  outline: none; font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: #777; }
textarea { min-height: 76px; resize: vertical; }
input[type=date] { color-scheme: dark; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #888 50%), linear-gradient(135deg, #888 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .3px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detect { margin-top: 6px; font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-height: 20px; }
.detect b { color: var(--text); }
.toggle { display: flex; background: var(--bg); border: 1px solid var(--line2); border-radius: 11px; padding: 3px; }
.toggle button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.toggle button.on { background: var(--s3); color: var(--text); }

.btn { border: 1px solid var(--line2); background: var(--s2); padding: 11px 16px; border-radius: 11px; font-weight: 600; }
.btn:hover { background: var(--s3); }
.btn.primary { background: var(--text); color: #000; border-color: var(--text); }
.btn.danger { color: var(--st-bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.actions .btn { flex: 1; min-width: 120px; }
.err { color: var(--st-bad); font-size: 14px; min-height: 20px; margin: 4px 0; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- detail ---------- */
.dhead { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.num { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 9px 12px; margin: 10px 0; }
.num span { flex: 1; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 14px 20px; border-left: 1px solid var(--line2); margin-left: 4px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--line2); }
.timeline li:first-child::before { background: var(--text); }
.timeline .t { font-size: 14px; }
.timeline .s { font-size: 12px; color: var(--dim); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.authbox { width: 100%; max-width: 360px; background: var(--s1); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px; }
.authbox .brand { justify-content: center; margin-bottom: 6px; font-size: 22px; }
.authbox p { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.userrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.userrow .grow { flex: 1; }
.userrow small { color: var(--muted); }
.mini { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--s3); border: 1px solid var(--line2); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
