/* Phone-first. Dark by default because this gets opened at 6am and 11pm. */
:root {
  --bg: #0e1015;
  --surface: #171a21;
  --surface-2: #1f232c;
  --line: #262b36;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #4c9aff;
  --urgent: #ff6b5e;
  --ok: #3ecf8e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --line: #dfe3ea;
    --text: #171a21;
    --muted: #667085;
  }
}

* { box-sizing: border-box; }

/* A class that sets `display` outruns the UA sheet's `[hidden] { display: none }`.
   Without this, the hidden thread sheet (position: fixed; inset: 0; display: flex)
   stays laid out and eats every tap on the screen behind it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------- gate ---------- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate__box {
  width: min(340px, 100%);
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 22px;
}
.gate__title { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.gate__input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  width: 100%;
}
.gate__error { margin: 0; color: var(--urgent); font-size: 14px; min-height: 1.2em; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(var(--safe-top) + 10px) 14px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar__row { display: flex; align-items: center; justify-content: space-between; }
.topbar__title { margin: 0; font-size: 26px; letter-spacing: -0.03em; }

.iconbtn {
  background: none;
  border: 0;
  font-size: 22px;
  line-height: 1;
  padding: 8px 10px;
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
}
.iconbtn:active { background: var(--surface-2); }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 0;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tab__count { opacity: 0.75; margin-left: 5px; }

/* ---------- list ---------- */
.list {
  padding: 10px 12px calc(var(--safe-bottom) + 90px);
  display: grid;
  gap: 8px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  cursor: pointer;
  overflow: hidden;
}
.card--low { opacity: 0.62; }

.card__top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.card__name {
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__chan { font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.card__age { margin-left: auto; font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.card__age--urgent { color: var(--urgent); font-weight: 600; }

.card__preview {
  color: var(--muted);
  font-size: 14.5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__buried {
  margin-top: 7px;
  display: inline-block;
  font-size: 12px;
  color: var(--urgent);
  background: color-mix(in srgb, var(--urgent) 14%, transparent);
  border-radius: 999px;
  padding: 2px 9px;
}
.card__account {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty__big { font-size: 40px; display: block; margin-bottom: 10px; }

.bulk {
  margin-top: 12px;
  width: 100%;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 13px;
  color: var(--muted);
  cursor: pointer;
}

.hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 12px);
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.hint--action { color: var(--accent); font-weight: 600; cursor: pointer; }

/* ---------- thread sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.sheet__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  border-bottom: 1px solid var(--line);
}
.sheet__who { display: grid; min-width: 0; }
.sheet__who strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet__sub { font-size: 12.5px; color: var(--muted); }
.sheet__bar .iconbtn:last-child { margin-left: auto; }

.sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 16px;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg--in { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 5px; }
.msg--out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
/* Automated sends are context, not conversation — mute them hard. */
.msg--auto {
  align-self: flex-end;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  max-width: 90%;
}
.msg__meta { display: block; font-size: 11px; opacity: 0.7; margin-top: 4px; }
.msg__subject { font-weight: 600; display: block; margin-bottom: 2px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.composer__text {
  flex: 1;
  resize: none;
  max-height: 130px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 14px;
}
.composer__error {
  margin: 0;
  padding: 0 14px calc(var(--safe-bottom) + 8px);
  color: var(--urgent);
  font-size: 13.5px;
  background: var(--surface);
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 600;
  cursor: pointer;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.5; }

.spinner { text-align: center; color: var(--muted); padding: 40px; }
