:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6a6a64;
  --line: #e4e2db;
  --accent: #1f7a4d;
  --accent-ink: #ffffff;
  --accent-soft: #e5f2ea;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --bad: #a3322a;
  --bad-soft: #fbe7e5;
  --chip: #efede6;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161714; --card: #20211d; --ink: #ecebe6; --muted: #a3a29a; --line: #33342e;
    --accent: #4cb882; --accent-ink: #0f1a13; --accent-soft: #1d3327; --warn: #e2a64a; --warn-soft: #3a2e19;
    --bad: #ef7f74; --bad-soft: #3d2220; --chip: #2a2b26; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161714; --card: #20211d; --ink: #ecebe6; --muted: #a3a29a; --line: #33342e;
  --accent: #4cb882; --accent-ink: #0f1a13; --accent-soft: #1d3327; --warn: #e2a64a; --warn-soft: #3a2e19;
  --bad: #ef7f74; --bad-soft: #3d2220; --chip: #2a2b26; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand img { border-radius: 7px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--chip); color: var(--muted); }
.pill.auto { background: var(--accent-soft); color: var(--accent); }
.pill.paused { background: var(--warn-soft); color: var(--warn); }
.icon-btn { border: 0; background: none; padding: 8px; margin: -8px; border-radius: 10px; color: var(--muted); cursor: pointer; }
.icon-btn.on { color: var(--accent); }

.connects { padding: 8px 16px; font-size: 14px; color: var(--muted); border-bottom: 1px solid var(--line); }
.connects b { color: var(--ink); font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--chip); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

main { padding: 12px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); max-width: 720px; margin: 0 auto; outline: none; }
h2 { font-size: 14px; font-weight: 650; color: var(--muted); text-transform: none; margin: 22px 2px 8px; letter-spacing: 0; }
h2:first-child { margin-top: 6px; }
h1.page { font-size: 22px; margin: 6px 2px 12px; }
p.lead { color: var(--muted); margin: 0 2px 12px; }

.card {
  display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 10px; color: var(--ink); text-decoration: none; cursor: pointer;
}
.card:active { transform: scale(.995); }
.card .t { font-weight: 600; line-height: 1.35; }
.card .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.card .why { font-size: 14px; margin-top: 6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.chip.go { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

.notice { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px; margin: 0 0 12px; }
.notice.warn { border-left-color: var(--warn); }
.notice p { margin: 0 0 10px; }
.notice p:last-child { margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 36px 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.actions .btn { flex: 1 1 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tabs-h); color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
.tabs a.on { color: var(--accent); }
.count { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

/* job detail */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; margin: 2px 0 10px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.fact { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.fact span { display: block; font-size: 12.5px; color: var(--muted); }
.fact b { font-weight: 600; overflow-wrap: anywhere; }
label.f { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 16px 2px 6px; }
textarea, input[type=text], input[type=number], input[type=password] {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 16px; line-height: 1.5;
}
textarea { min-height: 260px; resize: vertical; }
textarea.short { min-height: 90px; }
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-size: 13.5px; color: var(--muted); margin: 6px 2px 0; }
details { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 12px 0; }
details summary { font-weight: 600; cursor: pointer; }
.desc { white-space: pre-wrap; font-size: 15px; margin-top: 10px; overflow-wrap: anywhere; }
.trail { font-size: 13.5px; color: var(--muted); margin: 6px 0 0; padding-left: 18px; }

/* settings */
.set { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px; margin-bottom: 14px; }
.set .line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set .line:last-child { border-bottom: 0; }
.set .line > div { min-width: 0; }
.set .line small { display: block; color: var(--muted); font-size: 13.5px; }
.set input[type=number] { width: 92px; text-align: right; padding: 8px 10px; }
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 3px; margin: 12px 0; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 4px; font-weight: 600; font-size: 14.5px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 15px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }
.kb { white-space: pre-wrap; font-size: 15px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow-wrap: anywhere; }
.log { font-size: 14px; }
.log div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); font-size: 12.5px; display: block; }

.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login img { border-radius: 16px; }
.login h1 { font-size: 22px; margin: 14px 0 4px; }
.login form { margin-top: 20px; display: grid; gap: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 9;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast, .switch i, .switch i::after { transition: none; } .card:active { transform: none; } }
