:root, html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07111c;
  --panel: #0c1928;
  --line: #1d3550;
  --text: #e7f2fb;
  --muted: #8ea6bd;
  --accent: #1494c8;
  --shadow: 0 18px 50px #02060c66;
  --side: #08131f;
  --top: #081421;
  --input: #091421;
  --nav: #c5d7e6;
  --nav-active: #12344c;
  --nav-badge: #b7e9f8;
  --foot: #0c1c2d;
  --chip: #0d1d2e;
  --chip-text: #d5e6f3;
  --filter: #0b1726;
  --thread-line: #173049;
  --thread-selected: #10283b;
  --preview: #b7c9d8;
  --page: #08131f;
  --thread-bg: #09131f;
  --context: #0b1724;
  --composer: #0c1928;
  --bubble-in: #13283c;
  --bubble-out: #0e6488;
  --bubble-note: #16140f;
  --note-line: #6d5a32;
  --note-text: #f0e2c4;
  --gate: #0c1a2bcc;
  --hint: #ffd7a8;
  --danger-text: #ffb4b4;
  --danger-line: #6a3030;
  --member: #0b1726;
  --member-on: #12344c;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: #ffffff;
  --line: #d5e2ee;
  --text: #143049;
  --muted: #5d7388;
  --accent: #0878b7;
  --shadow: 0 18px 40px #14304914;
  --side: #f8fbfd;
  --top: #ffffff;
  --input: #ffffff;
  --nav: #1d3c56;
  --nav-active: #0878b7;
  --nav-badge: #0878b7;
  --foot: #ffffff;
  --chip: #f4f8fb;
  --chip-text: #1d3c56;
  --filter: #ffffff;
  --thread-line: #e6eef5;
  --thread-selected: #e8f5fb;
  --preview: #4d6578;
  --page: #eef3f8;
  --thread-bg: #f7fafc;
  --context: #ffffff;
  --composer: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #0878b7;
  --bubble-note: #fff8ee;
  --note-line: #e4d0b0;
  --note-text: #6a5332;
  --gate: #ffffff;
  --hint: #8a5a16;
  --danger-text: #a12626;
  --danger-line: #e7b8b8;
  --member: #ffffff;
  --member-on: #e8f5fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #67d2f1;
  outline-offset: 2px;
}

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    radial-gradient(circle at 15% 10%, #1494c833, transparent 26rem),
    radial-gradient(circle at 90% 90%, #0c6f9633, transparent 24rem),
    var(--bg);
}
.gate-card {
  width: min(440px, 100%);
  background: var(--gate);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand img { width: 52px; height: 52px; }
.brand b { display: block; font-size: 22px; letter-spacing: -.4px; }
.brand span, .eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 1.4px; }
.gate-card h1 { font-size: 28px; margin: 22px 0 8px; letter-spacing: -.6px; }
.gate-card > p, .muted { color: var(--muted); line-height: 1.55; }
form { display: grid; gap: 12px; margin-top: 22px; }
label { display: grid; gap: 6px; font-size: 12px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--input);
  border-radius: 10px;
  padding: 11px 12px;
}
textarea { resize: vertical; min-height: 78px; }
.primary, .ghost, .danger {
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 800;
  font-size: 13px;
}
.primary { border: 0; background: linear-gradient(180deg, #1aa3d4, #0d7eab); color: white; }
.ghost, .danger { background: transparent; border: 1px solid var(--line); }
.danger { color: var(--danger-text); border-color: var(--danger-line); }
.error {
  background: #3a1a1f;
  color: #ffc1c1;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}
.fine { font-size: 12px; color: var(--muted); }

.shell { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 236px minmax(0, 1fr); overflow: hidden; }
.side {
  background: var(--side);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.nav { display: grid; gap: 4px; margin-top: 22px; }
.nav button, .icon-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--nav);
  border-radius: 10px;
  padding: 11px 12px;
  font-weight: 700;
}
.nav button.active { background: var(--nav-active); color: white; box-shadow: inset 3px 0 #5ad2f0; }
.nav-ico { width: 22px; height: 22px; flex: 0 0 22px; stroke: currentColor; fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.nav-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.nav-bottom .nav-ico { width: 24px; height: 24px; flex-basis: 24px; stroke-width: 2.4; }
.nav b {
  margin-left: auto;
  background: #1494c833;
  color: var(--nav-badge);
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
  font-size: 11px;
  padding: 2px 6px;
}
.side-foot { margin-top: auto; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--foot); }
.side-foot strong { display: block; }
.side-foot span { color: var(--muted); font-size: 12px; }
.who { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 10px; }

.main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--top);
  min-width: 0;
}
.top h1 { margin: 0; font-size: 16px; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.pill {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--chip-text);
  white-space: nowrap;
}
.pill em { font-style: normal; color: var(--muted); margin-right: 6px; }
.pill.ok { color: #b7f0d4; border-color: #1d5c42; }
.pill.warn { color: #ffd7a8; border-color: #6d4c22; }

.workspace { min-height: 0; min-width: 0; height: 100%; display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr) minmax(230px, 280px); }
.col { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.col + .col { border-left: 1px solid var(--line); }
.col-head { padding: 14px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button, .small {
  border: 1px solid var(--line);
  background: var(--filter);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.filters button.active { background: #14384f; border-color: #1d6d8d; color: white; }
.list { overflow: auto; }
.thread {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--thread-line);
  background: transparent;
  padding: 14px;
}
.thread.selected { background: var(--thread-selected); box-shadow: inset 3px 0 var(--accent); }
.thread-top, .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.thread small, .meta { color: var(--muted); font-size: 12px; }
.preview { color: var(--preview); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 10px; font-weight: 800; letter-spacing: .3px; border-radius: 999px; padding: 3px 7px; }
.tag.queue { background: #3d2a12; color: #ffd7a1; }
.tag.mine { background: #12382c; color: #b6f0d4; }
.tag.closed { background: #243140; color: #c5d3e0; }
.tag.out { background: #3d2218; color: #ffc7a3; }

.thread-view { background: var(--thread-bg); }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: min(78%, 620px); padding: 11px 13px; border-radius: 14px; line-height: 1.5; font-size: 14px; white-space: pre-wrap; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: white; border-bottom-right-radius: 4px; }
.bubble.note, .bubble.system { align-self: stretch; max-width: none; background: var(--bubble-note); border: 1px dashed var(--note-line); color: var(--note-text); font-size: 13px; }
.bubble footer { display: flex; gap: 8px; margin-top: 6px; color: #d5e7f2cc; font-size: 11px; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; background: var(--composer); }
.composer-row { display: flex; gap: 8px; align-items: end; }
.composer-row textarea { flex: 1; }
.hint { font-size: 12px; color: var(--hint); }
.context { overflow: auto; background: var(--context); }
.block { padding: 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.block h2 { margin: 0; font-size: 15px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding-top: 8px; border-top: 1px solid var(--thread-line); }
.kv span { color: var(--muted); }
.kv b { min-width: 0; overflow-wrap: anywhere; text-align: right; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 28px; max-width: 360px; }
.empty h2 { color: var(--text); }

.page { overflow: auto; padding: 22px; background: var(--page); }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.card b { display: block; font-size: 28px; margin-top: 6px; }
.panel { margin-top: 14px; }
.panel h2 { margin: 0 0 6px; font-size: 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--thread-line); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-size: 11px; letter-spacing: .8px; text-transform: uppercase; }
.split { display: grid; grid-template-columns: 1.3fr .7fr; gap: 14px; align-items: start; }
.template { padding: 12px 0; border-bottom: 1px solid var(--thread-line); }
.template b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.banner {
  border: 1px solid #6d4c22;
  background: #2a2116;
  color: #ffe0bc;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}
.banner.ok { border-color: #1d5c42; background: #10281f; color: #c8f5df; margin-bottom: 14px; }
#accountForm, #userForm { display: grid; gap: 12px; }
#userForm { margin-top: 14px; }
input:disabled { opacity: .72; }
.member-list { display: grid; gap: 8px; margin: 12px 0; max-height: 280px; overflow: auto; }
.member { display: grid; text-align: left; border: 1px solid var(--line); background: var(--member); border-radius: 10px; padding: 10px 12px; }
.member.selected { border-color: var(--accent); background: var(--member-on); }
.theme-switch { display: flex; padding: 3px; border-radius: 999px; background: var(--filter); border: 1px solid var(--line); }
.theme-switch button { border: 0; background: transparent; color: var(--muted); border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; }
.theme-switch button.active { background: var(--accent); color: white; }
.gate .theme-switch { justify-self: start; margin-top: 18px; }
html[data-theme="light"] .filters button.active { background: var(--accent); border-color: var(--accent); }
html[data-theme="light"] .nav button.active b { background: #ffffff33; color: white; }
html[data-theme="light"] .bubble.out footer { color: #e7f6ff; }
html[data-theme="light"] .pill.ok { background: #e8f8ef; color: #146c43; border-color: #b7e4c7; }
html[data-theme="light"] .pill.warn { background: #fff6ea; color: #8a5a16; border-color: #f0d7b4; }
html[data-theme="light"] .tag.queue { background: #fff1df; color: #8a5a16; }
html[data-theme="light"] .tag.mine { background: #e5f6ee; color: #146c43; }
html[data-theme="light"] .tag.closed { background: #eef2f6; color: #52687a; }
html[data-theme="light"] .tag.out { background: #fff1df; color: #8a5a16; }
html[data-theme="light"] .error { background: #fff1f1; color: #8d2424; }
html[data-theme="light"] .banner { background: #fff8ee; color: #6a5332; border-color: #ead7b8; }
html[data-theme="light"] .banner.ok { background: #eefaf3; color: #146c43; border-color: #b7e4c7; }
.member small { color: var(--muted); margin-top: 4px; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(210px, 260px) minmax(0, 1fr); }
  .context { grid-column: 1 / -1; border-top: 1px solid var(--line); max-height: 280px; }
  .cards, .split { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 12px; }
  .nav-bottom { grid-template-columns: 1fr; margin-top: 8px; }
  .nav button { justify-content: center; flex-direction: column; gap: 4px; padding: 8px; font-size: 11px; }
  .nav b, .side-foot { display: none; }
  .workspace, .cards, .split { grid-template-columns: 1fr; }
  .main { grid-template-rows: auto minmax(50vh, 1fr); }
  .top { align-items: flex-start; flex-direction: column; padding: 12px; }
  .messages { min-height: 280px; }
}
