:root {
  --bg: #f4f5f8; --card: #ffffff; --text: #151922; --muted: #687083; --line: #e3e6ec; --soft: #eef1f6;
  --accent: #1f4fd1; --accent-soft: #e6edff; --danger: #c62828; --danger-soft: #fdecec;
  --warn: #b45309; --warn-soft: #fff4e0; --ok: #15803d; --ok-soft: #e7f6ec;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --nav-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --card: #181c24; --text: #e8ebf1; --muted: #949bab; --line: #2a303b; --soft: #212632;
    --accent: #6d95ff; --accent-soft: #1d2945; --danger: #f87171; --danger-soft: #3a1d20;
    --warn: #f5b04c; --warn-soft: #3a2c15; --ok: #4ade80; --ok-soft: #173023;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 920px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 14px) 14px 0; }
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-height: 36px; }
.top h1 { flex: 1; }
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }

/* buttons & inputs */
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px;
  font-weight: 550; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; padding: 12px; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; outline: none;
  min-height: 44px; font-size: 16px; /* 16px stops iOS zoom */
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
label.field > span b { color: var(--danger); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid2 .full { grid-column: 1 / -1; }

/* capture */
.capture { display: flex; gap: 8px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 4px 0 6px; }
.capture input { flex: 1; font-size: 16px; min-height: 48px; border-radius: 12px; box-shadow: var(--shadow); }
.capture .btn { min-width: 64px; border-radius: 12px; }
.preview { display: flex; flex-wrap: wrap; gap: 6px; min-height: 0; margin: 0 0 6px; }
.preview:empty { display: none; }

/* chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 500;
  white-space: nowrap; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { font-size: 12px; opacity: .7; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 550; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }

/* cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.task { display: flex; gap: 10px; align-items: flex-start; padding: 12px; cursor: pointer; }
.task .check {
  flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); background: transparent; margin-top: 1px;
  cursor: pointer; display: grid; place-items: center; padding: 0;
}
.task.p2 .check { border-color: var(--danger); }
.task.done .check { background: var(--ok); border-color: var(--ok); }
.task.done .check::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 500; word-wrap: break-word; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .meta { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 4px; }

.order { padding: 12px 14px; display: block; color: inherit; }
.order .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.order .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.order .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.bar { display: flex; gap: 3px; margin-top: 10px; }
.bar i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.bar i.on { background: var(--accent); }
.order.stuck .bar i.on { background: var(--warn); }

/* board */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; margin: 0 -14px; padding: 0 14px 10px; scroll-snap-type: x mandatory; }
.col { flex: 0 0 260px; scroll-snap-align: start; background: var(--soft); border-radius: var(--radius); padding: 10px; }
.col h3 { margin: 0 0 8px; font-size: 13px; display: flex; justify-content: space-between; }
.col .list { gap: 6px; }
.col .order { padding: 10px; }

/* order detail */
.steps { display: flex; gap: 0; margin: 4px 0 14px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
#app p { overflow-wrap: anywhere; }
.step { flex: 1; min-width: 64px; text-align: center; position: relative; font-size: 11px; color: var(--muted); }
.step::before { content: ""; position: absolute; top: 9px; left: -50%; right: 50%; height: 2px; background: var(--line); z-index: 0; }
.step:first-child::before { display: none; }
.step i { position: relative; z-index: 1; display: block; width: 20px; height: 20px; border-radius: 50%; margin: 0 auto 4px; background: var(--card); border: 2px solid var(--line); }
.step.done i { background: var(--accent); border-color: var(--accent); }
.step.done::before, .step.cur::before { background: var(--accent); }
.step.cur i { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.step.cur { color: var(--text); font-weight: 600; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 6px 12px; padding: 12px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-wrap: break-word; white-space: pre-wrap; }
.sec-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.timeline { padding: 4px 14px; }
.ev { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ev:last-child { border-bottom: 0; }
.ev .when { font-size: 12px; color: var(--muted); }
.ev.note .txt { white-space: pre-wrap; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { padding: 12px 14px; display: block; color: inherit; }
.stat .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .v.sm { font-size: 17px; }
.stat .l { font-size: 13px; color: var(--muted); }
.stat.alert .v { color: var(--danger); }
.stagerow { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); color: inherit; }
.stagerow:last-child { border-bottom: 0; }
.stagerow .nm { flex: 0 0 42%; font-size: 14px; }
.stagerow .track { flex: 1; height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.stagerow .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.stagerow .c { width: 28px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

/* nav */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
#nav[hidden] { display: none; }
#nav a { flex: 1; max-width: 200px; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 12px; font-weight: 550; position: relative; }
#nav a.on { color: var(--accent); }
#nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#nav .badge { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; display: grid; place-items: center; }
#nav .badge:empty { display: none; }

/* sheet */
dialog#sheet {
  border: 0; padding: 0; background: var(--card); color: var(--text); width: 100%; max-width: 560px; max-height: 92vh;
  margin: auto auto 0; border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
@media (min-width: 700px) { dialog#sheet { margin: auto; border-radius: 18px; } }
dialog#sheet::backdrop { background: rgba(10, 14, 22, .45); }
dialog#sheet[open] { animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
#sheet-body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
.sheet-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-h h3 { margin: 0; font-size: 18px; }
.sheet-f { display: flex; gap: 8px; margin-top: 8px; position: sticky; bottom: 0; background: var(--card); padding-top: 8px; }
.sheet-f .btn { flex: 1; padding: 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { flex: 1; }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 9px 4px; cursor: pointer; font-size: 14px; font-weight: 500; }
.seg input:checked + span { background: var(--accent); color: #fff; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.stage-group { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.stage-group:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; display: flex; gap: 12px; align-items: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 650; cursor: pointer; padding: 0; }
#toast.err { background: var(--danger); color: #fff; }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login .logo { width: 64px; height: 64px; margin: 0 auto 16px; display: block; border-radius: 16px; }
.login form { text-align: left; margin-top: 22px; }
.err-msg { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }
.offline-bar { background: var(--warn-soft); color: var(--warn); font-size: 13px; padding: 8px 12px; border-radius: 10px; margin-bottom: 8px; }
.step.tap { cursor: pointer; }
.step.tap:hover i, .step.tap:active i { box-shadow: 0 0 0 4px var(--accent-soft); }
