:root {
  --bg: #f4fbf8;
  --surface: #ffffff;
  --surface-2: #eff5f2;
  --surface-3: #e3eae7;
  --line: #dae5e1;
  --text: #171d1b;
  --muted: #4d5855;
  --faint: #6f7977;
  --primary: #006a60;
  --on-primary: #ffffff;
  --primary-soft: #cce8e2;
  --bubble-in: #ffffff;
  --bubble-in-text: #171d1b;
  --bubble-out: #9ef2e4;
  --bubble-out-text: #00201c;
  --warn-bg: #ffe08a;
  --warn-text: #3a2a00;
  --error: #ba1a1a;
  --error-bg: #ffdad6;
  --error-text: #410002;
  --ok: #2e7d32;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 12px 32px rgba(0, 0, 0, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513;
    --surface: #171d1b;
    --surface-2: #1b2120;
    --surface-3: #252b2a;
    --line: #2b3230;
    --text: #dde4e1;
    --muted: #bec9c6;
    --faint: #899390;
    --primary: #82d5c8;
    --on-primary: #003731;
    --primary-soft: #26403c;
    --bubble-in: #252b2a;
    --bubble-in-text: #dde4e1;
    --bubble-out: #005048;
    --bubble-out-text: #d4fbf4;
    --warn-bg: #5a4300;
    --warn-text: #ffe08a;
    --error: #ffb4ab;
    --error-bg: #93000a;
    --error-text: #ffdad6;
    --ok: #81c784;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, .conv:focus-visible, .bubble:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.boot {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  color: var(--faint);
  margin: 0;
}

.logo {
  width: 36px;
  height: 36px;
  flex: none;
  display: block;
}

/* ---------- Sign in ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 28px 26px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 1.05rem;
  min-width: 0;
}

.brand small {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login h1 {
  font-size: 1.55rem;
  margin: 22px 0 4px;
  letter-spacing: -0.01em;
}

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

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 16px 0 6px;
}

.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.check input { margin-top: 3px; accent-color: var(--primary); }

.btn-primary {
  width: 100%;
  margin-top: 20px;
  padding: 12px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: filter 0.15s;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

.alert {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  background: var(--error-bg);
  color: var(--error-text);
}

.alert.warn { background: var(--warn-bg); color: var(--warn-text); }

.fineprint {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--faint);
  margin: 16px 0 0;
}

.fineprint svg { flex: none; width: 16px; height: 16px; margin-top: 1px; fill: currentColor; }

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

.shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 8px 16px;
}

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover { background: var(--surface-3); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.gateway {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 12px 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 0.86rem;
}

.gateway .dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}

.gateway.idle .dot { background: var(--faint); box-shadow: none; }
.gateway.warn { background: var(--warn-bg); color: var(--warn-text); }
.gateway.warn .dot { background: currentColor; box-shadow: none; }
.gateway.error { background: var(--error-bg); color: var(--error-text); }
.gateway.error .dot { background: currentColor; box-shadow: none; }
.gateway-text { min-width: 0; }
.gateway-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gateway-sub { opacity: 0.85; }

.search { padding: 2px 12px 8px; }
.search .input { padding: 10px 14px; border-radius: 999px; background: var(--surface-2); border-color: transparent; }
.search .input:focus { background: var(--surface); border-color: var(--primary); }

.conversations {
  list-style: none;
  margin: 0;
  padding: 0 6px 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.conv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 14px;
  cursor: pointer;
}

.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--primary-soft); }

.avatar {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
  background: #00897b;
}

.avatar.c1 { background: #5e35b1; }
.avatar.c2 { background: #e53935; }
.avatar.c3 { background: #1e88e5; }
.avatar.c4 { background: #f4511e; }
.avatar.c5 { background: #6d4c41; }
.avatar.c6 { background: #3949ab; }
.avatar.c7 { background: #7cb342; }

.conv-main { flex: 1; min-width: 0; }

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.conv-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time { flex: none; font-size: 0.76rem; color: var(--faint); }

.conv-preview {
  color: var(--muted);
  font-size: 0.9rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.conv-preview .you { color: var(--faint); }

mark {
  background: color-mix(in srgb, var(--primary) 28%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.list-note {
  padding: 24px 16px;
  text-align: center;
  color: var(--faint);
  font-size: 0.9rem;
}

.sidebar-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 6px 14px 12px;
  border-top: 1px solid var(--line);
}

.link-btn {
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 0.86rem;
  cursor: pointer;
  padding: 6px 2px;
}

.link-btn:hover { text-decoration: underline; }
.link-btn:disabled { color: var(--faint); cursor: default; text-decoration: none; }

/* ---------- Thread ---------- */

.thread {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.thread-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  min-height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.thread-head .back { display: none; margin-left: -8px; }
.thread-title { min-width: 0; }
.thread-title .name { font-weight: 650; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-title .sub { font-size: 0.82rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day {
  align-self: center;
  margin: 14px 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 0.76rem;
}

.bubble {
  align-self: flex-start;
  max-width: min(640px, 80%);
  padding: 8px 13px 6px;
  border-radius: 6px 18px 18px 18px;
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

.bubble.out {
  align-self: flex-end;
  border-radius: 18px 6px 18px 18px;
  background: var(--bubble-out);
  color: var(--bubble-out-text);
}

.bubble .body { white-space: pre-wrap; overflow-wrap: anywhere; }

.bubble .meta {
  margin-top: 2px;
  font-size: 0.72rem;
  text-align: right;
  opacity: 0.7;
}

.bubble .details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  font-size: 0.78rem;
}

.bubble .details dt { opacity: 0.7; }
.bubble .details dd { margin: 0; }

.bubble.flash { animation: flash 1.6s ease-out; }

@keyframes flash {
  0%, 30% { box-shadow: 0 0 0 3px var(--primary); }
  100% { box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06); }
}

.thread-foot {
  padding: 10px 20px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--faint);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.empty {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  color: var(--faint);
  padding: 32px;
}

.empty svg { width: 56px; height: 56px; fill: currentColor; opacity: 0.6; }
.empty strong { color: var(--muted); font-size: 1.05rem; }

.banner {
  padding: 8px 16px;
  font-size: 0.85rem;
  background: var(--warn-bg);
  color: var(--warn-text);
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .thread { display: none; }
  .shell.show-thread .sidebar { display: none; }
  .shell.show-thread .thread { display: flex; }
  .thread-head { padding: 8px 12px; }
  .thread-head .back { display: grid; margin-left: 0; }
  .messages { padding: 10px 12px 20px; }
  .bubble { max-width: 88%; }
}
