:root {
  --ink: #16181d;
  --muted: #5e635c;
  --line: rgba(22, 24, 29, 0.1);
  --paper: #f3f0e8;
  --paper-2: #e7e2d6;
  --rail: #12141a;
  --rail-2: #1c1f27;
  --rail-text: #f4f1ea;
  --rail-dim: #a7aaa4;
  --accent: #1f7a4d;
  --accent-ink: #f4f1ea;
  --danger: #8d3424;
  --shadow: 0 18px 50px rgba(18, 20, 26, 0.16);
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --space: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.brand-mark {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--space) * 3);
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(31, 122, 77, 0.16), transparent 55%),
    var(--paper);
}
.gate-card {
  width: min(440px, 100%);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: calc(var(--space) * 4);
  box-shadow: var(--shadow);
}
.gate-card h1 {
  margin: calc(var(--space) * 2) 0 calc(var(--space) * 1);
  font-size: 40px;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-weight: 600;
}
.lede { margin: 0 0 calc(var(--space) * 3); color: var(--muted); max-width: 36ch; }
.auth-switch { display: block; width: 100%; min-height: 44px; margin: 14px auto 0; color: var(--accent); font-weight: 700; font-size: 16px; }
.read-filter { margin: 0 16px 8px; }
.auth-note { margin-top: 16px; margin-bottom: 0; }
.alert-prompt {
  position: fixed;
  z-index: 30;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: #12141a;
  color: #f3f0e8;
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.alert-prompt p { margin: 0; }
.alert-prompt div { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.alert-prompt .text-btn { color: #f3f0e8; }
.toasts {
  position: fixed;
  z-index: 25;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  width: min(320px, calc(100% - 32px));
}
.toast {
  background: #12141a;
  color: #f3f0e8;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.toast strong { display: block; margin-bottom: 4px; }
.toast span { color: #c9c3b6; font-size: 14px; }
.field { display: grid; gap: 6px; margin-bottom: calc(var(--space) * 2); }
.field span { font-size: 13px; font-weight: 600; }
.field small { color: var(--muted); }
.field input, .field select, .modal-field input:not([type="checkbox"]), .modal-field select, .msg textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
}
.form-error { color: var(--danger); margin: 0 0 calc(var(--space) * 2); }
.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { opacity: 0.55; }
.text-btn, .icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
}
.icon-btn:hover, .text-btn:hover { background: rgba(255, 255, 255, 0.06); }
.thread .icon-btn:hover, .thread .text-btn:hover { background: var(--paper-2); }

.skeleton { height: 14px; border-radius: 8px; background: linear-gradient(90deg, #e7e2d6, #f7f4ee, #e7e2d6); background-size: 200% 100%; animation: sheen 1.2s linear infinite; margin-top: 14px; }
.skeleton.short { width: 55%; }
@keyframes sheen { to { background-position: -200% 0; } }

.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 260px;
  background: var(--paper);
}
.rail, .people {
  background: var(--rail);
  color: var(--rail-text);
  min-height: 100dvh;
}
.rail { display: flex; flex-direction: column; border-right: 1px solid #000; }
.rail-head, .me, .thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px;
}
.conn { margin: 4px 0 0; color: var(--rail-dim); font-size: 13px; }
.conn.is-on { color: #b7e4c7; }
.rail-search { padding: 0 16px 12px; }
.rail-search input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--rail-2);
  color: var(--rail-text);
  border-radius: 10px;
  padding: 10px 12px;
}
.channel-list { overflow: auto; flex: 1; padding: 0 8px 12px; }
.group-label {
  margin: 16px 8px 6px;
  color: var(--rail-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.channel {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--rail-text);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.channel:hover, .channel.is-active { background: var(--rail-2); }
.avatar, .msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img, .msg-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar-btn { cursor: pointer; }
.avatar-lg { width: 96px; height: 96px; border-radius: 28px; font-size: 32px; margin: 0 auto; }
.look-stage { display: grid; justify-items: center; margin-bottom: 8px; }
.look-name, .look-blurb { margin: 0 0 12px; text-align: center; color: var(--muted); }
.look-tools { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 14px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; padding: 0; cursor: pointer; }
.swatch.is-on { border-color: #12141a; }
.avatar .dot, .member .dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #7dcea0;
  box-shadow: 0 0 0 2px var(--rail);
}
.channel-name, .channel-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-name { font-weight: 600; }
.channel-preview { color: var(--rail-dim); font-size: 13px; margin-top: 2px; }
.unread {
  min-width: 22px;
  height: 22px;
  border-radius: 99px;
  background: var(--accent);
  color: white;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0 6px;
}
.me { border-top: 1px solid rgba(255, 255, 255, 0.06); display: flex; gap: 10px; align-items: center; }
.me .text-btn { color: var(--rail-dim); padding: 6px 8px; }
.me strong { display: block; }
.me span { color: var(--rail-dim); font-size: 13px; }
.search-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.search-kinds button {
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--rail-text);
  border-radius: 99px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
}
.search-kinds button.is-on { background: var(--accent); color: #fff; }
.search-results {
  margin: 0 12px 8px;
  background: var(--rail-2);
  border-radius: 12px;
  max-height: min(52vh, 480px);
  overflow: auto;
}
.search-hit {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--rail-text);
  padding: 10px 12px;
}
.search-hit small { display: block; color: var(--rail-dim); }
.search-hit strong { display: block; }
.search-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.msg.is-hit { background: #e5f4ec; border-radius: 12px; }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
.thread-head { border-bottom: 1px solid var(--line); background: rgba(243, 240, 232, 0.9); position: sticky; top: 0; z-index: 2; }
.thread-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.person-filter {
  display: flex;
  gap: 6px;
  overflow: auto;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}
.person-filter button {
  border: 0;
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 99px;
  padding: 6px 12px;
  font-weight: 600;
  white-space: nowrap;
}
.person-filter button.is-on { background: var(--accent); color: #fff; }
.thread-actions .text-btn { padding: 8px 10px; border-radius: 10px; font-weight: 600; }
.thread-title h1 { margin: 0; font-size: 22px; letter-spacing: -0.03em; font-weight: 600; }
.thread-meta { margin: 2px 0 0; color: var(--muted); font-size: 13px; font-family: var(--mono); }
.messages { flex: 1; overflow: auto; padding: 18px 22px 8px; }
.day {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 18px 0;
}
.msg { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; margin-bottom: 14px; }
.msg.system { grid-template-columns: 1fr; }
.msg.system p { color: var(--muted); font-size: 13px; margin: 0; text-align: center; }
.msg-avatar { width: 36px; height: 36px; border-radius: 12px; }
.msg header { display: flex; gap: 8px; align-items: baseline; }
.msg header strong { font-weight: 600; }
.msg time, .msg .tools { color: var(--muted); font-size: 12px; }
.msg .tools { background: none; border: none; cursor: pointer; padding: 0; font: inherit; }
.msg .tools:hover { color: var(--accent); }
.edited-badge {
  font-size: 11px;
  color: var(--muted);
  cursor: default;
  user-select: none;
}
.edited-badge::before { content: '('; }
.edited-badge::after  { content: ')'; }
.msg .body { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.edit-area { margin-top: 6px; }
.edit-ta {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  padding: 8px 10px;
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  white-space: pre-wrap;
}
.edit-btns { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.msg a { color: var(--accent); }
.mention { background: #e5f4ec; border-radius: 6px; padding: 0 4px; }
.biz-tag {
  display: inline-block;
  background: #e7f3ec;
  color: #1a6640;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 5px;
  vertical-align: middle;
  letter-spacing: 0.01em;
}
.reply-quote {
  border-left: 2px solid var(--accent);
  padding-left: 8px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}
.attach-link { display: inline-block; margin-top: 6px; margin-right: 8px; }
.empty {
  margin: auto;
  max-width: 360px;
  color: var(--muted);
}
.empty h2 { color: var(--ink); letter-spacing: -0.03em; margin-bottom: 6px; }

.photo, .photo-link img {
  display: block;
  max-width: min(360px, 100%);
  max-height: 320px;
  border-radius: 14px;
  margin-top: 8px;
}
.voice-note { display: block; width: min(280px, 100%); margin-top: 8px; }
.composer { position: relative; border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #fffdf8; }
.mention-menu {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(100% - 8px);
  max-height: min(320px, 46dvh);
  overflow: auto;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(20, 24, 20, 0.12);
  z-index: 5;
  padding: 6px;
}
.mention-label { margin: 8px 8px 4px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.mention-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.mention-item small { display: block; color: var(--muted); }
.mention-item.is-on, .mention-item:hover { background: #e7f3ec; }
.mention-item .avatar { width: 32px; height: 32px; border-radius: 10px; font-size: 12px; }
.mention-empty { margin: 8px; color: var(--muted); font-size: 13px; }
.composer-row { display: grid; grid-template-columns: auto auto auto minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.record-status { margin: 0 0 8px; color: var(--danger); font-size: 13px; font-weight: 600; }
.icon-btn.is-recording { background: #f3d6d0; color: var(--danger); }
.file-chip img { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; vertical-align: middle; margin-right: 6px; }
.hotkeys {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.hotkeys kbd {
  font-family: inherit;
  font-size: 11px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 4px;
  background: #fff;
}
.composer textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  max-height: 160px;
  background: #fff;
}
.reply-bar, .file-chips { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.file-chip { background: var(--paper-2); border-radius: 999px; padding: 4px 10px; }

.people { padding: 18px 16px; border-left: 1px solid #000; }
.people h2 { margin: 0 0 12px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rail-dim); font-weight: 600; }
.people ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.member { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: center; }
.member small { color: var(--rail-dim); }

.menu {
  position: absolute;
  z-index: 5;
  background: #fffdf8;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 6px;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 10px 12px;
}
.menu button:hover { background: var(--paper); }

dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  width: min(480px, calc(100% - 24px));
  background: #fffdf8;
  color: var(--ink);
}
dialog.is-settings { width: min(680px, calc(100% - 24px)); }
dialog.is-settings #modal-body { max-height: min(70dvh, 640px); overflow: auto; padding-right: 4px; }
.settings-you {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.settings-you .avatar { width: 48px; height: 48px; border-radius: 16px; font-size: 16px; }
.settings-you strong { display: block; }
.settings-you small { color: var(--muted); }
.settings-summary {
  margin: 14px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #e7f3ec;
  color: #143628;
  line-height: 1.45;
}
.settings-block { margin: 8px 0 18px; }
.settings-block h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: -0.02em; }
.switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.switch-row strong { display: block; font-size: 15px; }
.switch-row small { display: block; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.switch-row input {
  appearance: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 99px;
  background: #d9d3c7;
  position: relative;
  cursor: pointer;
  flex: none;
}
.switch-row input::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform 0.18s ease;
}
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(18px); }
.switch-row input:active { transform: scale(0.98); }
.choice-row { display: grid; gap: 8px; }
.choice-row button {
  display: grid;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.choice-row button:active { transform: scale(0.99); }
.choice-row button small { color: var(--muted); }
.choice-row button.is-on { border-color: var(--accent); background: #e7f3ec; }
.settings-note { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
dialog::backdrop { background: rgba(18, 20, 26, 0.45); }
#modal-form { padding: 22px; }
#modal-form h2 { margin: 0 0 14px; letter-spacing: -0.03em; }
.modal-field { display: grid; gap: 6px; margin-bottom: 12px; }
.biz-pick {
  display: grid;
  gap: 4px;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  background: #fff;
}
.biz-option {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.biz-option small { color: var(--muted); }
.biz-option:hover { background: #e7f3ec; }
.checks { display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.checks label {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 40px;
  padding: 4px 8px;
  border-radius: 10px;
}
.checks label:hover { background: var(--paper-2); }
.checks input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: 0 0 18px;
  accent-color: var(--accent);
}
.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 420px; overflow: auto; }
.roster li { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.roster small { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.mobile-only { display: none; }

@media (max-width: 1180px) {
  .shell { grid-template-columns: 280px minmax(0, 1fr); }
  .people { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .thread, .people { display: none; }
  .shell.show-thread .rail { display: none; }
  .shell.show-thread .thread { display: flex; height: 100dvh; min-height: 0; }
  .mobile-only { display: grid; }
  .gate-card h1 { font-size: 34px; }
  .messages { padding: 12px 12px 8px; }
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer-row { grid-template-columns: auto auto auto minmax(0, 1fr); }
  .send-btn { grid-column: 1 / -1; }
  .icon-btn { width: 44px; height: 44px; }
  .settings-you { grid-template-columns: auto minmax(0, 1fr); }
  .settings-you .text-btn { grid-column: 1 / -1; justify-self: start; }
  .thread-title h1 { font-size: 18px; }
}
