:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #14181f;
  --muted: #5b6573;
  --line: #dde2ec;
  --accent: #0b5fff;
  --accent-text: #ffffff;
  --ok: #17803d;
  --ok-bg: #e3f5ea;
  --warn: #9a6700;
  --warn-bg: #fff3d1;
  --bad: #c62828;
  --bad-bg: #fde7e7;
  --info-bg: #e5edff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #181c24;
    --text: #e8ebf1;
    --muted: #9aa4b2;
    --line: #2a303b;
    --accent: #4c8dff;
    --accent-text: #08101f;
    --ok: #55d28a;
    --ok-bg: #12301f;
    --warn: #f0c24b;
    --warn-bg: #33290d;
    --bad: #ff7b7b;
    --bad-bg: #3a1616;
    --info-bg: #14233f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.screen { max-width: 640px; margin: 0 auto; padding: 24px 16px; }
.screen h1 { font-size: 22px; margin: 8px 0 12px; }
.screen p { color: var(--muted); }

.app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; position: sticky; top: 0; background: var(--bg); z-index: 2; border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; font-size: 18px; margin: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }
.agent-text { font-size: 12px; color: var(--muted); }

main { flex: 1; padding: 12px 16px 96px; }
.view[hidden] { display: none; }

.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav button { flex: 1; min-height: 52px; border: 0; background: none; color: var(--muted); font-size: 15px; font-weight: 600; }
.bottomnav button.active { color: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.toolbar .grow { flex: 1; color: var(--muted); font-size: 13px; }

h2 { font-size: 15px; margin: 22px 0 8px; display: flex; align-items: center; gap: 8px; }
h2 .count { font-weight: 500; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.card .head { display: flex; align-items: flex-start; gap: 8px; }
.card .title { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.card .buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card.done .title { text-decoration: line-through; color: var(--muted); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--info-bg); color: var(--accent); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.grey { background: var(--line); color: var(--muted); }

button, .button {
  min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.small, .button.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
button:disabled { opacity: 0.5; }
button.link { border: 0; background: none; color: var(--accent); min-height: 0; padding: 4px; }

input, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 96px; resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
.form-row { display: flex; gap: 8px; margin-top: 8px; }
.form-row > .grow { flex: 1; }

.notice { border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 14px; overflow-wrap: anywhere; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.info { background: var(--info-bg); color: var(--accent); }

.empty { color: var(--muted); text-align: center; padding: 14px 0; }

.hints { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.hints button { min-height: 30px; padding: 2px 10px; font-size: 13px; font-weight: 500; }

pre.result { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; padding: 10px; border-radius: 8px; background: var(--bg); font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
pre.result.error { background: var(--bad-bg); color: var(--bad); }
.progress { color: var(--muted); font-size: 13px; margin-top: 6px; overflow-wrap: anywhere; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(68px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); text-align: center; z-index: 5; }

.menu { position: absolute; right: 12px; top: 52px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px; z-index: 4; min-width: 210px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); }
.menu button { width: 100%; justify-content: flex-start; border: 0; background: none; }

.offscreen { position: fixed; left: -9999px; top: 0; }
