:root {
  --bg: #0b1016;
  --panel: #121a23;
  --panel-2: #17212c;
  --line: #233142;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #36c2a0;
  --accent-ink: #062018;
  --warn: #f2b84b;
  --bad: #f06a6a;
  --good: #36c2a0;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
code, pre { font-family: var(--mono); }
.small { color: var(--muted); font-size: 13px; }
[hidden] { display: none !important; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; }
.shield { width: 22px; height: 26px; background: var(--accent); clip-path: polygon(50% 0, 100% 16%, 100% 52%, 50% 100%, 0 52%, 0 16%); box-shadow: 0 0 18px rgba(54,194,160,.5); }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--muted); text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.side nav a:hover { background: var(--panel-2); color: var(--text); }
.side nav a.on { background: rgba(54,194,160,.12); color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.main { padding: 22px 28px 60px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top-right { display: flex; align-items: center; gap: 10px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.tile .k { color: var(--muted); font-size: 13px; }
.tile .v { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 13px; }
.banner { border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; font-weight: 600; border: 1px solid var(--line); background: var(--panel); }
.banner.good { border-color: rgba(54,194,160,.45); background: rgba(54,194,160,.08); }
.banner.warn { border-color: rgba(242,184,75,.5); background: rgba(242,184,75,.08); }
.banner.bad { border-color: rgba(240,106,106,.55); background: rgba(240,106,106,.1); }
.banner ul { margin: 6px 0 0; padding-left: 18px; font-weight: 400; }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.chart .bar { flex: 1; background: linear-gradient(180deg, var(--accent), rgba(54,194,160,.35)); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.chart .bar:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: #000; color: #fff; padding: 3px 6px; border-radius: 4px; font-size: 12px; white-space: nowrap; margin-bottom: 4px; z-index: 2; }

/* lists */
.svc { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.svc li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.good { background: var(--good); box-shadow: 0 0 8px rgba(54,194,160,.6); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-family: var(--mono); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 7px 8px; border-bottom: 1px solid rgba(35,49,66,.6); vertical-align: middle; word-break: break-word; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.ip, .ip { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.tag.ban { color: var(--bad); border-color: rgba(240,106,106,.4); }
.tag.unban { color: var(--good); border-color: rgba(54,194,160,.4); }
.tag.found { color: var(--warn); border-color: rgba(242,184,75,.4); }
.more { text-align: center; padding-top: 10px; }

/* forms */
input, select, button, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(54,194,160,.5); outline-offset: 1px; border-color: var(--accent); }
button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 9px 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.ghost:hover { color: var(--text); }
button.danger { background: var(--bad); color: #250707; }
button.mini { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input[name="ip"] { flex: 2 1 240px; }
.row input[name="reason"], .row input[name="note"] { flex: 1 1 160px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input { flex: 1 1 200px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.log { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 12.5px; line-height: 1.5; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
.toast { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; max-width: 360px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: rgba(240,106,106,.6); }
.toast.ok { border-color: rgba(54,194,160,.6); }

/* sign-in pages */
body.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; box-sizing: border-box; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: radial-gradient(1000px 500px at 50% -10%, rgba(54,194,160,.12), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; }
.auth-card .brand { margin-bottom: 18px; }
.auth-card h1 { margin-bottom: 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.auth-card button { margin-top: 4px; padding: 11px; }
.msg.err { color: var(--bad); }
.steps { padding-left: 18px; color: var(--muted); }
.steps li { margin-bottom: 12px; }
.qr { background: #fff; border-radius: 10px; padding: 8px; width: 236px; max-width: 100%; margin: 10px 0; }
.qr svg { display: block; width: 220px; height: auto; max-width: 100%; }
.auth-card code { overflow-wrap: anywhere; }

.tiles.mini { margin-bottom: 0; }
.tiles.mini .tile { background: var(--panel-2); }
.tiles.mini .v { font-size: 26px; }

/* assistant */
.chat-log { display: flex; flex-direction: column; gap: 10px; min-height: 160px; max-height: 60vh; overflow-y: auto; padding: 4px 2px; overscroll-behavior: contain; }
.bubble { max-width: 85%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: rgba(54,194,160,.14); border: 1px solid rgba(54,194,160,.35); border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.note { align-self: center; max-width: 95%; background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; text-align: center; }
.bubble.thinking { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: vertical; min-height: 46px; max-height: 40vh; }
.pending-card { border-color: rgba(242,184,75,.55); }
.pend { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.pend:last-child { margin-bottom: 0; }
.cmd { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; box-sizing: border-box; }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg form { display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { font-size: 17px; }
.dlg p { margin: 0; overflow-wrap: anywhere; }
.dlg label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.row.end { justify-content: flex-end; }

.steps code { overflow-wrap: anywhere; }

/* phones */
@media (max-width: 900px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  html, body { overflow-x: hidden; }
  .app { grid-template-columns: 1fr; min-height: 100dvh; }
  /* sticky top bar: brand and sign-out on one line, tabs scroll sideways under it */
  .side { position: sticky; top: 0; z-index: 5; height: auto; border-right: 0; border-bottom: 1px solid var(--line);
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
  .side .brand { grid-column: 1; }
  .side-foot { grid-column: 2; grid-row: 1; margin: 0; flex-direction: row; align-items: center; }
  .side-foot #me { display: none; }
  .side nav { grid-column: 1 / -1; flex-direction: row; overflow-x: auto; gap: 2px; margin: 0 -12px; padding: 0 12px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .side nav::-webkit-scrollbar { display: none; }
  .side nav a { white-space: nowrap; padding: 0 12px; min-height: 44px; display: flex; align-items: center; }
  .main { padding: 14px max(14px, env(safe-area-inset-right)) calc(50px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .top { flex-wrap: wrap; margin-bottom: 14px; }
  .top-right { flex-wrap: wrap; }
  .card { padding: 14px; }
  .card-h { flex-wrap: wrap; }
  .tiles { gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile .v { font-size: 26px; }
  .svc { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 6px; }
  .kv dd { overflow-wrap: anywhere; }
  /* tables become stacked cards; labels come from the column headings (app.js labelTables) */
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { display: none; }
  .tbl tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; background: var(--panel-2); }
  .tbl td { display: flow-root; border: 0; padding: 5px 0; text-align: right; overflow-wrap: anywhere; }
  .tbl td[data-label]::before { content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 12px; line-height: 20px; text-transform: uppercase; letter-spacing: .04em; }
  .tbl td:not([data-label]) { text-align: left; }
  .tbl td:empty { display: none; }
  .row > *, .filters > * { flex: 1 1 100%; }
  .filters .check { flex: 1 1 auto; }
  .log { max-height: 60vh; font-size: 12px; }
  .chat-log { max-height: 55vh; max-height: 55dvh; }
  .bubble { max-width: 92%; }
  .toast { left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); max-width: none; }
  .dlg { padding: 16px; }
}
/* touch: 44px targets, 16px text in fields so Android doesn't zoom */
@media (max-width: 720px), (pointer: coarse) {
  input, select, textarea { font-size: 16px; min-height: 44px; }
  button { min-height: 44px; }
  button.mini { min-height: 44px; padding: 6px 14px; }
  .check input { min-height: 0; width: 22px; height: 22px; }
  .auth-card button { min-height: 48px; }
}
@media (max-width: 400px) {
  .auth-card { padding: 20px 16px; }
  .tile .v { font-size: 22px; }
}
