:root {
  --bg: #f4f3ef; --card: #ffffff; --text: #1d1d1b; --muted: #6b6a63; --line: #e3e1da;
  --green: #1f7a4d; --green-bg: #e3f3ea; --amber: #94620b; --amber-bg: #fbefd6;
  --gray: #5e5e5a; --gray-bg: #ecebe6; --blue: #1f5fa8; --blue-bg: #e2ecf8;
  --red: #b3261e; --accent: #1d1d1b; --accent-text: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --card: #1e1e1c; --text: #ecebe6; --muted: #9c9a92; --line: #2f2e2b;
    --green: #6fd19c; --green-bg: #173326; --amber: #f0c06a; --amber-bg: #3a2c10;
    --gray: #b4b2aa; --gray-bg: #2a2a27; --blue: #8cb8ec; --blue-bg: #172a40;
    --red: #f2a19b; --accent: #ecebe6; --accent-text: #141413;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.error { color: var(--red); font-size: 14px; min-height: 1.2em; margin: 8px 0 0; }
.banner { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }

/* login */
.login {
  min-height: calc(100vh - 48px); display: grid; place-items: center;
  background: radial-gradient(900px 500px at 50% -10%, var(--blue-bg), transparent 70%);
  margin: -16px; padding: 16px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px 24px; display: grid; gap: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 12px 32px rgba(0,0,0,.06);
}
.login-mark {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); margin-bottom: 2px;
}
.login-card h1 { font-size: 24px; }
.login-sub { margin: -8px 0 4px; color: var(--muted); font-size: 14.5px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field input { width: 100%; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 68px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); background: none; border: 0;
  padding: 8px 10px; min-height: 36px; border-radius: 7px; cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--gray-bg); }
.code-input {
  font: inherit; font-size: 26px !important; letter-spacing: 0.45em; text-align: center; font-variant-numeric: tabular-nums;
  padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--text); min-height: 54px;
}
.code-input::placeholder { color: var(--line); }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); }
.warn-text { color: var(--amber); font-weight: 600; }
.btn-block { width: 100%; min-height: 46px; font-weight: 600; font-size: 15px; margin-top: 4px; }
.btn-block:disabled { cursor: progress; }
.login-error {
  margin: 0; padding: 10px 12px; border-radius: 9px; font-size: 14px;
  color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent);
}
.login-error.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { .login-error.shake { animation: none; } }
.login-foot { margin: 4px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
input[type=password], input[type=search] {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); min-height: 44px;
}

/* layout */
#panel { max-width: 1080px; margin: 0 auto; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.tab {
  font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; min-height: 40px;
}
.tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
#search { margin-left: auto; flex: 1 1 200px; max-width: 320px; }
.list { display: grid; gap: 10px; }
.foot { margin-top: 20px; text-align: center; }

/* app row */
.app {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center;
}
.app-main { min-width: 0; }
.app-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.app-title strong { font-size: 16px; }
.app-about { color: var(--muted); font-size: 13.5px; margin: 3px 0 0; }
.app-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; font-size: 13px; }
.app-meta a { color: var(--blue); text-decoration: none; }
.app-meta a:hover { text-decoration: underline; }
.chip { font-variant-numeric: tabular-nums; color: var(--muted); }
.chip.up { color: var(--green); }
.app-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.events { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); margin: 0; padding: 0; list-style: none; }
.events li.err { color: var(--red); }

.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill.running { color: var(--green); background: var(--green-bg); }
.pill.stopped { color: var(--gray); background: var(--gray-bg); }
.pill.partial { color: var(--amber); background: var(--amber-bg); }
.pill.busy { color: var(--blue); background: var(--blue-bg); }

.btn {
  font: inherit; font-size: 14px; padding: 8px 14px; min-height: 40px; min-width: 44px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--red); }
.btn.confirm { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; min-height: 40px; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--gray-bg); border: 1px solid var(--line); position: relative; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s; }
.switch input:checked { background: var(--green); border-color: var(--green); }
.switch input:checked::after { left: 18px; }

dialog { width: min(900px, 94vw); border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#log-body { margin: 0; padding: 14px; max-height: 70vh; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .app-actions { justify-content: flex-start; }
  #search { max-width: none; margin-left: 0; }
}

/* header actions, warning */
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.banner.warn { color: var(--amber); background: var(--amber-bg); border-color: transparent; margin: 0 0 14px; font-size: 14px; }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font-weight: 600; }

/* status filters */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip-btn {
  font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; min-height: 36px; display: inline-flex; align-items: center; gap: 6px;
}
.chip-btn .count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.chip-btn.active { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.chip-btn .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.running { background: var(--green); } .dot.stopped { background: var(--gray); }
.dot.partial { background: var(--amber); } .dot.boot { background: var(--blue); } .dot.noboot { background: var(--line); border: 1px solid var(--muted); }

/* security dialog */
#sec-dialog { width: min(720px, 96vw); }
.sec-body { padding: 4px 18px 18px; max-height: 78vh; overflow: auto; }
.sec-body section { border-bottom: 1px solid var(--line); padding: 14px 0; }
.sec-body section:last-child { border-bottom: 0; }
.sec-body h2 { font-size: 15px; margin: 0 0 6px; }
.sec-body p { margin: 6px 0; font-size: 14px; }
.sec-body ol { padding-left: 20px; font-size: 14px; }
.sec-body input { font: inherit; font-size: 16px; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--text); min-height: 44px; }
.sec-body label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input { flex: 1 1 140px; }
.stack { display: grid; gap: 8px; max-width: 380px; }
.secret { display: block; font-size: 17px; letter-spacing: 0.08em; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; word-break: break-all; user-select: all; }
.ok-msg { color: var(--green); }
.table-wrap { overflow-x: auto; }
#history { border-collapse: collapse; width: 100%; font-size: 13px; }
#history th, #history td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#history td.bad { color: var(--red); } #history td.good { color: var(--green); }
.blocked-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; flex-wrap: wrap; }

/* health strip */
.health { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.spark { display: inline-flex; gap: 1px; align-items: flex-end; height: 16px; }
.spark i { display: block; width: 3px; height: 16px; border-radius: 1px; background: var(--green); opacity: .85; }
.spark i.f { background: var(--red); }
.spark i.o { background: var(--line); height: 6px; }
.spark i.n { background: transparent; }
.incident { grid-column: 1 / -1; margin: 0; padding: 8px 12px; border-radius: 9px; font-size: 13.5px;
  color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  background: var(--red); color: #fff; line-height: 18px; text-align: center; }
.tab.active .badge { background: #fff; color: var(--red); }

/* domains */
.domains-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.dtable { border-collapse: collapse; width: 100%; font-size: 13.5px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.dtable th, .dtable td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.dtable th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
.dtable tr:last-child td { border-bottom: 0; }
.dtable .bad { color: var(--red); font-weight: 600; }
.dtable .warn { color: var(--amber); font-weight: 600; }
.dtable .good { color: var(--green); }
.dtable .dim { color: var(--muted); }
.sub-h { font-size: 15px; margin: 22px 0 10px; }

/* diagnosis */
#diag-dialog { width: min(760px, 96vw); }
.diag-body { padding: 14px 18px 18px; max-height: 75vh; overflow: auto; }
.diag-text { white-space: pre-wrap; font-size: 14.5px; line-height: 1.55; }
.diag-text.loading { color: var(--muted); }
.small { font-size: 12px; margin-top: 14px; }
#set-dialog { width: min(620px, 96vw); }
#set-dialog select { font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--text); min-height: 42px; }
#set-dialog .switch { color: var(--text); font-size: 14px; }
