/* Stars. A calm desktop messenger: neutral surfaces, one indigo accent, light and dark. */

:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --surface-hover: #e9ebf1;
  --surface-active: #e2e6fb;
  --ink: #16181d;
  --ink-soft: #5b616e;
  --ink-faint: #8c919c;
  --rule: rgba(20, 24, 33, 0.08);
  --rule-strong: rgba(20, 24, 33, 0.16);
  --accent: #4b5bd6;
  --accent-ink: #ffffff;
  --accent-deep: #3a48b8;
  --accent-wash: #e8ebfc;
  --bubble-them: #eceef3;
  --bubble-them-ink: #16181d;
  --bubble-me: #4b5bd6;
  --bubble-me-ink: #ffffff;
  --ok: #24855a;
  --warn: #9a6512;
  --warn-wash: #fbf1de;
  --danger: #b4372c;
  --danger-wash: #fbe7e4;
  --unread: #4b5bd6;
  --scrim: rgba(22, 26, 40, 0.42);
  --shadow: 0 1px 2px rgba(16, 20, 32, .06), 0 10px 30px -16px rgba(16, 20, 32, .28);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --radius: 18px;
  --sidebar: 340px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #16191f;
    --surface-2: #1d2129;
    --surface-hover: #222731;
    --surface-active: #262c45;
    --ink: #e8eaf0;
    --ink-soft: #a3a9b6;
    --ink-faint: #737a88;
    --rule: rgba(255, 255, 255, 0.07);
    --rule-strong: rgba(255, 255, 255, 0.14);
    --accent: #7d8bf2;
    --accent-ink: #0f1115;
    --accent-deep: #9aa5f6;
    --accent-wash: #232a4a;
    --bubble-them: #252a34;
    --bubble-them-ink: #e8eaf0;
    --bubble-me: #5463df;
    --bubble-me-ink: #ffffff;
    --ok: #4cc28c;
    --warn: #e0a64a;
    --warn-wash: #2e2616;
    --danger: #f07a6e;
    --danger-wash: #3a1f1c;
    --unread: #7d8bf2;
    --scrim: rgba(0, 0, 0, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -16px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115; --surface: #16191f; --surface-2: #1d2129; --surface-hover: #222731; --surface-active: #262c45;
  --ink: #e8eaf0; --ink-soft: #a3a9b6; --ink-faint: #737a88;
  --rule: rgba(255, 255, 255, 0.07); --rule-strong: rgba(255, 255, 255, 0.14);
  --accent: #7d8bf2; --accent-ink: #0f1115; --accent-deep: #9aa5f6; --accent-wash: #232a4a;
  --bubble-them: #252a34; --bubble-them-ink: #e8eaf0; --bubble-me: #5463df; --bubble-me-ink: #ffffff;
  --ok: #4cc28c; --warn: #e0a64a; --warn-wash: #2e2616; --danger: #f07a6e; --danger-wash: #3a1f1c;
  --unread: #7d8bf2; --scrim: rgba(0, 0, 0, 0.55);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -16px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100vh;
  min-width: 900px;
}

/* ---------- sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 12px;
}
.sidebar-head .brand { width: 28px; height: 28px; border-radius: 8px; }
.sidebar-head h1 { font-size: 19px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -.01em; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--ink); }

.search {
  margin: 0 14px 10px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-faint);
}
.search input { border: 0; background: transparent; outline: none; flex: 1; color: var(--ink); }
.search input::placeholder { color: var(--ink-faint); }

.convs { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
.conv {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.conv:hover { background: var(--surface-hover); }
.conv[aria-current="true"] { background: var(--surface-active); }
.conv .avatar { grid-row: 1 / span 2; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv .name span { overflow: hidden; text-overflow: ellipsis; }
.conv .room-mark { color: var(--ink-faint); width: 14px; height: 14px; stroke-width: 2; }
.conv time { font-size: 12px; color: var(--ink-faint); justify-self: end; }
.conv .preview { font-size: 13.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.conv .badge {
  justify-self: end;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  background: var(--unread); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
.conv.unread .name, .conv.unread .preview { color: var(--ink); }
.conv.unread .preview { font-weight: 500; }
.conv.unread time { color: var(--unread); font-weight: 600; }

.sidebar-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--rule);
  font-size: 13px; color: var(--ink-soft);
}
.sidebar-foot .me { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.status-dot.bad { background: var(--danger); }

/* ---------- avatars ---------- */

.avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 650; font-size: 16px;
  color: #fff;
  background: var(--av, #7a80a0);
  overflow: hidden;
  flex: none;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.room { border-radius: 14px; }
.av-1 { --av: #6c7ae0; } .av-2 { --av: #e0866c; } .av-3 { --av: #4ca08a; }
.av-4 { --av: #c06cb8; } .av-5 { --av: #d6a33e; } .av-6 { --av: #5c9bd6; }

/* ---------- thread ---------- */

.thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
  position: relative;
}
.thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  min-height: 66px;
}
.thread-head .avatar { width: 40px; height: 40px; font-size: 15px; }
.thread-head .title { flex: 1; min-width: 0; }
.thread-head h2 { font-size: 16px; font-weight: 650; margin: 0; }
.thread-head .sub { font-size: 12.5px; color: var(--ink-faint); }

.banner {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 22px 0;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  background: var(--warn-wash);
  color: var(--ink);
}
.banner .i { color: var(--warn); }
.banner p { margin: 0; flex: 1; }
.banner.danger { background: var(--danger-wash); }
.banner.danger .i { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  font-weight: 600; font-size: 13.5px;
  cursor: pointer;
  text-decoration: none; color: var(--ink);
}
.btn:hover { background: var(--surface-hover); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-deep); }
.btn.block { width: 100%; height: 42px; font-size: 15px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day {
  align-self: center;
  margin: 14px 0 10px;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 12px; font-weight: 600;
  color: var(--ink-faint);
  background: var(--surface-2);
}
.notice {
  align-self: center;
  display: inline-flex; align-items: center; gap: 8px;
  margin: 8px 0;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--danger);
  background: var(--danger-wash);
}
.notice .i { width: 16px; height: 16px; }

.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 68%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar.sm { visibility: hidden; }
.msg.last .avatar.sm { visibility: visible; }
.msg + .msg:not(.cont) { margin-top: 10px; }
.msg .col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg.me .col { align-items: flex-end; }
.who { font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 0 12px 2px; }

.bubble {
  padding: 8px 13px;
  border-radius: var(--radius);
  background: var(--bubble-them);
  color: var(--bubble-them-ink);
  overflow-wrap: anywhere;
  position: relative;
}
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-ink); }
.bubble .text { white-space: pre-wrap; }
.msg:not(.me).cont .bubble { border-top-left-radius: 6px; }
.msg:not(.me):not(.last) .bubble { border-bottom-left-radius: 6px; }
.msg.me.cont .bubble { border-top-right-radius: 6px; }
.msg.me:not(.last) .bubble { border-bottom-right-radius: 6px; }
.bubble time {
  float: right;
  margin: 6px 0 -3px 10px;
  font-size: 11px;
  opacity: .62;
  line-height: 1;
}

.bubble.media { padding: 4px; overflow: hidden; width: 268px; max-width: 100%; }
.bubble.media img, .bubble.media .thumb {
  display: block;
  width: 100%;
  border-radius: calc(var(--radius) - 4px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-2);
}
.bubble.media .caption { padding: 6px 9px 4px; }
.thumb { position: relative; display: block; cursor: zoom-in; }
.thumb.video { cursor: pointer; }
.thumb .play {
  position: absolute; inset: 0; margin: auto;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(10, 12, 20, .55);
  display: grid; place-items: center;
  color: #fff;
  backdrop-filter: blur(4px);
}
.thumb .play svg { width: 22px; height: 22px; fill: currentColor; stroke: none; margin-left: 3px; }
.thumb .duration {
  position: absolute; right: 8px; bottom: 8px;
  padding: 1px 6px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600;
  background: rgba(10, 12, 20, .6); color: #fff;
}

.audio { display: flex; align-items: center; gap: 10px; min-width: 230px; padding: 2px 0; }
.audio .play-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer; flex: none;
}
.msg.me .audio .play-btn { background: rgba(255, 255, 255, .22); color: #fff; }
.audio .play-btn svg { width: 14px; height: 14px; fill: currentColor; stroke: none; margin-left: 2px; }
.audio .wave { flex: 1; height: 26px; display: flex; align-items: center; gap: 2px; color: var(--accent); }
.msg.me .audio .wave { color: #fff; }
.audio .wave i { flex: 1; border-radius: 2px; background: currentColor; opacity: .35; }
.audio .wave i.on { opacity: .9; }
.audio .len { font-size: 12px; opacity: .7; font-variant-numeric: tabular-nums; }

.pending { opacity: .92; }
.pending .thumb::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: rgba(15, 17, 21, .35);
}
.pending-state {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-faint);
  margin: 2px 6px 0;
}
.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--rule-strong); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.receipt { font-size: 11.5px; color: var(--ink-faint); margin: 2px 6px 0; }

/* ---------- composer ---------- */

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 18px 16px;
  background: var(--bg);
}
.composer .field {
  flex: 1;
  display: flex; align-items: flex-end;
  min-height: 42px;
  padding: 0 6px 0 14px;
  border-radius: 21px;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
}
.composer .field:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  resize: none;
  border: 0; outline: none; background: transparent;
  padding: 10px 0;
  max-height: 160px;
  line-height: 1.4;
  field-sizing: content;
  min-height: 40px;
}
.composer textarea::placeholder { color: var(--ink-faint); }
.composer .attach { height: 40px; width: 40px; border-radius: 50%; }
.send {
  width: 42px; height: 42px;
  border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer; flex: none;
}
.send:hover { background: var(--accent-deep); }
.send:disabled { background: var(--surface-2); color: var(--ink-faint); cursor: default; }
.send svg { width: 18px; height: 18px; }

.dropzone {
  position: absolute; inset: 10px;
  border-radius: 20px;
  border: 2px dashed var(--accent);
  background: color-mix(in srgb, var(--accent-wash) 88%, transparent);
  display: grid; place-content: center; justify-items: center; gap: 10px;
  color: var(--accent-deep);
  font-weight: 650; font-size: 17px;
  z-index: 5;
  backdrop-filter: blur(2px);
}
.dropzone .i { width: 40px; height: 40px; stroke-width: 1.5; }
.dropzone small { font-weight: 500; font-size: 13px; color: var(--ink-soft); }

.empty-thread {
  flex: 1; display: grid; place-content: center; justify-items: center; gap: 10px;
  color: var(--ink-faint); text-align: center;
}
.empty-thread img { width: 64px; height: 64px; border-radius: 16px; opacity: .9; }

/* ---------- auth / link screens ---------- */

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 32px; }
.card {
  width: 400px; max-width: 100%;
  padding: 32px 30px 28px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--rule);
}
.card .logo { width: 56px; height: 56px; border-radius: 15px; display: block; margin: 0 auto 16px; }
.card h1 { font-size: 22px; text-align: center; margin: 0 0 6px; letter-spacing: -.01em; }
.card .lede { text-align: center; color: var(--ink-soft); margin: 0 0 22px; font-size: 14.5px; }
.card form { display: grid; gap: 14px; }
.card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.card input {
  height: 42px; padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  font-size: 15px;
}
.card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.card .hint { font-size: 12.5px; color: var(--ink-faint); margin: 0; }
.card .error {
  padding: 9px 12px; border-radius: 10px;
  background: var(--danger-wash); color: var(--danger);
  font-size: 13.5px; margin: 0;
}
.card .fine { font-size: 12.5px; color: var(--ink-faint); text-align: center; margin: 18px 0 0; }
.google-btn svg { width: 18px; height: 18px; }

.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- live app additions ---------- */

.avatar { position: relative; }
.avatar img.av { position: absolute; inset: 0; }
.messages > .older { display: grid; place-items: center; padding: 8px 0; }
.bubble.media video { width: 100%; max-height: 360px; border-radius: 14px; display: block; background: #000; }
.bubble .voice { display: block; width: 260px; max-width: 100%; height: 36px; margin: 2px 0 4px; }
.pending-state.bad { color: var(--danger); }
.msg.sending .bubble { opacity: .6; }
.pending-state .retry {
  border: 0; background: none; padding: 0; font: inherit;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}
.composer { position: relative; }
.composer-error {
  position: absolute; left: 0; right: 0; bottom: 100%; margin: 0 0 8px;
  font-size: 13px; color: var(--danger); background: var(--danger-wash);
  padding: 6px 10px; border-radius: 10px;
}
.composer.busy .attach { opacity: .4; pointer-events: none; }
.thread > #banner:empty { display: none; }
.thread > #banner { display: flex; flex-direction: column; align-items: center; }
.thread > #banner .banner { align-self: stretch; }
.progress.indeterminate i { width: 35%; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.sync { display: grid; gap: 10px; margin-top: 8px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 22px; font-size: 14px; }
.facts dt { color: var(--ink-faint); }
.facts dd { margin: 0; overflow: hidden; text-overflow: ellipsis; }
.danger-zone { display: grid; gap: 12px; }
.card label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.card label.check input { width: auto; }
