:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --line: #e3e6ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --high: #d97706;
  --critical: #dc2626;
  --low: #98a2b3;
  --chip: #eceef2;
  --unread: #eef4ff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --card: #1a2027;
    --text: #e6e9ed;
    --muted: #98a2b3;
    --line: #2a313a;
    --accent: #5b8def;
    --chip: #252c35;
    --unread: #1d2a3d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
a { color: var(--accent); }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px 96px; }
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: 12px 0 8px;
}
.top h1 { flex: 1; }
.badge {
  display: inline-block; min-width: 1.5em; padding: 0 .45em; border-radius: 999px;
  background: var(--critical); color: #fff; font-size: .8rem; text-align: center; font-weight: 600;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--chip); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.chip .badge { margin-left: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0 0 12px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.msg { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.msg:last-child { border-bottom: 0; }
.msg.unread { background: var(--unread); }
.msg .ic { font-size: 1.4rem; line-height: 1.6rem; flex: none; width: 1.8rem; text-align: center; }
.msg .main { flex: 1; min-width: 0; }
.msg .head { display: flex; gap: 8px; align-items: baseline; }
.msg .title { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg.unread .title::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: middle; }
.msg .time { color: var(--muted); font-size: .8rem; flex: none; }
.msg .meta { color: var(--muted); font-size: .82rem; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; font-size: .93rem; }
.msg:not(.open) .body { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg.p-high { box-shadow: inset 4px 0 0 var(--high); }
.msg.p-critical { box-shadow: inset 4px 0 0 var(--critical); }
.msg.p-low .title { font-weight: 500; color: var(--muted); }
.msg .tools { display: none; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.msg.open .tools { display: flex; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px;
  cursor: pointer; min-height: 40px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--critical); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 1.35rem; padding: 6px 8px; cursor: pointer; border-radius: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { background: var(--chip); border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin: 0 0 12px; }
.hint.warn { box-shadow: inset 4px 0 0 var(--high); }

label { display: block; font-size: .9rem; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 11px; min-height: 42px;
}
textarea { min-height: 120px; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table td, .table th { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; }
.table td.r { text-align: right; white-space: nowrap; }
.src-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.src-row:last-child { border-bottom: 0; }
.src-row .ic { font-size: 1.3rem; width: 1.8rem; text-align: center; }
.src-row select { width: auto; min-height: 36px; padding: 4px 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.up { background: #16a34a; } .dot.down { background: var(--critical); }

.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login .logo { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; margin-bottom: 16px; }
.err { color: var(--critical); font-size: .9rem; min-height: 1.3em; margin-top: 8px; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card {
  background: var(--card); width: 100%; max-width: 640px; max-height: 85vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-card { border-radius: 16px; } }
.sheet-card pre { white-space: pre-wrap; overflow-wrap: anywhere; font: .92rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: 12px; border-radius: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }
.tabs { display: flex; gap: 4px; margin: 0 0 12px; }
.tabs .chip { flex: 1; text-align: center; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--chip); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
