:root {
  color-scheme: light dark;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #14202b;
  --muted: #5b6b78;
  --border: #d9e0e5;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn: #92600a;
  --warn-bg: #fdf3dc;
  --ok: #166534;
  --ok-bg: #e3f6e9;
  --video: #1c2733;
  --video-text: #e8eef2;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e151b;
    --surface: #17212a;
    --text: #e8eef2;
    --muted: #93a4b1;
    --border: #2a3945;
    --accent: #2dd4bf;
    --accent-text: #05211e;
    --danger: #ff8a80;
    --danger-bg: #3a1c1a;
    --warn: #f5c565;
    --warn-bg: #3a2e12;
    --ok: #7ee2a0;
    --ok-bg: #12301d;
    --video: #0a1015;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.app {
  max-width: 960px; margin: 0 auto; padding: 24px 16px 48px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 24px; }
.brand svg { width: 28px; height: 28px; color: var(--accent); }
.brand .badge { margin-left: auto; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
}
.card.narrow { max-width: 460px; margin: 0 auto; }
h1 { font-size: 24px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 0 0 8px; }
p { margin: 0 0 16px; }
.muted { color: var(--muted); }
label { display: block; font-weight: 600; margin-bottom: 6px; }
.field { display: flex; gap: 8px; }
input[type=text], input[type=password], input[type=search], input[type=date] {
  flex: 1; min-width: 0; padding: 12px 14px; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
input[type=text]:focus-visible, input[type=password]:focus-visible,
input[type=search]:focus-visible, input[type=date]:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 16px; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none;
}
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); width: 100%; }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button svg { width: 20px; height: 20px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { margin-bottom: 16px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--accent);
  animation: spin 1s linear infinite; margin: 8px auto 16px;
}
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--danger-bg); color: var(--danger); }

/* call screen */
.stage {
  position: relative; background: var(--video); color: var(--video-text);
  border-radius: var(--radius); aspect-ratio: 16 / 9; overflow: hidden;
  display: grid; place-items: center;
  background-image: linear-gradient(135deg, #24384a, #0d1a24);
}
.stage.preview { aspect-ratio: 4 / 3; margin-bottom: 16px; }
.stage .label { position: relative; opacity: .7; font-size: 14px; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
video.mirror { transform: scaleX(-1); }
.self {
  position: absolute; right: 12px; bottom: 12px; width: 24%; min-width: 96px;
  aspect-ratio: 4 / 3; border-radius: 8px; border: 2px solid rgba(255,255,255,.3); overflow: hidden;
  background-image: linear-gradient(135deg, #3a5266, #1b2c3a);
  display: grid; place-items: center; font-size: 12px; color: var(--video-text);
}
.self span { position: relative; }
.controls { display: flex; justify-content: center; gap: 12px; margin-top: 16px; }
.controls button { width: 52px; height: 52px; padding: 0; border-radius: 50%; }
.controls button[aria-pressed="true"] { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.controls .slash { display: none; }
.controls button[aria-pressed="true"] .slash { display: inline; }

/* banners */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 8px; margin-bottom: 16px; }
.banner.err { background: var(--danger-bg); color: var(--danger); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner strong { display: block; }
.banner svg { width: 22px; height: 22px; flex: none; margin-top: 2px; }
.banner .body { flex: 1; }
.banner .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.banner button { padding: 8px 14px; }

@media (max-width: 480px) {
  .card { padding: 16px; }
  .field { flex-wrap: wrap; }
  .field input { flex-basis: 100%; }
  .field button { flex: 1; }
}
@media (max-width: 600px) and (orientation: portrait) {
  #view-call .stage { aspect-ratio: 3 / 4; }
}

/* call + chat */
.call-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
@media (max-width: 760px) { .call-layout { grid-template-columns: 1fr; } }
.chat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 320px; max-height: 480px; }
.chat h2 { font-size: 15px; margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.chat-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.msg small { display: block; font-size: 11px; opacity: .7; margin-top: 2px; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; min-width: 0; padding: 10px 12px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.chat-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-form button { width: auto; padding: 10px 14px; }
.chat-form button:disabled, .chat-form input:disabled { opacity: .5; cursor: not-allowed; }
.unread { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 8px; font-size: 12px; }

/* device error state on control buttons */
.controls button.error { position: relative; background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.controls button.error .slash { display: inline; }
.controls button.error::after {
  content: "!"; position: absolute; top: -4px; right: -4px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--danger); color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--bg);
}
.stage[data-nocam] video { visibility: hidden; }
.stage[data-nocam] .label::after { content: " (no camera)"; }
.self[data-nocam] video { visibility: hidden; }
.self[data-nocam] span::after { content: " (no camera)"; }

/* receipts */
.msg .meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; opacity: .85; margin-top: 2px; }
.msg:not(.me) .meta { justify-content: flex-start; }
.tick { font-weight: 700; letter-spacing: -2px; }
.tick.sent, .tick.delivered { opacity: .75; }
.tick.read { color: #7dd3fc; opacity: 1; }
.tick.failed { letter-spacing: 0; background: var(--danger); color: #fff; border-radius: 50%; width: 16px; height: 16px; display: inline-grid; place-items: center; font-size: 11px; }
.msg.failed { border-color: var(--danger); }

/* attachments */
.att-media { display: block; max-width: 100%; width: 260px; max-height: 280px; border-radius: 8px; object-fit: contain; background: var(--video); }
audio.att-media { height: 40px; background: none; }
.att-cap { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.att-file { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.att-file .ico { width: 40px; height: 40px; border-radius: 8px; background: var(--surface); color: var(--text); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.att-file .name { font-weight: 600; overflow-wrap: anywhere; }
.att-file .size { font-size: 12px; opacity: .8; }
.att-file .dl { margin-left: auto; padding: 6px 10px; font-size: 13px; }
.msg.me .btn.dl, .msg.me .att-file button.dl { color: var(--text); background: var(--surface); }
.progress { height: 6px; border-radius: 3px; background: rgba(127,127,127,.3); margin-top: 8px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: currentColor; }
.prog-row { display: flex; justify-content: space-between; font-size: 12px; margin-top: 4px; opacity: .9; gap: 12px; }
.prog-row button { width: auto; padding: 0; border: 0; background: none; color: inherit; text-decoration: underline; font-size: 12px; font-weight: 600; cursor: pointer; }
.offer-actions { display: flex; gap: 8px; margin-top: 8px; }
.offer-actions button { width: auto; padding: 6px 12px; font-size: 13px; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg); border: 1px dashed var(--border); border-radius: 999px; padding: 4px 12px; text-align: center; }
.chat-form .attach { width: auto; padding: 10px; }
.chat-form .attach svg { width: 20px; height: 20px; }
.chat.drop { outline: 2px dashed var(--accent); outline-offset: -6px; position: relative; }
.chat.drop::after { content: "Drop files to send"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(15,118,110,.12); color: var(--accent); font-weight: 700; border-radius: var(--radius); pointer-events: none; }
