:root {
  --bg: #f5f6fa; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e4e7ef;
  --accent: #4f46e5; --accent-ink: #ffffff; --accent-weak: #eef0ff;
  --ok: #15803d; --ok-weak: #e8f6ee; --warn: #b45309; --warn-weak: #fdf3e3; --bad: #b91c1c; --bad-weak: #fdeaea;
  --active: #16a34a; --idle: #f59e0b; --away: #cbd5e1;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px rgba(15, 23, 42, .07);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --card: #131b33; --text: #e7eaf6; --muted: #94a3b8; --line: #243050;
    --accent: #818cf8; --accent-ink: #0b1020; --accent-weak: #1d2550;
    --ok: #4ade80; --ok-weak: #11301f; --warn: #fbbf24; --warn-weak: #35280d; --bad: #f87171; --bad-weak: #3a1616;
    --away: #3b4767; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--accent-weak); color: var(--accent); }
.pill.ok { background: var(--ok-weak); color: var(--ok); }
.pill.warn { background: var(--warn-weak); color: var(--warn); }
.pill.bad { background: var(--bad-weak); color: var(--bad); }
.pill.gray { background: var(--line); color: var(--muted); }

.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-size: 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--line); }

input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 20px; }

/* login */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(1000px 500px at 20% -10%, var(--accent-weak), transparent), var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-card h1 { font-size: 22px; margin: 16px 0 4px; }
.login-card .logo { width: 40px; height: 40px; font-size: 20px; border-radius: 12px; }
.fine { font-size: 12px; color: var(--muted); margin-top: 18px; line-height: 1.5; }

/* chat */
.chat-wrap { max-width: 820px; margin: 0 auto; padding: 24px 16px 150px; }
.hero { text-align: center; padding: 56px 0 24px; }
.hero h2 { font-size: 26px; }
.hero p { color: var(--muted); margin: 8px 0 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.msg { display: flex; margin: 18px 0; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 88%; padding: 12px 16px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.warnbox { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--warn-weak); color: var(--warn); font-size: 13px; }
.typing { display: inline-flex; gap: 5px; align-items: center; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { position: fixed; left: 0; right: 0; bottom: 0; padding: 16px; background: linear-gradient(transparent, var(--bg) 35%); }
.composer form { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px; box-shadow: var(--shadow); }
.composer textarea { border: none; box-shadow: none; resize: none; max-height: 140px; padding: 8px 10px; }
.composer textarea:focus { box-shadow: none; }
.composer .note { max-width: 820px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

/* admin */
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tab { padding: 10px 16px; cursor: pointer; border: none; background: none; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile { padding: 16px 18px; }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.tile .l { font-size: 13px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.svc { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.svc:first-of-type { border-top: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--away); }
.dot.up { background: var(--active); box-shadow: 0 0 0 3px var(--ok-weak); }
.dot.down { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-weak); }
.dot.degraded { background: var(--idle); box-shadow: 0 0 0 3px var(--warn-weak); }
.svc .name { font-weight: 550; min-width: 130px; }
.svc .detail { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc .ms { font-size: 12px; color: var(--muted); width: 54px; text-align: right; }
.linkrow { display: flex; flex-wrap: wrap; gap: 8px; }
.codebox { display: flex; gap: 10px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.codebox code { white-space: nowrap; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-weak); }
.scroll { overflow-x: auto; }
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--line); min-width: 120px; }
.bar > span { display: block; height: 100%; }
.s-active { background: var(--active); }
.s-idle { background: var(--idle); }
.s-away { background: var(--away); }
.strip { display: flex; height: 22px; border-radius: 8px; overflow: hidden; background: var(--line); margin: 10px 0 6px; }
.strip > span { display: block; height: 100%; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 160px; }
.formrow { display: grid; grid-template-columns: 1.4fr 1fr 1.4fr auto; gap: 12px; align-items: end; }
.secret { background: var(--warn-weak); color: var(--text); border: 1px solid var(--idle); border-radius: 12px; padding: 14px 16px; margin: 14px 0; }
.secret code { font-size: 16px; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 14px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.timeline li:first-child { border-top: none; }
.timeline .t { width: 78px; color: var(--muted); flex: none; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 28, .55); display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal { width: 100%; max-width: 420px; padding: 26px; }
.modal h3 { margin-bottom: 6px; }
@media (max-width: 720px) {
  .formrow { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
  .svc .name { min-width: 100px; }
}
.lead { margin: 0 0 22px; }
.block { width: 100%; }

/* charts */
.hbars { display: grid; gap: 8px; }
.hrow { display: grid; grid-template-columns: 38% 1fr 84px; gap: 10px; align-items: center; font-size: 13px; }
.hl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hv { text-align: right; color: var(--muted); }
.cols { display: flex; gap: 6px; align-items: flex-end; height: 130px; padding-top: 6px; }
.col { flex: 1; min-width: 10px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.stack { width: 100%; height: 100px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 4px; overflow: hidden; background: var(--line); }
.stack > span { display: block; width: 100%; }
.cl { font-size: 10px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.c-good { background: var(--active); }
.c-bad { background: var(--bad); }
.notice { padding: 12px 16px; border-radius: 12px; background: var(--warn-weak); color: var(--text); border: 1px solid var(--idle); margin-bottom: 18px; font-size: 14px; }
.flagrow { white-space: nowrap; }
.sub { font-size: 12px; color: var(--muted); }
.guide { font-size: 13px; color: var(--muted); }
.guide b { color: var(--text); }
tr.flagged td { background: var(--warn-weak); }

/* feedback */
.fb { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; }
.fb-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fb-btn { appearance: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; width: 34px; height: 34px; font-size: 16px; cursor: pointer; }
.fb-btn:hover { border-color: var(--accent); }
.fb-btn.on { background: var(--accent-weak); border-color: var(--accent); }
.fb-panel { margin-top: 10px; display: grid; gap: 10px; }
.fb-panel textarea { resize: vertical; }
.chips.left { justify-content: flex-start; }
.chip.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.msg.bot .bubble { white-space: pre-wrap; }
.fb, .fb * { white-space: normal; }
.qtext { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 13px; max-height: 260px; overflow: auto; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 14px; margin: 8px 0 14px; }
.kv > span:nth-child(odd) { color: var(--muted); }
textarea.wide { min-height: 120px; }

input[type=checkbox] { width: auto; margin-right: 6px; }
details { margin: 8px 0; }
summary { cursor: pointer; font-weight: 550; }

/* security map */
.worldmap { width: 100%; height: auto; display: block; background: var(--bg); border-radius: 10px; }
.ctry { fill: var(--line); stroke: var(--card); stroke-width: .4; }
.ctry.c-use.l1 { fill: #bcd3f7; } .ctry.c-use.l2 { fill: #8fb5f0; } .ctry.c-use.l3 { fill: #5e92e6; } .ctry.c-use.l4 { fill: #2f6dd6; }
.ctry.c-bad.l1 { fill: #f6c0bd; } .ctry.c-bad.l2 { fill: #ee918c; } .ctry.c-bad.l3 { fill: #e2625b; } .ctry.c-bad.l4 { fill: #c8372f; }
.ctry.c-allow { stroke: var(--ok); stroke-width: 1.2; }
.dot { fill: #2563eb; stroke: #fff; stroke-width: 1; fill-opacity: .9; } .dot.hot { fill: #dc2626; }
.glow { fill: #2563eb; fill-opacity: .18; } .glow.hot { fill: #dc2626; fill-opacity: .22; }
.maplegend { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.sw { display: inline-block; width: 14px; height: 10px; border-radius: 3px; margin-right: -8px; }
.sw-use { background: #5e92e6; } .sw-bad { background: #e2625b; } .sw-allow { background: var(--card); border: 2px solid var(--ok); }
.chips.left { justify-content: flex-start; margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.check input { width: auto; }
.secret { font-size: 18px; letter-spacing: 1px; user-select: all; }
