/* WhatsApp (simulador): a generic phone-style messaging surface in the Nexadev palette.
   Contrast (WCAG AA) checked for both appearances: text on bubbles >= 4.5:1, ticks >= 3:1. */
:root {
  --desk: #e9edf4;
  --chat: #eef1f6;
  --head: #16203a;
  --head-text: #ffffff;
  --head-sub: #c9d3e8;        /* on #16203a: 10.9:1 */
  --bubble-in: #ffffff;
  --bubble-out: #dce6fb;
  --text: #16203a;            /* on white 15.6:1, on #dce6fb 12.6:1 */
  --muted: #566176;           /* on white 6.3:1, on #dce6fb 5.1:1 */
  --accent: #2456c9;          /* on white 6.1:1 */
  --accent-text: #ffffff;
  --tick: #6b7588;            /* on #dce6fb 3.9:1 */
  --tick-read: #1d4fc0;       /* on #dce6fb 5.4:1 */
  --line: #dbe1ee;
  --card: #ffffff;
  --chip: #ffffffd9;
  --danger: #b42318;
  --shadow: 0 1px 1px rgb(22 32 58 / 8%);
  --phone-shadow: 0 30px 80px rgb(22 32 58 / 22%), 0 0 0 1px rgb(22 32 58 / 8%);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #0b0f19;
    --chat: #0f1524;
    --head: #141c31;
    --head-text: #eef2fa;
    --head-sub: #a6b0c3;
    --bubble-in: #1b2438;
    --bubble-out: #213a73;
    --text: #eef2fa;           /* on #1b2438 14.6:1, on #213a73 11.0:1 */
    --muted: #a6b0c3;          /* on #1b2438 7.0:1, on #213a73 5.2:1 */
    --accent: #8fb0ff;         /* on #0f1524 8.4:1 */
    --accent-text: #0b1530;
    --tick: #a6b0c3;
    --tick-read: #9cc0ff;      /* on #213a73 5.6:1 */
    --line: #263049;
    --card: #141c31;
    --chip: #1b2438e6;
    --danger: #ff8a80;
    --shadow: none;
    --phone-shadow: 0 30px 80px rgb(0 0 0 / 50%), 0 0 0 1px #263049;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--desk); color: var(--text); font-size: 17px; line-height: 1.35; -webkit-font-smoothing: antialiased; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 10px; }

.desk { min-height: 100%; display: flex; gap: 40px; align-items: center; justify-content: center; padding: 32px 24px; }

/* ---------------------------------------------------------------- phone */
.phone {
  position: relative; width: 390px; height: min(820px, calc(100vh - 64px)); min-height: 560px;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--chat); border-radius: 44px; box-shadow: var(--phone-shadow);
  border: 10px solid #0d1322;
}
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 12px 12px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--head); color: var(--head-text);
}
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 15px; flex: none; }
.who { min-width: 0; flex: 1; }
.who h1 { margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .sub { margin: 1px 0 0; font-size: 13px; color: var(--head-sub); }

.notice { margin: 8px 12px 0; padding: 10px 12px; border-radius: 12px; background: var(--card); color: var(--danger); font-size: 15px; box-shadow: var(--shadow); }

.log { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.day-chip { align-self: center; margin: 4px 0 8px; }
.day-chip span { display: inline-block; padding: 4px 10px; border-radius: 8px; background: var(--chip); color: var(--muted); font-size: 13px; box-shadow: var(--shadow); }
.e2e { align-self: center; max-width: 88%; margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; background: var(--chip); color: var(--muted); font-size: 13px; text-align: center; }

.row { display: flex; flex-direction: column; max-width: 82%; }
.row.in { align-self: flex-start; }
.row.out { align-self: flex-end; align-items: flex-end; }
.row + .row.same { margin-top: -1px; }
.bubble {
  position: relative; padding: 7px 10px 6px; border-radius: var(--radius); box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px;
}
.in .bubble { background: var(--bubble-in); border-top-left-radius: 6px; }
.out .bubble { background: var(--bubble-out); border-top-right-radius: 6px; }
.row.same .bubble { border-radius: var(--radius); }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.bubble .t-header { display: block; font-weight: 600; margin-bottom: 4px; }
.bubble .t-footer { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; }
.bubble .tag { display: inline-block; margin-bottom: 4px; font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.meta { display: inline-flex; gap: 4px; align-items: center; float: right; margin: 6px 0 -2px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.ticks { width: 17px; height: 11px; color: var(--tick); }
.ticks.read { color: var(--tick-read); }
.ticks.failed { color: var(--danger); }
.status-word { font-size: 12px; color: var(--muted); }

.bubble audio { display: block; width: 230px; max-width: 100%; height: 40px; margin: 2px 0; }
.bubble img { display: block; max-width: 100%; border-radius: 12px; margin-bottom: 4px; }

.actions { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; width: 100%; min-width: 220px; }
.actions button {
  min-height: 44px; padding: 8px 12px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--bubble-in); color: var(--accent); font-weight: 600; box-shadow: var(--shadow);
}
.actions button:hover:not(:disabled) { filter: brightness(.97); }
.actions button:disabled { color: var(--muted); cursor: default; }
.actions button[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: -2px; }

.typing { align-self: flex-start; margin: 0 12px 6px; padding: 10px 14px; border-radius: var(--radius); border-top-left-radius: 6px; background: var(--bubble-in); box-shadow: var(--shadow); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bob 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-3px); opacity: 1; } }

.suggestions { display: flex; gap: 8px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; }
.suggestions:empty { display: none; }
.suggestions button {
  flex: none; min-height: 36px; padding: 6px 12px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 14px; cursor: pointer;
}

.composer { position: relative; display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.field { flex: 1; display: flex; align-items: flex-end; gap: 2px; min-height: 48px; padding: 2px 6px 2px 2px; border-radius: 24px; background: var(--card); box-shadow: var(--shadow); }
.field textarea { flex: 1; resize: none; border: 0; background: transparent; padding: 12px 4px; max-height: 120px; outline: none; font-size: 16px; line-height: 1.35; }
.field:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
.field textarea::placeholder { color: var(--muted); }
.icon-btn { width: 44px; height: 44px; flex: none; border: 0; border-radius: 22px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.chat-head .icon-btn { color: var(--head-text); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; stroke: currentColor; }
.round-btn { width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; cursor: pointer; }
.round-btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; }
.round-btn:disabled { opacity: .55; cursor: default; }
#mic[aria-pressed="true"] { background: var(--danger); color: #fff; }

.attach-menu {
  position: absolute; left: 10px; bottom: 64px; z-index: 2; display: flex; flex-direction: column; min-width: 220px; padding: 6px;
  border-radius: 16px; background: var(--card); box-shadow: 0 12px 40px rgb(22 32 58 / 22%), 0 0 0 1px var(--line);
}
.attach-menu button { min-height: 44px; padding: 8px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; cursor: pointer; }
.attach-menu button:hover { background: var(--chat); }

.recording { display: flex; align-items: center; gap: 10px; padding: 8px 16px 12px; font-size: 15px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
.rec-hint { flex: 1; color: var(--muted); font-size: 13px; }

.text-btn { min-height: 44px; padding: 8px 12px; border: 0; border-radius: 12px; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; }

/* ---------------------------------------------------------------- side panel */
.panel { width: 340px; display: flex; flex-direction: column; gap: 16px; }
.card { padding: 18px 18px 14px; border-radius: 20px; background: var(--card); box-shadow: 0 1px 2px rgb(22 32 58 / 6%), 0 0 0 1px var(--line); }
.card h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.hint { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.phone-form { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.phone-form input, .name-row input {
  flex: 1; min-width: 140px; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--chat); font-variant-numeric: tabular-nums;
}
.name-row { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.name-row input { color: var(--text); font-size: 16px; }
.events { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; font-size: 14px; }
.events li { display: grid; grid-template-columns: 56px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; }
.events .empty { display: block; color: var(--muted); }
.legend { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.tick-demo { color: var(--tick); font-weight: 700; letter-spacing: -2px; }
.tick-demo.read { color: var(--tick-read); }
.fineprint { margin: 0 4px; font-size: 13px; color: var(--muted); }
.only-compact { display: none; }

/* ---------------------------------------------------------------- compact: the phone is the screen */
@media (max-width: 820px) {
  .desk { display: block; padding: 0; }
  .phone { width: 100%; height: 100dvh; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .only-compact { display: grid; }
  .panel { position: fixed; inset: auto 0 0 0; z-index: 5; width: auto; max-height: 85dvh; overflow-y: auto; padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    background: var(--desk); border-radius: 20px 20px 0 0; box-shadow: 0 -12px 40px rgb(0 0 0 / 25%); transform: translateY(105%); transition: transform .25s ease; }
  .panel.open { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .dots i { opacity: .8; }
}
@media (prefers-contrast: more) {
  :root { --muted: #3b4556; --tick: #3b4556; --line: #8a94a8; }
  @media (prefers-color-scheme: dark) { :root { --muted: #d0d7e4; --tick: #d0d7e4; --line: #5b6680; } }
}

/* White label: account logo in the chat header avatar. */
.avatar { overflow: hidden; }
.avatar .avatar-logo { width: 100%; height: 100%; object-fit: contain; background: #ffffff; padding: 3px; border-radius: 50%; }
