:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #17202a; --muted: #5d6b79; --line: #dfe4ea;
  --brand: #128c7e; --brand-2: #0b6e63; --brand-soft: #e3f4f1;
  --ok: #1e8e3e; --ok-soft: #e6f4ea; --warn: #b26a00; --warn-soft: #fff4e0;
  --bad: #c5221f; --bad-soft: #fce8e6; --info-soft: #e8f0fe; --info: #1a5fb4;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 6px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b; --card: #1a2128; --text: #e6ebf0; --muted: #9aa7b4; --line: #2c3640;
    --brand: #25b39f; --brand-2: #1e9a89; --brand-soft: #173a35;
    --ok: #5cc27a; --ok-soft: #183323; --warn: #f0b04a; --warn-soft: #3a2e15;
    --bad: #f28b82; --bad-soft: #3d1f1d; --info-soft: #1c2b44; --info: #8ab4f8;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { margin-left: auto; }
.stack > * + * { margin-top: 10px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.brand { font-weight: 700; color: var(--brand); white-space: nowrap; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.status-dot.ok { background: var(--ok); } .status-dot.bad { background: var(--bad); }
main { max-width: 1100px; margin: 0 auto; padding: 12px; padding-bottom: 80px; }
.banner { max-width: 1100px; margin: 8px auto 0; padding: 8px 12px; border-radius: var(--radius); background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.page-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .topbar .nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); justify-content: space-around; padding: 4px; z-index: 30; }
  .topbar .nav a { padding: 6px 6px; font-size: 12px; }
  .topbar .nav .long { display: none; } .topbar .nav .short { display: inline; }
  main { padding: 10px; padding-bottom: 90px; }
}

/* cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tiles { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.tile b { display: block; font-size: 20px; }
.list { max-height: 62vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.list.short { max-height: 40vh; }
.item { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .title { font-weight: 600; }
.item .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.item .actions { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 18px; text-align: center; color: var(--muted); }
.error-text { color: var(--bad); font-size: 12px; margin-top: 3px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 6px 2px; color: var(--muted); font-size: 12px; }
.pager button { min-width: 34px; }

/* badges */
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.info { background: var(--info-soft); color: var(--info); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-size: 12px; margin: 2px 4px 2px 0; max-width: 100%; }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip button { border: 0; background: none; padding: 0 0 0 2px; cursor: pointer; color: inherit; font-size: 14px; line-height: 1; }

/* forms */
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); min-height: 36px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
@media (max-width: 520px) { .three { grid-template-columns: 1fr 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 13px; }
.checks input:checked + span { font-weight: 700; color: var(--brand); }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12px; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 8px 10px; border-radius: 8px; }

button.btn, a.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none; color: var(--text); min-height: 32px; white-space: nowrap; }
.btn.sm { padding: 3px 9px; min-height: 28px; font-size: 12px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 7px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 24px 10px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 620px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.modal.sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 520px) { .modal-back { padding: 0; } .modal { border-radius: 0; min-height: 100vh; } }

.toasts { position: fixed; right: 12px; bottom: 70px; z-index: 80; display: flex; flex-direction: column; gap: 6px; max-width: calc(100vw - 24px); }
.toast { padding: 9px 12px; border-radius: 8px; background: #263238; color: #fff; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); } .toast.ok { background: var(--ok); }

.login { max-width: 340px; margin: 12vh auto; }
.nav .short { display: none; }
.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.slotgrid { display: flex; flex-wrap: wrap; gap: 4px; }
