:root {
  --bg: #14161a;
  --panel: #1c1f25;
  --panel-2: #252931;
  --line: #333843;
  --text: #e6e8ec;
  --muted: #98a0ad;
  --accent: #5b8def;
  --ok: #3fb27f;
  --warn: #e0a83a;
  --danger: #e5534b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0; font-size: 22px; }
h2 { margin: 28px 0 8px; font-size: 16px; }
h2:first-child { margin-top: 0; }
small { display: block; color: var(--muted); font-size: 13px; }
a { color: var(--accent); overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

button, select, input { font: inherit; color: inherit; }
button, .file-button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover, .file-button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary, .file-button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-color: var(--danger); color: var(--danger); }
button.small { padding: 3px 9px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=password], input[type=search], input[type=number], select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 0;
}
input[type=number] { width: 110px; }

.pill {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 20px;
}
.pill.ok { background: rgba(63, 178, 127, .18); color: var(--ok); }
.pill.warn { background: rgba(224, 168, 58, .18); color: var(--warn); }
.pill.off { background: rgba(229, 83, 75, .15); color: var(--danger); }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
}
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.login-card label { display: grid; gap: 4px; font-size: 14px; }
.error { color: var(--danger); margin: 0; }

/* ---------- layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand, .account { display: flex; align-items: center; gap: 10px; }
.account { margin-left: auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tab { border-color: transparent; background: none; color: var(--muted); }
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
button.ghost { background: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px; }
.panel { min-width: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.card b { display: block; font-size: 17px; overflow-wrap: anywhere; }

.rows { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.rows:empty { display: none; }
.rows > p { margin: 0; padding: 10px 14px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.row select, .row input[type=text] { width: 260px; max-width: 50%; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.switch { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar h2 { margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.inline-form input { flex: 1; max-width: 320px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 12px; }
.chip button { border: 0; background: none; padding: 0 6px; color: var(--muted); }

/* ---------- banned images ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 12px; }
.thumb { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; gap: 6px; }
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; filter: blur(14px); background: var(--bg); }
.thumb { overflow: hidden; }
.grid.revealed .thumb img { filter: none; }
.thumb figcaption { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- messages ---------- */
.messages-panel { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 12px; height: calc(100vh - 110px); min-height: 380px; }
.channels { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow-y: auto; }
.channels select { width: 100%; margin-bottom: 6px; }
.category { margin: 10px 6px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.channel { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 4px 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel:hover:not(:disabled), .channel.active { background: var(--panel-2); color: var(--text); }

.chat { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.chat-scroll { flex: 1; overflow-y: auto; padding: 10px 14px; }
#chat-older { display: block; margin: 0 auto 10px; }

.msg { display: flex; gap: 10px; padding: 6px 4px; border-radius: 6px; }
.msg:hover { background: rgba(255, 255, 255, .03); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--panel-2); flex: none; }
.msg-main { min-width: 0; flex: 1; }
.msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.msg-head time { color: var(--muted); font-size: 12px; }
.msg-delete { margin-left: auto; padding: 0 8px; font-size: 12px; border-color: transparent; background: none; color: var(--danger); visibility: hidden; }
.msg:hover .msg-delete, .msg-delete:focus-visible { visibility: visible; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-body > * + * { margin-top: 4px; }
.attachment { display: block; max-width: min(100%, 360px); max-height: 280px; border-radius: 6px; }
.file { display: block; color: var(--muted); }
a.file { color: var(--accent); }
.embed { border-left: 3px solid var(--line); background: var(--bg); border-radius: 4px; padding: 8px 10px; max-width: 520px; }
.embed-title { display: block; }
.embed-field { margin-top: 6px; }
.forward { border-left: 3px solid var(--accent); padding-left: 10px; margin-top: 4px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 40px));
  background: var(--panel-2);
  border: 1px solid var(--ok);
  border-radius: 8px;
  padding: 10px 14px;
}
.toast.error { border-color: var(--danger); }

@media (max-width: 720px) {
  main { padding: 12px; }
  .messages-panel { grid-template-columns: 1fr; height: auto; }
  .channels { max-height: 200px; }
  .chat { height: 70vh; }
  .row { flex-wrap: wrap; }
  .row select, .row input[type=text] { width: 100%; max-width: 100%; }
}
