:root {
  --ink: #0c0f0d;
  --panel: #141816;
  --panel-2: #1c221e;
  --panel-3: #242b26;
  --line: rgba(236, 226, 210, 0.1);
  --text: #f4efe6;
  --muted: #b7aea3;
  --faint: #7d756c;
  --brass: #e0b07a;
  --brass-deep: #c4925c;
  --ink-on-brass: #1a140e;
  --sage: #8fbfa4;
  --coral: #e08b78;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --sans: "Outfit", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  font-weight: 440;
  background:
    radial-gradient(1100px 480px at 0% -10%, rgba(224, 176, 122, 0.14), transparent 55%),
    radial-gradient(900px 420px at 100% 0%, rgba(143, 191, 164, 0.08), transparent 50%),
    var(--ink);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.65; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.mark { width: 36px; height: 36px; display: block; flex: 0 0 auto; }
.brand-lockup { display: flex; gap: 12px; align-items: center; }
.brand-lockup strong { display: block; font-family: var(--display); font-size: 22px; font-weight: 560; letter-spacing: -0.03em; }
.brand-lockup em { display: block; margin-top: 1px; color: var(--muted); font-style: normal; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; }
.eyebrow { margin: 0 0 4px; color: var(--brass); letter-spacing: 0.16em; text-transform: uppercase; font-size: 11px; }

.gate { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; }
.gate-card {
  width: min(440px, 100%);
  padding: 32px;
  background: rgba(20, 24, 22, 0.92);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.gate-card h1 { margin: 0; font-family: var(--display); font-weight: 560; font-size: 40px; letter-spacing: -0.04em; }
.lede { color: var(--muted); line-height: 1.5; margin: 18px 0 22px; }
.stack { display: grid; gap: 14px; }
.stack label, .field { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0f1311;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
textarea { resize: none; min-height: 44px; max-height: 160px; }
.secret { position: relative; }
.secret input { padding-right: 68px; }
.peek {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--brass);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 6px;
}
input:focus, textarea:focus { border-color: rgba(224, 176, 122, 0.7); box-shadow: 0 0 0 3px rgba(224, 176, 122, 0.15); }
.primary, .ghost, .send {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--brass);
  color: var(--ink-on-brass);
  font-weight: 600;
}
.primary:hover, .send:hover { background: #ebc093; }
.ghost, .text {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 0;
}
.text:hover, .ghost:hover { color: var(--text); }
.primary.block { width: 100%; }
.form-error { margin: 0; color: var(--coral); font-size: 14px; }
.fine { margin: 22px 0 0; color: var(--faint); font-size: 12px; }
.fine span { color: var(--muted); }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 280px 340px minmax(0, 1fr);
  min-height: 0;
}
.rail, .inbox, .thread {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.rail {
  padding: 18px 14px 14px;
  border-right: 1px solid var(--line);
  background: rgba(12, 15, 13, 0.72);
}
.rail .brand-lockup { padding: 0 6px 14px; }
.rail-switch { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.account-step { display: none; }
.rail-list { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 2px; }
.rail-foot { padding-top: 12px; }
.rail-links { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 0; }
.rail-links form { margin: 0; }

.account {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 14px;
  padding: 8px;
  background: transparent;
  position: relative;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.account.dragging { opacity: 0.72; cursor: grabbing; z-index: 2; }
.account:hover { background: rgba(255, 255, 255, 0.03); }
.account.active { background: var(--panel-2); }
.account.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2px;
  border-radius: 2px;
  background: var(--brass);
}
.account .who { min-width: 0; }
.account .who strong, .dialog strong, .thread-head h2 { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account .who strong { font-weight: 560; font-size: 14px; }
.account .meta, .sub, .hint, .dialog .preview { color: var(--faint); font-size: 12px; }
.account .meta { display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.account .pending { width: 8px; height: 8px; border-radius: 99px; background: var(--brass); box-shadow: 0 0 0 3px rgba(224, 176, 122, 0.18); }
.account .unread-dot {
  position: absolute;
  top: 8px;
  left: 36px;
  width: 11px;
  height: 11px;
  border-radius: 99px;
  background: #e23d3d;
  border: 2px solid #121614;
  box-shadow: 0 0 0 1px rgba(226, 61, 61, 0.35);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 600;
  color: #f6f1e8;
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 36px; height: 36px; border-radius: 12px; font-size: 13px; }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--faint);
  flex: 0 0 auto;
}
.dot.ready { background: var(--sage); }
.dot.connecting, .dot.healing, .dot.saved { background: var(--brass); animation: pulse 1.4s ease-in-out infinite; }
.dot.offline, .dot.attention { background: var(--coral); }
.dot.banned, .dot.frozen { background: var(--faint); }
@keyframes pulse { 50% { opacity: 0.35; } }

.inbox, .thread { background: rgba(20, 24, 22, 0.55); }
.inbox { border-right: 1px solid var(--line); }
.pane-head { padding: 16px 16px 8px; min-height: 72px; }
.pane-head h2 { margin: 0; font-size: 18px; font-weight: 560; letter-spacing: -0.02em; }
.kicker { margin: 0 0 4px; color: var(--brass); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.head-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.icon-row { display: flex; gap: 6px; }
.icon-btn, .chip, .send {
  display: inline-grid;
  place-items: center;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 0;
}
.icon-btn:hover { color: var(--text); border-color: rgba(224, 176, 122, 0.45); }
.remove-link { padding: 8px 2px; white-space: nowrap; }
.icon-btn svg, .send svg { width: 18px; height: 18px; }
.search-row, .filters { padding: 0 16px; }
.search-row input { background: #101412; }
.filters { display: flex; gap: 6px; overflow: auto; padding-top: 10px; padding-bottom: 8px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.chip.on { background: var(--panel-3); color: var(--text); border-color: transparent; }

.dialog-list, .messages { flex: 1; overflow: auto; }
.dialog {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
}
.dialog:hover { background: rgba(255, 255, 255, 0.03); }
.dialog.active { background: rgba(224, 176, 122, 0.08); }
.dialog-open {
  width: 100%;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 4px 10px 16px;
  color: inherit;
}
.dialog .preview { display: flex; align-items: center; min-width: 0; margin: 3px 0 0; }
.preview-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-btn {
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 11px;
  padding: 0 14px 0 6px;
}
.pin-btn.on, .pin-head.on, .pin-mark { color: var(--brass); }
.pin-mark { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; margin-right: 6px; }
.pin-head { margin-left: auto; white-space: nowrap; }
.ticks { display: inline-flex; flex: 0 0 auto; width: 16px; height: 11px; margin-right: 4px; color: var(--faint); }
.ticks svg { width: 16px; height: 11px; }
.ticks.read { color: #8eb7ef; }
.bubble .foot .ticks { margin: 0 0 0 2px; }
.msg-menu {
  position: absolute;
  top: 28px;
  right: 8px;
  z-index: 3;
  display: grid;
  min-width: 132px;
  padding: 4px;
  background: #1c221f;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}
.msg-menu button {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
}
.msg-menu button:hover { background: rgba(255, 255, 255, 0.05); }
.forward-list { display: grid; max-height: 320px; overflow: auto; }
.forward-row {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 10px;
  padding: 9px 10px;
}
.forward-row:hover { background: rgba(255, 255, 255, 0.05); }
.dialog time, .bubble time { color: var(--faint); font-size: 11px; }
.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--brass);
  color: var(--ink-on-brass);
  font-size: 11px;
  font-weight: 600;
  display: inline-grid;
  place-items: center;
}
.kind {
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.thread { position: relative; background:
  linear-gradient(180deg, rgba(20, 24, 22, 0.2), rgba(12, 15, 13, 0.2)),
  #101412;
}
.thread-head { border-bottom: 1px solid var(--line); }
.thread-id { display: flex; gap: 12px; align-items: center; min-width: 0; }
.thread-id .sub { margin-top: 2px; }
.messages { padding: 18px 8% 12px; display: flex; flex-direction: column; gap: 6px; }
.day {
  align-self: center;
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 4px 10px;
}
.service { align-self: center; color: var(--faint); font-size: 12px; margin: 6px 0; text-align: center; }
.bubble {
  max-width: min(68%, 640px);
  padding: 9px 12px 7px;
  border-radius: 18px;
  background: var(--panel-2);
  position: relative;
}
.bubble.out { align-self: flex-end; background: #24352e; border-bottom-right-radius: 6px; }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble .sender { color: var(--brass); font-size: 12px; margin-bottom: 3px; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.bubble .foot { display: flex; justify-content: flex-end; gap: 6px; align-items: center; margin-top: 4px; }
.bubble .media-chip, .quote {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}
.bubble img.photo { display: block; width: min(320px, 100%); border-radius: 12px; margin-bottom: 6px; }
.sticker { font-size: 42px; line-height: 1.1; }
.quote {
  border-left: 2px solid var(--brass);
  padding-left: 8px;
  cursor: pointer;
}
.reply-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 11px;
  opacity: 0;
  padding: 2px 4px;
}
.bubble:hover .reply-btn, .bubble:focus-within .reply-btn { opacity: 1; }
.back { display: none; }

.composer { padding: 0 8% 16px; }
.composer-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 8px;
}
.send { width: 42px; height: 42px; border-radius: 12px; padding: 0; }
.hint { margin: 6px 8px 0; }
.reply-bar, .file-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(224, 176, 122, 0.08);
  color: var(--muted);
  font-size: 13px;
}
.reply-bar button, .file-bar button { border: 0; background: transparent; color: var(--text); }

.new-pill {
  position: absolute;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  border: 0;
  background: var(--text);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.empty {
  margin: auto;
  max-width: 360px;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty h3 { margin: 0 0 8px; color: var(--text); font-family: var(--display); font-weight: 560; font-size: 28px; }
.empty p { margin: 0; line-height: 1.5; }
.skel {
  height: 58px;
  margin: 8px 16px;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(255,255,255,0.03), rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 7, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(520px, 100%);
  background: #171c19;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 0;
  box-shadow: var(--shadow);
  max-height: min(88vh, 760px);
  overflow: hidden;
}
#modal-body > .stack {
  max-height: min(88vh, 760px);
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}
#modal-body > .stack > h3 { margin: 0; padding: 22px 22px 8px; font-family: var(--display); font-size: 30px; font-weight: 560; }
#modal-body > .stack > .stack,
#modal-body > .stack > .lede { overflow: auto; padding: 0 22px 12px; min-height: 0; }
.modal-card .lede { margin-top: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 14px;
  align-items: center;
  margin: 0;
  padding: 12px 22px 18px;
  border-top: 1px solid var(--line);
}
.drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 96px;
  border: 1px dashed rgba(224, 176, 122, 0.45);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
  padding: 16px;
  background: rgba(224, 176, 122, 0.04);
  cursor: pointer;
}
.drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop.over { background: rgba(224, 176, 122, 0.12); color: var(--text); }
.busy { color: var(--brass); min-height: 1.2em; margin: 0; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 30; }
.toast {
  width: min(360px, 80vw);
  background: #241c19;
  border: 1px solid rgba(224, 139, 120, 0.35);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.rename {
  border: 0;
  background: transparent;
  padding: 0;
  font-weight: 560;
  font-size: 18px;
  text-align: left;
}
.actions-inline { display: flex; gap: 8px; flex-wrap: wrap; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 99px; }

@media (prefers-reduced-motion: reduce) {
  .dot.connecting, .dot.healing, .skel { animation: none; }
}

@media (max-width: 980px) {
  .app { height: 100dvh; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .thread { display: none; }
  .app.show-thread { grid-template-rows: minmax(0, 1fr); }
  .app.show-thread .rail,
  .app.show-thread .inbox { display: none; }
  .app.show-thread .thread { display: flex; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; padding: 8px 10px 8px; gap: 8px; }
  .rail .brand-lockup { display: none; }
  .rail-switch { flex: none; flex-direction: row; align-items: stretch; gap: 6px; }
  .account-step {
    display: grid;
    place-items: center;
    width: 36px;
    flex: 0 0 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-2);
    color: var(--brass);
  }
  .account-step svg { width: 20px; height: 20px; }
  .account-step:disabled { opacity: 0.35; cursor: default; }
  .rail-list {
    flex: 1;
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 68px;
    gap: 8px;
    padding: 0 0 2px;
  }
  .account { width: auto; min-width: 176px; flex: 0 0 auto; touch-action: manipulation; }
  .rail-foot { display: flex; align-items: center; gap: 12px; padding-top: 0; }
  .rail-foot .primary.block { width: auto; padding: 8px 12px; }
  .rail-links { flex: 1; padding: 0; }
  .back { display: inline-grid; }
  .messages, .composer { padding-left: 12px; padding-right: 12px; }
  .bubble { max-width: 88%; }
}
