:root {
  --bg: #14161a;
  --bg-alt: #1b1e24;
  --panel: #21252c;
  --border: #2c313a;
  --text: #e6e9ef;
  --muted: #8b93a1;
  --accent: #5aa9e6;
  --accent-soft: #2b4a63;
  --danger: #e06c75;
  --online: #6cc070;
  --offline: #5a6069;
  --nick-0: #e06c75;
  --nick-1: #e5c07b;
  --nick-2: #98c379;
  --nick-3: #56b6c2;
  --nick-4: #61afef;
  --nick-5: #c678dd;
  --nick-6: #d19a66;
  --nick-7: #7ec8a9;
  --nick-8: #e28fb6;
  --nick-9: #a3bee0;
  --nick-10: #b3c777;
  --nick-11: #d9a0d0;
  --scrollbar-thumb: #383e47;
  --scrollbar-thumb-hover: #4a515c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner { background: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--accent); }

.muted { color: var(--muted); }

.error {
  color: var(--danger);
  background: rgba(224, 108, 117, 0.1);
  padding: 8px 10px;
  border-radius: 6px;
}

button {
  font: inherit;
  cursor: pointer;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
}

button[type="submit"], .auth-card button {
  background: var(--accent);
  color: #08131c;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-weight: 600;
  width: 100%;
}

.link {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  width: auto;
}
.link:hover { color: var(--text); }
.link.danger:hover { color: var(--danger); }

.auth { display: grid; place-items: center; min-height: 100vh; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-card h1 { margin: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }

.app {
  display: flex;
  position: fixed;
  top: var(--app-offset, 0px);
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
}

body.app-body {
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width, 280px);
  flex: none;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-toggle {
  margin: 8px 16px 12px;
  font-size: 12px;
  text-align: left;
}

.resizer {
  flex: none;
  width: 5px;
  cursor: col-resize;
  background: transparent;
}
.resizer:hover { background: var(--accent-soft); }

body.resizing {
  cursor: col-resize;
  user-select: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: 0.5px; }
.user { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.user .icon {
  font-size: 16px;
  line-height: 1;
  padding: 3px;
  text-decoration: none;
}
.user .icon:hover { color: var(--text); }

.networks { padding: 8px; display: flex; flex-direction: column; gap: 12px; }
.empty { padding: 16px; font-size: 13px; }

.network { display: flex; flex-direction: column; gap: 4px; }
.network-title { position: relative; }
.network-title-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  padding: 5px 30px 5px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.network-title-btn:hover { background: var(--panel); }
.network-title-btn.active { background: var(--accent-soft); }
.network-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.network-add {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.network-add:hover { color: var(--text); background: var(--panel); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); flex: none; }
.dot.online { background: var(--online); }

.channel-list { list-style: none; margin: 0; padding: 0; }
.channel-row { position: relative; }
.channel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  padding: 5px 30px 5px 22px;
  border-radius: 6px;
  font-size: 13px;
}
.channel:hover { background: var(--panel); color: var(--text); }
.channel.active { background: var(--accent-soft); color: var(--text); }

.leave {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
}
.channel-row:hover .leave { opacity: 1; }
.leave:hover { color: var(--danger); background: var(--bg-alt); }

.channel-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  background: var(--accent);
  color: #08131c;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.join-box { padding: 8px 12px; }
.join-box input { font-size: 13px; }

.connectivity-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #b7791f;
  color: #fff;
  text-align: center;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

.panel { border-top: 1px solid var(--border); padding: 10px 14px; }
.panel summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.field textarea { font: inherit; resize: vertical; min-height: 2.6em; }
.field .hint { font-size: 12px; line-height: 1.4; }
.field .hint code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 3px;
}

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; height: var(--app-height, 100dvh); overflow: hidden; }
.channel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.channel-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-header .icon-button { padding: 5px 8px; }
#toggle-members { margin-left: auto; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.msg { display: flex; gap: 10px; line-height: 1.5; align-items: baseline; }
.msg .time {
  flex: 0 0 68px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.msg .nick { flex: 0 0 auto; min-width: 4.5em; font-weight: 600; color: var(--accent); }
.msg .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg .body a { color: var(--accent); text-decoration: none; }
.msg .body a:hover { text-decoration: underline; }
.msg.kind-action .body, .msg.kind-history_action .body { font-style: italic; color: var(--muted); }
.msg.kind-action .nick, .msg.kind-history_action .nick { color: inherit; }
.msg.kind-notice .body, .msg.kind-history_notice .body { color: #d8b26a; }
.msg.kind-join .body, .msg.kind-part .body, .msg.kind-quit .body,
.msg.kind-mode .body, .msg.kind-kick .body, .msg.kind-topic .body,
.msg.kind-nick .body, .msg.kind-away .body, .msg.kind-account .body,
.msg.kind-status .body, .msg.kind-history .body {
  color: var(--muted);
  font-size: 13px;
}
.msg.kind-join .nick, .msg.kind-part .nick, .msg.kind-quit .nick,
.msg.kind-nick .nick, .msg.kind-away .nick, .msg.kind-account .nick,
.msg.kind-status .nick { color: var(--muted); }
.msg.kind-error .body { color: var(--danger); }
.msg.kind-error .nick { color: var(--danger); }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.composer input { flex: 1; }
.composer button { width: auto; }

.members {
  width: var(--members-width, 190px);
  flex: none;
  background: var(--bg-alt);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 8px;
}
.members-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 0 8px 8px;
}
.members ul { list-style: none; margin: 0; padding: 0; }
.members li {
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.members li .prefix { color: var(--accent); font-weight: 700; }
.members li.op .prefix { color: var(--online); }
.members li:hover { background: var(--panel); }

.row-actions { display: flex; align-items: center; gap: 12px; }
.row-actions button[type="submit"] { width: auto; }

.icon-button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  padding: 7px 10px;
  line-height: 1;
}
.icon-button:hover { color: var(--text); border-color: var(--accent); }

.ok {
  color: var(--online);
  background: rgba(108, 192, 112, 0.1);
  padding: 8px 10px;
  border-radius: 6px;
}

.settings-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-header { display: flex; align-items: baseline; justify-content: space-between; }
.settings-header h1 { margin: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h2 { margin: 0; font-size: 16px; }
.card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card .row.checkbox { justify-content: flex-start; gap: 8px; }
.card .row.checkbox input { width: auto; }
.card .row select { width: auto; min-width: 140px; }
.card code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

.network-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.network-item + .network-item { margin-top: 8px; }
.network-item > summary {
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.network-item > summary .net-name { font-weight: 600; }
.add-network > summary { color: var(--accent); }
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

[data-compact="compact"] .messages { gap: 0; padding: 10px 20px; }
[data-compact="compact"] .msg { line-height: 1.3; }
[data-timestamps="0"] .msg .time { display: none; }
[data-events="0"] .msg.kind-join,
[data-events="0"] .msg.kind-part,
[data-events="0"] .msg.kind-quit,
[data-events="0"] .msg.kind-nick,
[data-events="0"] .msg.kind-away,
[data-events="0"] .msg.kind-account,
[data-events="0"] .msg.kind-mode,
[data-events="0"] .msg.kind-status,
[data-events="0"] .msg.kind-history { display: none; }

[data-theme="light"] {
  --bg: #ffffff;
  --bg-alt: #f4f5f7;
  --panel: #eceef1;
  --border: #d8dbe0;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #1f6fd6;
  --accent-soft: #d6e6fb;
  --danger: #c0392b;
  --online: #2e9e44;
  --offline: #b0b6be;
  --nick-0: #c0392b;
  --nick-1: #b7791f;
  --nick-2: #2f855a;
  --nick-3: #2c7a7b;
  --nick-4: #2b6cb0;
  --nick-5: #805ad5;
  --nick-6: #a05a1f;
  --nick-7: #276749;
  --nick-8: #b83280;
  --nick-9: #3182ce;
  --nick-10: #6b7f1f;
  --nick-11: #97266d;
  --scrollbar-thumb: #c6cbd2;
  --scrollbar-thumb-hover: #aab0ba;
}
[data-theme="light"] .body { color: var(--text); }

@media (max-width: 720px) {
  .sidebar,
  .members {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 40;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.45);
  }
  .sidebar {
    left: 0;
    width: min(82vw, 320px);
    border-right: none;
  }
  .members {
    right: 0;
    width: min(78vw, 300px);
    border-left: none;
  }
  .resizer { display: none; }

  .channel-header {
    padding: 8px 10px;
  }
  .messages { padding: 10px 12px; }
  .msg { gap: 8px; }
  .msg .time { flex: 0 0 52px; font-size: 11px; }
  .msg .nick { min-width: 0; }

  .composer {
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  .composer input { padding: 10px; }
  .composer button { padding: 10px 14px; }

  .settings-page { padding: 20px 14px 48px; }
  .card .row select { min-width: 0; }
}
