/* Lagoon — shared design tokens for the visitor chat and the staff inbox.
   Ink slate, mist paper, lagoon teal for "yours" and read ticks, signal amber for typing/unread.
   System fonts only (nothing to download on a small server). */

:root {
  color-scheme: light dark;

  --ink: #13232e;
  --ink-2: #33454f;
  --muted: #5b6b73;
  --paper: #eef2f0;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --line: #d5dedb;
  --lagoon: #0f7c7a;
  --lagoon-strong: #0a5f5e;
  --lagoon-wash: #d6eee9;
  --amber: #e8a33d;
  --amber-ink: #6b4300;
  --danger: #b3261e;
  --focus: #0f7c7a;

  --bubble-mine: var(--lagoon-wash);
  --bubble-theirs: var(--surface);

  --radius-bubble: 16px;
  --radius-control: 10px;
  --shadow-float: 0 8px 28px rgb(19 35 46 / 0.16);

  --font: "Segoe UI Variable Text", "Segoe UI", ui-sans-serif, system-ui, -apple-system, "Roboto", "Helvetica Neue", Arial, sans-serif;
  --step--1: 0.8125rem;   /* 13px meta */
  --step-0: 0.9375rem;    /* 15px body */
  --step-1: 1.0625rem;    /* 17px titles */
  --step-2: 1.375rem;     /* 22px headings */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e4ecea;
    --ink-2: #c3d0cd;
    --muted: #93a5a3;
    --paper: #0e1a21;
    --surface: #15242c;
    --surface-2: #1b2c35;
    --line: #2a3d47;
    --lagoon: #3fb6ae;
    --lagoon-strong: #6fd0c8;
    --lagoon-wash: #12403f;
    --amber: #f0b456;
    --amber-ink: #2b1b00;
    --danger: #ff8a80;
    --focus: #6fd0c8;
    --shadow-float: 0 8px 28px rgb(0 0 0 / 0.45);
  }
}
:root[data-theme="dark"] {
  --ink: #e4ecea; --ink-2: #c3d0cd; --muted: #93a5a3; --paper: #0e1a21; --surface: #15242c; --surface-2: #1b2c35;
  --line: #2a3d47; --lagoon: #3fb6ae; --lagoon-strong: #6fd0c8; --lagoon-wash: #12403f; --amber: #f0b456;
  --amber-ink: #2b1b00; --danger: #ff8a80; --focus: #6fd0c8; --shadow-float: 0 8px 28px rgb(0 0 0 / 0.45);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: var(--step-0) / 1.45 var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 40px; padding: 0 1rem; border-radius: var(--radius-control);
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn:hover { border-color: var(--lagoon); }
.btn-primary { background: var(--lagoon); border-color: var(--lagoon); color: #fff; }
.btn-primary:hover { background: var(--lagoon-strong); border-color: var(--lagoon-strong); }
:root[data-theme="dark"] .btn-primary, :root:not([data-theme="light"]) .btn-primary { color: #fff; }
.btn-quiet { background: transparent; border-color: transparent; }
.btn-quiet:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; padding: 0; border-radius: 50%; display: inline-grid; place-items: center;
  border: 0; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- connection banner ---------- */
.conn-banner {
  padding: 0.45rem 1rem; font-size: var(--step--1); text-align: center;
  background: var(--amber); color: var(--amber-ink);
}
.conn-banner[data-kind="offline"] { background: var(--ink-2); color: var(--paper); }

/* ---------- thread ---------- */
.thread {
  list-style: none; margin: 0; padding: 0.75rem 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 2px;
}
.day-sep {
  align-self: center; margin: 0.9rem 0 0.5rem; padding: 0.15rem 0.7rem; border-radius: 999px;
  font-size: var(--step--1); color: var(--muted); background: var(--surface);
}
.msg {
  max-width: min(78%, 34rem); padding: 0.45rem 0.7rem 0.3rem; border-radius: var(--radius-bubble);
  background: var(--bubble-theirs); align-self: flex-start;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  box-shadow: 0 1px 0 rgb(19 35 46 / 0.06);
}
.msg + .msg { margin-top: 2px; }
.msg.group-start { margin-top: 8px; }
.msg.mine { align-self: flex-end; background: var(--bubble-mine); }
.msg .who { display: block; font-size: var(--step--1); font-weight: 600; color: var(--lagoon); margin-bottom: 1px; }
.msg .meta {
  float: right; margin: 0.35rem 0 -0.1rem 0.6rem; display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.6875rem; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1;
}
.msg .ticks { width: 16px; height: 11px; color: var(--muted); }
.msg .ticks[data-state="read"] { color: var(--lagoon); }
.msg.pending { opacity: 0.75; }
.msg.failed { box-shadow: inset 0 0 0 1px var(--danger); }
.msg .retry {
  display: block; margin-top: 0.25rem; padding: 0; border: 0; background: none;
  font-size: var(--step--1); color: var(--danger); font-weight: 600; text-decoration: underline;
}
.older {
  align-self: center; margin: 0.25rem 0 0.5rem;
}
.empty-thread {
  margin: auto; max-width: 22rem; text-align: center; color: var(--muted); padding: 2rem 1rem;
}

/* ---------- composer ---------- */
.composer {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem; padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
  background: var(--surface-2); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 9rem; padding: 0.65rem 0.9rem; line-height: 1.35;
  border: 1px solid var(--line); border-radius: 22px; background: var(--surface);
}
.composer textarea:focus { outline: none; border-color: var(--lagoon); }
.send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--lagoon); color: #fff;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:disabled { background: var(--line); color: var(--muted); cursor: default; }

/* ---------- presence ring (the one memorable element) ---------- */
.ring {
  --size: 40px;
  position: relative; flex: none; width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center; background: var(--lagoon-wash); color: var(--lagoon-strong); font-weight: 700;
}
.ring-avatar { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.ring::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px dashed var(--line);
}
.ring[data-presence="online"]::after { border: 2px solid var(--lagoon); }
.ring[data-presence="typing"]::after {
  border: 2px solid transparent; border-top-color: var(--amber); border-right-color: var(--amber);
  animation: ring-spin 0.9s linear infinite;
}
@keyframes ring-spin { to { transform: rotate(360deg); } }
.ring svg { width: 55%; height: 55%; }

/* ---------- sheets / dialogs ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgb(14 26 33 / 0.45); display: grid; place-items: end center; z-index: 20;
}
.sheet {
  width: min(100%, 28rem); background: var(--surface); border-radius: 18px 18px 0 0; padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-float);
}
@media (min-width: 720px) {
  .sheet-backdrop { place-items: center; }
  .sheet { border-radius: 18px; }
}
.sheet h2 { margin: 0 0 0.5rem; font-size: var(--step-1); }
.sheet p { margin: 0 0 1rem; color: var(--ink-2); }
.sheet .actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.5rem 0; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + span { background: var(--lagoon); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + span { opacity: 0.5; }
.note { font-size: var(--step--1); color: var(--muted); }


/* ---------- attachments (Phase 6/7) ---------- */
.msg.has-att { padding: 0.3rem 0.3rem 0.3rem; white-space: normal; }
.msg.has-att .caption { display: block; white-space: pre-wrap; padding: 0.3rem 0.4rem 0; }
.msg.has-att .meta { float: none; display: flex; justify-content: flex-end; margin: 0.25rem 0.35rem 0.05rem; }
.msg.has-att .who { padding: 0 0.4rem; }
.msg .retry-row { display: flex; flex-wrap: wrap; gap: 0.75rem; padding: 0 0.4rem; }
.msg .retry.discard { color: var(--ink-2); }
span.retry { text-decoration: none !important; }

.att-image {
  position: relative; display: block; width: min(17rem, 64vw); min-height: 6rem; max-height: 22rem; padding: 0; border: 0;
  border-radius: calc(var(--radius-bubble) - 4px); overflow: hidden; background: var(--surface-2); cursor: zoom-in;
}
.att-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.att-image.is-loading img { opacity: 0; }
.att-image.is-loading::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / 0.35) 50%, transparent 70%) var(--surface-2);
  background-size: 220% 100%; animation: att-shimmer 1.2s linear infinite;
}
.att-image.is-error { cursor: pointer; }
.att-image.is-error::after { content: "Couldn't load the photo. Tap to try again."; position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem; font-size: var(--step--1); color: var(--muted); text-align: center; }
@keyframes att-shimmer { to { background-position: -120% 0; } }

.att-file {
  display: flex; align-items: center; gap: 0.6rem; min-width: min(15rem, 60vw); padding: 0.55rem 0.4rem 0.55rem 0.6rem;
  border-radius: calc(var(--radius-bubble) - 4px); background: rgb(19 35 46 / 0.05);
}
.att-file-icon { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; background: var(--lagoon); color: #fff; }
.att-file-icon svg { width: 22px; height: 22px; }
.att-file-text { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.att-file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file-meta { font-size: var(--step--1); color: var(--muted); }

.att-voice { display: flex; align-items: center; gap: 0.5rem; min-width: min(15rem, 62vw); padding: 0.35rem 0.4rem; }
.voice-play {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--lagoon); color: #fff; cursor: pointer;
}
.voice-play svg { width: 20px; height: 20px; }
.voice-seek { flex: 1; min-width: 0; accent-color: var(--lagoon); }
.voice-time, .voice-pending-label { font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums; }
.voice-pending-label { flex: 1; }

.att-progress { position: absolute; left: 0.5rem; right: 0.5rem; bottom: 0.5rem; height: 4px; border-radius: 2px; background: rgb(255 255 255 / 0.5); overflow: hidden; }
.att-file .att-progress, .att-voice .att-progress { position: static; flex-basis: 100%; background: var(--line); }
.att-file.is-pending, .att-voice.is-pending { flex-wrap: wrap; }
.att-progress-bar { display: block; height: 100%; width: 0; background: var(--lagoon); transition: width 0.2s; }
.msg.failed .att-progress { display: none; }

.att-tray {
  flex-basis: 100%; order: -1; display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.4rem 0.4rem 0.5rem;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.att-tray-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; flex: none; }
.att-tray-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 8px; background: var(--lagoon); color: #fff; flex: none; }
.att-tray-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.att-tray-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-tray-meta { font-size: var(--step--1); color: var(--muted); }
.composer-note { flex-basis: 100%; order: -2; margin: 0; padding: 0.4rem 0.6rem; border-radius: 10px; font-size: var(--step--1); background: var(--surface); color: var(--danger); }
.composer-attach, .composer-mic { flex: none; height: 44px; width: 40px; }
.composer [hidden] { display: none !important; }

.rec-bar { flex: 1; display: flex; align-items: center; gap: 0.6rem; min-height: 44px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: rec-pulse 1.2s ease-in-out infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-label { flex: 1; color: var(--muted); font-size: var(--step--1); }
.rec-send { margin-left: auto; }
@keyframes rec-pulse { 50% { opacity: 0.25; } }
.composer.is-recording > textarea, .composer.is-recording > .composer-attach, .composer.is-recording > .composer-mic,
.composer.is-recording > .send-btn:not(.rec-send), .composer.is-recording > .att-tray { display: none !important; }

.is-drop { outline: 3px dashed var(--lagoon); outline-offset: -6px; }

/* "turn on notifications / install the app" card (app-setup.js) */
.setup-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.5rem 0.75rem; padding: 0.8rem 0.9rem;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--lagoon);
  box-shadow: var(--shadow-float);
}
.setup-card[hidden] { display: none; }
.setup-card[data-kind="blocked"] { border-left-color: var(--amber); }
.setup-body { flex: 1 1 14rem; min-width: 0; }
.setup-title { margin: 0; font-size: var(--step-0); }
.setup-text { margin: 0.15rem 0 0; font-size: var(--step--1); color: var(--muted); }
.setup-actions { display: flex; gap: 0.4rem; margin-left: auto; }

/* full-screen photo viewer */
.viewer { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: rgb(8 14 18 / 0.94); color: #fff; }
.viewer-bar { display: flex; align-items: center; gap: 0.25rem; padding: 0.5rem 0.5rem 0.5rem 1rem; }
.viewer-bar .icon-btn { color: #fff; }
.viewer-bar .icon-btn:hover { background: rgb(255 255 255 / 0.12); }
.viewer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0.5rem; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-caption { margin: 0; padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom)); text-align: center; white-space: pre-wrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
