:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #14202e; --muted: #5d6b7c; --line: #e1e6ed;
  --brand: #1f4e78; --brand-ink: #ffffff; --accent: #2b6cb0;
  --green: #0b7a43; --green-bg: #c6efce; --green-ink: #006100;
  --amber: #9c6500; --amber-bg: #ffeb9c;
  --red: #b42318; --red-bg: #ffc7ce; --red-ink: #9c0006;
  --blue-bg: #d9eaf7; --shadow: 0 1px 2px rgba(16,32,52,.08), 0 2px 8px rgba(16,32,52,.05);
  --radius: 14px; --nav-h: 62px; --bar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b; --card: #17202b; --ink: #e8eef5; --muted: #93a1b3; --line: #263241;
    --brand: #3a78b0; --accent: #6fa8dc; --green: #4cc38a; --green-bg: #12382a; --green-ink: #8be0b5;
    --amber: #e6b04c; --amber-bg: #3d3015; --red: #ff7b72; --red-bg: #43191c; --red-ink: #ffaba5;
    --blue-bg: #16324a; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141b; --card: #17202b; --ink: #e8eef5; --muted: #93a1b3; --line: #263241;
  --brand: #3a78b0; --accent: #6fa8dc; --green: #4cc38a; --green-bg: #12382a; --green-ink: #8be0b5;
  --amber: #e6b04c; --amber-bg: #3d3015; --red: #ff7b72; --red-bg: #43191c; --red-ink: #ffaba5;
  --blue-bg: #16324a; --shadow: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.green { color: var(--green); } .red { color: var(--red); } .amber { color: var(--amber); }

/* shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; min-height: var(--bar-h);
  padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--brand); color: var(--brand-ink); }
.topbar h1 { font-size: 17px; flex: 1; font-weight: 650; letter-spacing: .1px; }
.topbar select { background: rgba(255,255,255,.16); color: #fff; border: 0; border-radius: 10px; padding: 7px 10px; max-width: 42vw; }
.topbar select option { color: #111; }
.pill-job { background: rgba(255,255,255,.2); border-radius: 999px; padding: 4px 10px; font-size: 12px; border: 0; color: #fff; }
.pill-job.run { background: #ffeb84; color: #5a4300; }
main { padding: 14px 16px 24px; max-width: 980px; margin: 0 auto; }
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.bottom a { flex: 1; text-align: center; padding: 8px 2px 7px; font-size: 11px; color: var(--muted); text-decoration: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: var(--nav-h); justify-content: center; }
nav.bottom a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.bottom a.on { color: var(--accent); font-weight: 650; }

/* basics */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 18px 2px 8px; }
.section-title:first-child { margin-top: 2px; }
.banner { border-radius: 12px; padding: 11px 13px; margin-bottom: 12px; background: var(--blue-bg); font-size: 14px; }
.banner.amber { background: var(--amber-bg); } .banner.red { background: var(--red-bg); } .banner.green { background: var(--green-bg); }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; min-height: 42px; font-weight: 600; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 11px; min-height: 42px; }
label.field { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; color: var(--ink); }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; overflow-x: auto; margin-bottom: 12px; }
.seg button { flex: 1 0 auto; border: 0; background: transparent; border-radius: 9px; padding: 8px 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--brand); color: #fff; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; box-shadow: var(--shadow); }
.tile .l { font-size: 12px; color: var(--muted); } .tile .v { font-size: 20px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .n { font-size: 11.5px; color: var(--muted); }
.tile.green .v { color: var(--green); } .tile.red .v { color: var(--red); } .tile.amber .v { color: var(--amber); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 13px; border: 0; }
.chip.green { background: var(--green-bg); color: var(--green-ink); } .chip.red { background: var(--red-bg); color: var(--red-ink); }

/* bars */
.bars .b { margin: 7px 0; } .bars .t { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.bars .t span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .track { position: relative; height: 9px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: 3px; }
.bars .fill { height: 100%; border-radius: 6px; background: var(--accent); }
.bars .fill.green { background: var(--green); } .bars .fill.red { background: var(--red); } .bars .fill.amber { background: #e0a800; }
.bars .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .55; }
.bars .div .track { background: linear-gradient(90deg, var(--line) 50%, var(--line) 50%); }
.bars .div .fill { position: absolute; top: 0; }

/* list cards */
.tools { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.tools input { flex: 1; } .tools select { width: auto; max-width: 44%; }
.count { font-size: 12px; color: var(--muted); margin: 0 2px 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.item.tap { cursor: pointer; } .item .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.item .ttl { font-weight: 650; overflow-wrap: anywhere; } .item .sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 6px 10px; margin-top: 8px; }
.metrics .m .l { font-size: 11px; color: var(--muted); } .metrics .m .v { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 650; background: var(--line); white-space: nowrap; }
.pill.g { background: var(--green-bg); color: var(--green-ink); } .pill.a { background: var(--amber-bg); color: var(--amber); }
.pill.r { background: var(--red-bg); color: var(--red-ink); }
details.more { margin-top: 8px; } details.more summary { font-size: 12.5px; color: var(--accent); cursor: pointer; }
.kv { display: grid; grid-template-columns: minmax(90px, 36%) 1fr; gap: 3px 10px; font-size: 13px; margin-top: 6px; }
.kv .k { color: var(--muted); } .kv .vv { overflow-wrap: anywhere; }
.scroll { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); margin-bottom: 10px; max-height: 70vh; }
table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: var(--card); z-index: 1; font-size: 12px; color: var(--muted); cursor: pointer; }
td:first-child, th:first-child { position: sticky; left: 0; background: var(--card); z-index: 2; }

/* sheet */
dialog { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 760px; margin: auto auto 0; background: var(--bg); color: var(--ink);
  max-height: 92vh; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(8,16,28,.55); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); z-index: 3; }
.sheet-head h2 { flex: 1; font-size: 16px; overflow-wrap: anywhere; } .sheet-body { padding: 14px 16px 24px; overflow: auto; max-height: calc(92vh - 60px); }
.x { border: 0; background: var(--line); border-radius: 50%; width: 34px; height: 34px; font-size: 18px; line-height: 1; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .box { width: 100%; max-width: 360px; }
.login img { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto 14px; }
.login h1 { text-align: center; margin-bottom: 18px; font-size: 22px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin: 6px 0; }

/* progress */
.progress { height: 12px; background: var(--line); border-radius: 8px; overflow: hidden; } .progress > div { height: 100%; background: var(--green); transition: width .4s; }
.log { background: #0b1118; color: #cfe3f5; font: 12px/1.4 ui-monospace, Consolas, monospace; padding: 10px; border-radius: 10px; max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.stage { display: flex; gap: 8px; font-size: 13px; padding: 3px 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); background: #101c2b; color: #fff;
  padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.3); font-size: 14px; }
.toast.err { background: #8c1d18; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes sp { to { transform: rotate(360deg); } }
.review-row.need { border-color: var(--amber); background: color-mix(in srgb, var(--amber-bg) 45%, var(--card)); }
.review-row .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.review-row .grid label { font-size: 11px; color: var(--muted); } .review-row .grid input, .review-row .grid select { min-height: 38px; padding: 6px 8px; }
.pick { width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } .progress > div { transition: none; } }
