/* Messages — mobile-first, two colour schemes from prefers-color-scheme.
   No framework, no build step: every rule here is reachable from the markup in
   app.js, and the stylesheet is small enough that a class list is faster than a
   dependency would be. */

:root {
  --bg: #ffffff;
  --panel: #f6f7f9;
  --panel-2: #eef0f3;
  --line: #e3e6ea;
  --text: #16181c;
  --muted: #6b7280;
  --accent: #06c755;
  --accent-ink: #ffffff;
  --bubble-me: #d9fdd3;
  --bubble-you: #ffffff;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(16,18,22,.06), 0 8px 24px rgba(16,18,22,.06);
  --radius: 14px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --panel: #171a20;
    --panel-2: #1e222a;
    --line: #262b33;
    --text: #e8eaed;
    --muted: #9aa3af;
    --bubble-me: #0f5c2e;
    --bubble-you: #1e222a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#root { height: 100%; }

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

button {
  cursor: pointer;
  border: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.noscript { padding: 32px; max-width: 34rem; margin: 0 auto; }

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

.app { display: flex; height: 100dvh; flex-direction: column; }

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-height: 52px;
  flex: 0 0 auto;
}

.bar h1 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; min-width: 0; }
.bar h1 span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  display: grid; place-items: center;
  border-radius: 10px; font-size: 18px;
}
.icon-btn:hover { background: var(--panel-2); }

/* --------------------------------------------------------------- signin */

.center {
  flex: 1; display: grid; place-items: center; padding: 24px;
  overflow-y: auto;
}

.card {
  width: 100%; max-width: 24rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 4px; font-size: 22px; }
.card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

label { display: block; margin: 14px 0 0; }
label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input, textarea {
  width: 100%;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: var(--tap);
}
input:focus, textarea:focus { border-color: var(--accent); outline: none; }

.btn {
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  min-height: var(--tap);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 10px;
  font-weight: 600;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--panel-2); color: var(--text); }

.tabs { display: flex; gap: 6px; margin-bottom: 4px; }
.tabs button {
  flex: 1; padding: 9px; border-radius: 10px; font-size: 14px;
  color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--text); }

.error { color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 1.2em; }
.note { color: var(--muted); font-size: 13px; margin-top: 16px; line-height: 1.45; }

/* -------------------------------------------------------- conversations */

.split { flex: 1; display: flex; min-height: 0; }

.list { width: 100%; max-width: 26rem; overflow-y: auto; border-right: 1px solid var(--line); }
.list.hidden { display: none; }

.thread { flex: 1; display: none; flex-direction: column; min-width: 0; }
.thread.open { display: flex; }

.row {
  display: flex; gap: 12px; align-items: center;
  width: 100%; padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--line);
  min-height: 64px;
}
.row:hover, .row[aria-current="true"] { background: var(--panel-2); }

.avatar {
  flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 16px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.row .meta { flex: 1; min-width: 0; }
.row .name { font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.row .name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { margin-left: auto; font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.row .preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

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

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

.scroll { flex: 1; overflow-y: auto; padding: 14px; scroll-behavior: smooth; }

.day { text-align: center; margin: 14px 0; }
.day span { background: var(--panel-2); color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 10px; }

.msg { display: flex; margin-bottom: 8px; }
.msg.me { justify-content: flex-end; }
.msg .bubble {
  max-width: min(78%, 34rem);
  padding: 8px 12px;
  background: var(--bubble-you);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.me .bubble { background: var(--bubble-me); }
.msg .who { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.msg .body { font-size: 15px; }
.msg .body a { color: inherit; }
.msg .time { font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .quote {
  border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px;
  background: rgba(128,128,128,.12); border-radius: 6px; font-size: 13px; color: var(--muted);
}
.msg .reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.msg .reactions button {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 1px 7px; font-size: 12px;
}
.msg .reactions button.mine { border-color: var(--accent); }
.msg .attach { display: block; margin-top: 6px; }
.msg .attach img { max-width: 100%; border-radius: 10px; display: block; }
.msg .attach .file {
  display: inline-flex; gap: 8px; align-items: center;
  background: var(--panel-2); padding: 8px 10px; border-radius: 10px; font-size: 14px;
}

.composer {
  flex: 0 0 auto;
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer textarea { resize: none; max-height: 8rem; border-radius: 20px; padding: 11px 14px; }
.composer .send {
  flex: 0 0 auto; width: var(--tap); height: var(--tap); border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 18px; display: grid; place-items: center;
}
.composer .send:disabled { opacity: .4; }

.typing { padding: 2px 16px 6px; font-size: 12px; color: var(--muted); min-height: 1.2em; background: var(--panel); }

@media (min-width: 760px) {
  .list.hidden { display: block; }
  .thread { display: flex; }
  .thread:not(.open) { display: none; }
}
