:root {
  --brand: #323234;
  --accent: #e22e34;
  --bg: #f2f2f4;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #e1e1e6;
  --client: #ffffff;
  --mine: #323234;
  --mine-text: #ffffff;
  --other: #e9e9ee;
  --selected: #fdecec;
  --new: #e22e34;
  --waiting: #b26b00;
  --answered: #2f7d4f;
  --sales: #2f5fa8;
  --closed: #8a8a90;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #222225;
    --text: #f2f2f4;
    --muted: #a0a0a8;
    --line: #333338;
    --client: #262629;
    --mine: #4a4a50;
    --other: #2c2c30;
    --selected: #3a2426;
    --waiting: #e0a040;
    --answered: #5cc28a;
    --sales: #7aa7ee;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body { display: flex; flex-direction: column; height: 100dvh; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Header ------------------------------------------------------------ */

.bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand);
  color: #fff;
  flex: none;
}
.logo { width: 34px; height: 34px; flex: none; }
.titles { flex: 1; min-width: 0; }
.title { font-weight: 650; font-size: 17px; }
.tag {
  font-size: 12px;
  font-weight: 600;
  background: var(--accent);
  border-radius: 6px;
  padding: 1px 6px;
  margin-inline-start: 6px;
  vertical-align: 2px;
}
.subtitle { font-size: 13px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  flex: none;
}
.icon-button svg { width: 22px; height: 22px; fill: currentColor; }
.bar .icon-button:hover { background: rgba(255, 255, 255, 0.12); }
.menu {
  position: absolute;
  top: calc(100% - 4px);
  inset-inline-end: 12px;
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  padding: 6px;
  min-width: 230px;
  z-index: 10;
}
.menu button {
  display: block;
  width: 100%;
  text-align: start;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  border-radius: 8px;
}
.menu button:hover { background: var(--bg); }

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

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; }
.center { display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; }
.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.card h1 { font-size: 21px; margin: 0 0 8px; line-height: 1.25; }
.card p { margin: 0 0 18px; color: var(--muted); }
.card label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.card input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}
#code { font-size: 22px; letter-spacing: 6px; text-align: center; }
.card .sent { color: var(--text); }
.card .error { color: var(--accent); margin: 14px 0 0; }
.primary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}
.primary:disabled { opacity: 0.6; cursor: default; }
.link {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  margin-top: 12px;
  padding: 4px 0;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Desk: inbox + thread ------------------------------------------------ */

.desk { display: flex; }
.inbox {
  width: 380px;
  flex: none;
  border-inline-end: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filters { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex: none; }
.filters button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 14px;
}
.filters button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  flex: none;
}
.banner span { flex: 1; }
#banner-action {
  border: 0;
  border-radius: 10px;
  padding: 7px 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}
.banner-close { border: 0; background: transparent; color: var(--muted); font-size: 20px; width: 30px; height: 30px; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
}
.list li:hover { background: var(--bg); }
.list li.selected { background: var(--selected); }
.list .who { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .when { font-size: 12px; color: var(--muted); text-align: end; }
.list .what { grid-column: 1 / -1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; }
.list li.unread .who::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-inline-start: 6px;
  vertical-align: 1px;
}
.empty { color: var(--muted); text-align: center; padding: 30px 16px; }
.badge {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-radius: 6px;
  padding: 2px 7px;
  color: #fff;
  background: var(--closed);
  white-space: nowrap;
}
.badge.new { background: var(--new); }
.badge.waiting { background: var(--waiting); }
.badge.answered { background: var(--answered); }
.badge.sales { background: var(--sales); }
.lang { font-size: 12px; color: var(--muted); }

.thread { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.placeholder { margin: auto; color: var(--muted); padding: 24px; text-align: center; }
.conversation { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thread-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.thread-head .back { display: none; color: var(--text); }
.thread-titles { flex: 1; min-width: 0; }
.thread-title { font-weight: 650; font-size: 16px; }
.thread-sub { font-size: 13px; color: var(--muted); }
.summary {
  margin: 12px 14px 0;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: 12px;
  font-size: 14px;
  border-inline-start: 3px solid var(--accent);
}
.actions { display: flex; gap: 8px; padding: 10px 14px 0; flex-wrap: wrap; }
.actions button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 14px;
}
.actions button:hover { border-color: var(--accent); }
.actions button:disabled { opacity: 0.5; cursor: default; }

/* Summary, actions and conversation scroll together: on a phone the
   conversation gets the whole screen once scrolled. */
.scroll { flex: 1; min-height: 0; overflow-y: auto; }
.timeline {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ev {
  max-width: min(80%, 620px);
  padding: 8px 12px 6px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ev .by { display: block; font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 2px; }
.ev .time { display: block; font-size: 11px; opacity: 0.6; text-align: end; margin-top: 2px; }
.ev.client { align-self: flex-start; background: var(--client); border-end-start-radius: 4px; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05); }
.ev.advisor, .ev.photo { align-self: flex-end; background: var(--other); border-end-end-radius: 4px; }
.ev.mine { background: var(--mine); color: var(--mine-text); }
.ev.mine .by { color: rgba(255, 255, 255, 0.75); }
.ev.note {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 90%;
}
.ev details { margin-top: 6px; font-size: 13px; }
.ev details summary { cursor: pointer; opacity: 0.8; }
.ev details div { margin-top: 4px; opacity: 0.9; }
.ev img { display: block; max-width: 100%; max-height: 50vh; border-radius: 10px; }
.ev a { color: inherit; }
.ev.pending { opacity: 0.6; }

.notice {
  margin: 0 14px 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--selected);
  color: var(--text);
  font-size: 14px;
  flex: none;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: none;
}
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  max-height: 180px;
  min-height: 44px;
}
.attach {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  flex: none;
}
.attach:hover { background: var(--bg); }
.attach input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.attach svg { width: 24px; height: 24px; fill: currentColor; }
.send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}
.send svg { width: 22px; height: 22px; fill: currentColor; }
.send:disabled { opacity: 0.45; cursor: default; }

/* Phones: one pane at a time. */
@media (max-width: 760px) {
  .inbox { width: 100%; border: 0; }
  .thread { display: none; }
  .desk.reading .inbox { display: none; }
  .desk.reading .thread { display: flex; }
  .thread-head .back { display: grid; }
  .placeholder { display: none; }
}
