:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #111418;
  --muted: #626a75;
  --line: #dfe2e7;
  --brand: #2e5699;
  --accent: #f5c518;
  --accent-ink: #111418;
  --ok: #2f7d4f;
  --ok-bg: #e5f2e9;
  --warn: #b5501f;
  --warn-bg: #fbe9df;
  --info-bg: #e8eef8;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 10px; min-height: 56px;
}
.top .title { flex: 1; min-width: 0; }
.top .title h1 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title .sub { font-size: 13px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .icon-btn { color: #fff; }
main.page { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 760px; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.section-title { margin: 22px 0 10px; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.section-title:first-child { margin-top: 4px; }

/* ---------- bottom nav ---------- */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: var(--safe-b);
}
nav.bottom a {
  height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; font-size: 11.5px; color: var(--muted); position: relative;
}
nav.bottom a svg { width: 24px; height: 24px; }
nav.bottom a.on { color: var(--brand); font-weight: 700; }
nav.bottom a.on::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
nav.bottom .dot { position: absolute; top: 9px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card + .card { margin-top: 10px; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); min-height: 60px; text-decoration: none; }
.item:last-child { border-bottom: 0; }
button.item, a.item { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; }
.item .t { font-weight: 600; }
.item .s { font-size: 14px; color: var(--muted); }
.chev { color: #b3bac4; flex: none; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; box-shadow: 0 1px 2px rgba(0,0,0,.05); display: block; }
.stat .n { font-size: 28px; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: 14px; color: var(--muted); }
.stat.warn .n { color: var(--warn); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--info-bg); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.accent { background: #fff6d1; color: #6b5300; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--warn); border-color: #f0c9b5; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; cursor: pointer; flex: none; }
.icon-btn svg { width: 24px; height: 24px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 25;
  height: 56px; padding: 0 20px; border-radius: 28px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.fab svg { width: 22px; height: 22px; }

/* ---------- stepper ---------- */
.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.stepper button { width: 52px; border: 0; background: #f1f3f6; font-size: 24px; font-weight: 600; cursor: pointer; }
.stepper button:active { background: #e3e7ed; }
.stepper input { width: 70px; flex: 1; border: 0; text-align: center; font-size: 20px; font-weight: 700; padding: 10px 4px; min-width: 0; }
.stepper.big button { width: 72px; font-size: 32px; }
.stepper.big input { font-size: 34px; padding: 14px 4px; }
.stepper.mini button { width: 40px; font-size: 20px; }
.stepper.mini input { width: 44px; font-size: 17px; padding: 6px 2px; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-weight: 500; }
label.check input { width: 22px; height: 22px; }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font-size: 16px; font-weight: 400;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search { position: relative; }
.search input { padding-left: 42px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); }

/* ---------- tabs & chips ---------- */
.tabs { display: flex; gap: 6px; background: #e3e7ed; padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tabs button { flex: 1 1 auto; min-width: 0; min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs .cnt { display: inline-block; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; line-height: 18px; vertical-align: 1px; }
@media (max-width: 360px) { .tabs button { font-size: 13px; padding: 0 3px; } }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; text-decoration: none; color: var(--ink); min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: #fff; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- material line ---------- */
.mline { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.mline + .mline { margin-top: 10px; }
.mline .head { display: flex; gap: 10px; align-items: flex-start; }
.mline .name { font-weight: 700; flex: 1; min-width: 0; }
.nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0; }
.nums div { background: #f1f3f6; border-radius: 10px; padding: 8px 6px; text-align: center; }
.nums b { display: block; font-size: 19px; line-height: 1.15; }
.nums span { font-size: 12px; color: var(--muted); }
.nums .short { background: var(--warn-bg); color: var(--warn); }
.nums .short span { color: var(--warn); }
.nums .done { background: var(--ok-bg); color: var(--ok); }
.nums .done span { color: var(--ok); }
.mline .actions { display: flex; gap: 8px; }
.mline .actions .btn { flex: 1; padding: 0 8px; font-size: 14px; }
.mline .actions .icon-btn { border: 1px solid var(--line); }

/* ---------- shopping ---------- */
.shop { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.shop:last-child { border-bottom: 0; }
.tick { width: 44px; height: 44px; flex: none; border-radius: 50%; border: 2px solid #c5cbd3; background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; color: transparent; }
.tick:active { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.tick svg { width: 22px; height: 22px; }
.shop .q { font-weight: 800; white-space: nowrap; }
.totals { margin-top: 14px; }
.totals .row { padding: 4px 0; }
.totals .big { font-size: 20px; font-weight: 800; }

/* ---------- man ---------- */
.crew-day { text-align: center; }
.crew-day .date { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.crew-day .date b { font-size: 17px; }
.progress { height: 10px; border-radius: 5px; background: #e3e7ed; overflow: hidden; margin: 8px 0 4px; }
.progress div { height: 100%; background: var(--accent); border-radius: 5px; }
.progress.over div { background: var(--warn); }
.today-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.today-row:last-child { border-bottom: 0; }
.today-row a { text-decoration: none; }

/* ---------- sheet (bottom modal) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(20,25,30,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(20px + var(--safe-b)); animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #cfd4db; margin: 0 auto 10px; }
.sheet .sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.sheet .sheet-head h2 { flex: 1; }
@media (min-width: 640px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes down { from { transform: translateY(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast { position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 12px); z-index: 60; display: flex; justify-content: center; pointer-events: none; }
.toast div { background: #111418; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 20px rgba(0,0,0,.2); max-width: 520px; animation: down .2s; }
.toast div.err { background: var(--warn); }

.notice { background: var(--warn-bg); color: var(--warn); padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.hint { background: var(--info-bg); padding: 12px 14px; border-radius: 12px; font-size: 14px; }

/* ---------- auth ---------- */
body.auth, .auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--brand); border-top: 8px solid var(--accent); }
.auth-card { width: 100%; max-width: 400px; background: var(--bg); border-radius: 20px; padding: 28px 20px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card .logo { width: 100%; max-width: 300px; height: auto; display: block; margin: 0 auto 10px; }
.auth-card { background: #fff; }

@media print {
  .top, nav.bottom, .fab, .tick, .noprint { display: none !important; }
  main.page { padding: 0; }
  body { background: #fff; }
  .list, .card { box-shadow: none; border: 1px solid #ccc; }
}
.tabs.scroll { overflow-x: auto; scrollbar-width: none; }
.tabs.scroll::-webkit-scrollbar { display: none; }
.tabs.scroll button { flex: 1 0 auto; overflow: visible; }
