:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #ececea;
  --text: #17181b;
  --muted: #6b6e75;
  --line: #dcdcd8;
  --accent: #c8312b;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26b00;
  --bad: #c8312b;
  --link: #1f5fbf;
  --self: #2a6fdb;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #272a31;
    --text: #e9e9e6;
    --muted: #9599a2;
    --line: #30343c;
    --accent: #e0463f;
    --ok: #3dbb72;
    --warn: #e6a23c;
    --bad: #ff6b63;
    --link: #7fb0ff;
    --self: #7fb0ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a; --surface: #1d2025; --surface-2: #272a31; --text: #e9e9e6; --muted: #9599a2; --line: #30343c;
  --accent: #e0463f; --ok: #3dbb72; --warn: #e6a23c; --bad: #ff6b63; --link: #7fb0ff; --self: #7fb0ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.screen { min-height: 100%; display: flex; flex-direction: column; }

/* login */
#login { align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.brand { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.login-card input { font-size: 16px; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); }
.err { color: var(--bad); margin: 0; }

/* topo */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 17px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: none; border: 0; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--ok); }
.conn.off { background: var(--bad); }

.view { flex: 1; display: flex; flex-direction: column; }
#home { padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px); gap: 12px; }

.banner { padding: 12px 16px; font-weight: 600; }
.banner.urgent { background: var(--accent); color: var(--accent-text); }
.banner.warn { background: var(--surface-2); color: var(--warn); font-weight: 500; font-size: 14px; }

/* chips de status */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.ok i { background: var(--ok); }
.chip.bad i { background: var(--bad); }
.chip.warn i { background: var(--warn); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--bad); }
.pill.warn { color: var(--warn); }
.big-line { font-size: 22px; font-weight: 700; margin: 2px 0 10px; }
.big-line small { font-size: 14px; font-weight: 400; color: var(--muted); }

.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 0; min-width: 0; }
.btn {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px;
  padding: 11px 12px; font-weight: 600; cursor: pointer; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; flex: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.speed-body { font-size: 14px; }
.speed-body .nums { display: flex; gap: 16px; font-variant-numeric: tabular-nums; margin: 4px 0; }
.speed-body .nums b { font-size: 18px; }
.speed-body a { color: var(--link); word-break: break-all; }
.muted { color: var(--muted); }

.buflist { list-style: none; margin: 0; padding: 0; }
.buflist li { border-top: 1px solid var(--line); }
.buflist li:first-child { border-top: 0; }
.buflist button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 2px;
  background: none; border: 0; text-align: left; cursor: pointer; }
.buflist .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buflist .name.parted { color: var(--muted); font-weight: 400; }
.buflist .last { color: var(--muted); font-size: 12px; }
.badge { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); font-size: 12px;
  text-align: center; font-variant-numeric: tabular-nums; }
.badge.hl { background: var(--accent); color: var(--accent-text); }
.foot { text-align: center; margin: 4px 0 0; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; }

/* conversa */
#bufview { min-height: 0; height: calc(100dvh - 52px - env(safe-area-inset-top)); }
.buf-tools { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line);
  font-size: 13px; }
.spacer { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.log { flex: 1; overflow-y: auto; padding: 8px 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.line { padding: 2px 0; word-wrap: break-word; overflow-wrap: anywhere; }
.line time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-right: 6px; }
.line .nick { font-weight: 600; }
.n0 { color: #c0392b; } .n1 { color: #2e7d32; } .n2 { color: #1565c0; } .n3 { color: #8e24aa; }
.n4 { color: #ef6c00; } .n5 { color: #00838f; } .n6 { color: #ad1457; } .n7 { color: #5d4037; }
.n8 { color: #6a7d00; } .n9 { color: #3949ab; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .n0 { color: #ff7b72; } :root:not([data-theme="light"]) .n1 { color: #7ee787; }
  :root:not([data-theme="light"]) .n2 { color: #79c0ff; } :root:not([data-theme="light"]) .n3 { color: #d2a8ff; }
  :root:not([data-theme="light"]) .n4 { color: #ffa657; } :root:not([data-theme="light"]) .n5 { color: #56d4dd; }
  :root:not([data-theme="light"]) .n6 { color: #ff9bce; } :root:not([data-theme="light"]) .n7 { color: #d8b48a; }
  :root:not([data-theme="light"]) .n8 { color: #c9d36a; } :root:not([data-theme="light"]) .n9 { color: #a5b4fc; }
}
.line.self .nick { color: var(--self); }
.line.hl { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 6px; margin: 0 -6px;
  padding: 2px 6px; }
.line.meta { color: var(--muted); font-size: 13px; }
.line.error { color: var(--bad); font-size: 13px; }
.line a { color: var(--link); }
.more { display: block; margin: 4px auto 10px; }
.composer { display: flex; gap: 8px; padding: 8px 16px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line); background: var(--bg); }
.composer input { flex: 1; min-width: 0; font-size: 16px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 20;
  padding: 12px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg); font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog p { margin: 0 0 8px; font-weight: 600; }
dialog code { display: block; padding: 8px; border-radius: 8px; background: var(--surface-2); word-break: break-all;
  font-size: 13px; }
