:root {
  --red: #d2232a;
  --red-dark: #a8181e;
  --ink: #16181c;
  --ink-2: #4a4f57;
  --ink-3: #7b8089;
  --bg: #f3f2ef;
  --card: #ffffff;
  --line: #e2e0db;
  --soft: #ecebe7;
  --overdue: #b3121a;
  --final: #d9480f;
  --due: #b8740a;
  --notice: #1f5fa8;
  --ok: #1e7a46;
  --stock: #5b6470;
  --returned: #6b46c1;
  --disposed: #3a3d42;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 24, 28, .06), 0 4px 14px rgba(22, 24, 28, .05);
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px calc(10px);
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink); color: #fff;
  border-bottom: 4px solid var(--red);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  background: var(--red); color: #fff; font-family: var(--cond); font-weight: 700;
  font-size: 20px; letter-spacing: 1px; padding: 3px 8px 1px; border-radius: 4px; line-height: 1.1;
}
.brand-text { font-family: var(--cond); font-weight: 700; font-size: 22px; letter-spacing: 1.5px; line-height: 1; }
.brand-text small { display: block; font-family: var(--body); font-weight: 500; font-size: 11px; letter-spacing: .3px; color: #b9bcc2; margin-top: 3px; }
.icon-btn { background: transparent; border: 1px solid #3a3d42; color: #fff; border-radius: 8px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:active { transform: scale(.96); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.page-title { font-family: var(--cond); font-size: 28px; text-transform: uppercase; letter-spacing: .5px; margin: 6px 0 4px; }
.page-sub { color: var(--ink-2); margin: 0 0 16px; font-size: 14px; }
.section-title { font-family: var(--cond); font-size: 19px; text-transform: uppercase; letter-spacing: .6px; margin: 26px 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title .count { font-family: var(--body); font-size: 13px; color: var(--ink-3); text-transform: none; letter-spacing: 0; font-weight: 500; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 8px; text-decoration: none; color: var(--ink-3); font-size: 12px; font-weight: 600;
  border-top: 3px solid transparent;
}
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bottom-nav a.active { color: var(--red); border-top-color: var(--red); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 12px;
  text-decoration: none; border-left: 5px solid var(--c, var(--stock)); display: block;
}
.tile .num { font-family: var(--cond); font-size: 38px; font-weight: 700; line-height: 1; color: var(--c, var(--ink)); }
.tile .lbl { font-weight: 600; font-size: 14px; margin-top: 4px; }
.tile .hint { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.tile.alarm { background: var(--overdue); color: #fff; border-left-color: #6d0a0f; }
.tile.alarm .num, .tile.alarm .hint { color: #fff; }

/* ---------- Alert rule strip ---------- */
.rules { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.rules div { padding: 10px 10px 9px; color: #fff; font-size: 12px; line-height: 1.3; }
.rules b { display: block; font-family: var(--cond); font-size: 15px; letter-spacing: .4px; text-transform: uppercase; }
@media (max-width: 520px) { .rules { grid-template-columns: 1fr 1fr; } }

/* ---------- Lifter cards ---------- */
.list { display: grid; gap: 10px; }
@media (min-width: 820px) { .list.two { grid-template-columns: 1fr 1fr; } }
.lifter {
  display: block; text-decoration: none; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 13px 14px 12px; position: relative; overflow: hidden;
  border-left: 5px solid var(--c, var(--stock));
}
.lifter:active { transform: scale(.995); }
.lifter-top { display: flex; align-items: center; gap: 8px; }
.serial { font-family: var(--mono); font-weight: 700; font-size: 17px; letter-spacing: .3px; word-break: break-all; }
.size-badge {
  font-family: var(--cond); font-weight: 700; font-size: 14px; letter-spacing: .5px;
  border: 2px solid var(--ink); border-radius: 5px; padding: 0 6px; line-height: 1.35;
}
.size-badge.m30 { background: var(--ink); color: #fff; }
.lifter-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.lifter-meta span { display: inline-flex; gap: 4px; align-items: center; }
.days { margin-left: auto; text-align: right; font-family: var(--cond); font-weight: 700; font-size: 20px; color: var(--c, var(--ink)); line-height: 1; white-space: nowrap; }
.days small { display: block; font-family: var(--body); font-size: 11px; font-weight: 600; color: var(--ink-3); letter-spacing: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c, var(--stock)) 13%, white);
  color: var(--c, var(--stock)); white-space: nowrap; letter-spacing: .2px;
}
.chip.solid { background: var(--c); color: #fff; }

.lifebar { height: 6px; border-radius: 4px; background: var(--soft); margin-top: 10px; overflow: hidden; position: relative; }
.lifebar i { display: block; height: 100%; background: var(--c, var(--ok)); border-radius: 4px; }
.lifebar::after { content: ''; position: absolute; top: 0; bottom: 0; left: 95.8%; width: 2px; background: rgba(22, 24, 28, .25); }

/* stage colour hooks */
.s-overdue { --c: var(--overdue); }
.s-final { --c: var(--final); }
.s-due { --c: var(--due); }
.s-notice { --c: var(--notice); }
.s-ok { --c: var(--ok); }
.s-stock { --c: var(--stock); }
.s-returned { --c: var(--returned); }
.s-disposed { --c: var(--disposed); }
.lifter.s-disposed { opacity: .72; }

/* ---------- Filters ---------- */
.searchbar { position: relative; }
.searchbar input { padding-left: 40px; }
.searchbar svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--ink-3); fill: none; stroke-width: 2; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.fchip {
  flex: none; border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2);
}
.fchip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.fchip .n { opacity: .6; margin-left: 4px; font-weight: 500; }
.filters { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 6px; }

/* ---------- Forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; letter-spacing: .2px; }
label.field > em { display: block; font-style: normal; font-size: 12px; color: var(--ink-3); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; background: #fff; border: 1.5px solid #d6d4ce; border-radius: 10px; padding: 11px 12px; font-size: 16px; min-height: 46px;
}
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(22, 24, 28, .1); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2.collapse { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--red); flex: none; margin: 0; }

.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 16px; border-radius: 8px; font-weight: 700; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.big button { font-family: var(--cond); font-size: 20px; padding: 6px 22px; letter-spacing: .5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: 10px; border: 0; cursor: pointer;
  font-weight: 700; font-size: 15px; background: var(--ink); color: #fff; text-decoration: none; letter-spacing: .2px;
}
.btn:active { transform: scale(.98); }
.btn.red { background: var(--red); }
.btn.red:hover { background: var(--red-dark); }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid #d6d4ce; }
.btn.purple { background: var(--returned); }
.btn.danger { background: var(--overdue); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.actions .btn:only-child { grid-column: 1 / -1; }

/* ---------- Detail ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--ink-2); text-decoration: none; font-size: 14px; margin-bottom: 8px; }
.hero { background: var(--ink); color: #fff; border-radius: var(--radius); padding: 18px 16px 16px; position: relative; overflow: hidden; }
.hero::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c, var(--stock)); }
.hero .serial { font-size: 24px; }
.hero .size-badge { border-color: #fff; }
.hero .size-badge.m30 { background: #fff; color: var(--ink); }
.hero .big-days { font-family: var(--cond); font-size: 44px; font-weight: 700; line-height: 1; margin-top: 14px; color: #fff; }
.hero .big-days small { font-family: var(--body); font-size: 14px; font-weight: 500; color: #b9bcc2; display: block; margin-top: 4px; }
.hero .chip { background: var(--c); color: #fff; }
.hero .lifebar { background: #33363c; }
.hero .lifebar::after { background: rgba(255, 255, 255, .5); }
.timeline-dates { display: flex; justify-content: space-between; font-size: 12px; color: #b9bcc2; margin-top: 6px; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.facts div { padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts div:nth-child(odd) { padding-right: 10px; }
.facts dt { font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.facts dd { margin: 2px 0 0; font-weight: 600; word-break: break-word; }

.history { list-style: none; margin: 0; padding: 0; }
.history li { position: relative; padding: 0 0 14px 22px; }
.history li::before { content: ''; position: absolute; left: 5px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--ink); }
.history li::after { content: ''; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.history li:last-child::after { display: none; }
.history li.alert::before { background: var(--final); }
.history li.dispose::before { background: var(--disposed); border-radius: 2px; }
.history b { display: block; font-size: 14px; }
.history p { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); }
.history time { font-size: 12px; color: var(--ink-3); }

/* ---------- Settings tables ---------- */
.trow { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }
.trow .who { flex: 1; min-width: 0; }
.trow .who b { display: block; font-size: 15px; }
.trow .who span { font-size: 13px; color: var(--ink-3); word-break: break-all; }
.trow select { width: auto; min-height: 36px; padding: 5px 8px; font-size: 14px; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #c9c7c1; border-radius: 999px; transition: .15s; cursor: pointer; }
.switch i::after { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(18px); }
.status-line { display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 6px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.bad { background: var(--overdue); }
.log { font-size: 13px; }
.log div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log div:last-child { border: 0; }

/* ---------- Empty / banners ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.banner { border-radius: 10px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: #fff4e0; color: #7a4b00; }
.banner.bad { background: #fde8e8; color: #8a1016; }
.banner.info { background: #e8f0fa; color: #173f6e; }

/* ---------- Auth ---------- */
.auth { max-width: 420px; margin: 28px auto 0; }
.auth .card { padding: 22px 20px; }
.auth h1 { font-family: var(--cond); text-transform: uppercase; font-size: 30px; margin: 0 0 4px; }
.auth p { color: var(--ink-2); margin: 0 0 18px; font-size: 14px; }
.auth .switch-link { text-align: center; margin-top: 16px; font-size: 14px; }
.auth .switch-link a { color: var(--red); font-weight: 700; }
.err { color: var(--overdue); font-size: 14px; font-weight: 600; min-height: 1em; }

/* ---------- Bottom sheet dialog ---------- */
.sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; border-radius: 18px 18px 0 0;
  max-height: 92vh; background: var(--bg); box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 16px; } }
.sheet::backdrop { background: rgba(22, 24, 28, .55); }
.sheet-head { position: sticky; top: 0; background: var(--bg); padding: 16px 18px 8px; display: flex; justify-content: space-between; align-items: center; z-index: 1; }
.sheet-head h2 { font-family: var(--cond); text-transform: uppercase; margin: 0; font-size: 22px; letter-spacing: .4px; }
.sheet-body { padding: 4px 18px 22px; }
.sheet-body .serial-line { font-family: var(--mono); font-weight: 700; margin-bottom: 14px; color: var(--ink-2); }
.x { background: var(--soft); border: 0; width: 36px; height: 36px; border-radius: 50%; font-size: 20px; cursor: pointer; line-height: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--overdue); }

/* ---------- Loading ---------- */
.loading { display: grid; place-items: center; padding: 70px 0; color: var(--ink-3); gap: 12px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
.skeleton { background: linear-gradient(90deg, #e9e7e2 25%, #f3f1ed 50%, #e9e7e2 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); height: 74px; }
@keyframes sk { to { background-position: -200% 0; } }

@media (min-width: 960px) {
  .container { padding: 24px; }
}
