:root {
  --bg: #f1f5f9; --panel: #ffffff; --text: #0f172a; --muted: #64748b;
  --mine: #2563eb; --mine-text: #ffffff; --theirs: #ffffff; --border: #e2e8f0;
  --accent: #2563eb; --red: #dc2626; --green: #16a34a;
  --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --panel: #111827; --text: #e5e7eb; --muted: #94a3b8;
    --mine: #2563eb; --theirs: #1f2937; --border: #1f2937; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); background: var(--panel); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 14px; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; padding: 24px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { font-size: 20px; margin: 0; text-align: center; }
.card p { margin: 0; font-size: 14px; }
.logo { width: 64px; height: 64px; border-radius: 14px; align-self: center; }
.card input { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 600; }
.primary:disabled { opacity: .6; }
.primary.small { padding: 6px 14px; }
.link { background: none; border: 0; color: var(--accent); padding: 6px; }
.danger { color: var(--red) !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 4px; padding: calc(8px + var(--safe-top)) 8px 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); }
.title { flex: 1; min-width: 0; }
.title .appName { font-weight: 600; }
.icon { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px;
  border: 0; background: none; border-radius: 50%; color: var(--accent); flex-shrink: 0; }
.icon svg { width: 24px; height: 24px; fill: currentColor; }
.icon:active { background: var(--border); }

.banner { background: #fef3c7; color: #78350f; padding: 10px 16px; font-size: 14px; }

/* messages */
#messages { flex: 1; overflow-y: auto; padding: 12px 10px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#loadOlder { display: block; margin: 0 auto 8px; }
.daysep { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 8px; }
.msg { display: flex; margin: 3px 0; }
.msg.mine { justify-content: flex-end; }
.bubble { max-width: 78%; padding: 7px 11px 5px; border-radius: 18px; background: var(--theirs);
  border: 1px solid var(--border); word-wrap: break-word; overflow-wrap: anywhere; }
.mine .bubble { background: var(--mine); color: var(--mine-text); border-color: var(--mine); }
.msg.pending .bubble { opacity: .6; }
.sender { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.time { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.photo { display: block; max-width: 100%; height: auto; border-radius: 12px; margin: 2px -4px; background: rgba(0,0,0,.08); min-width: 120px; min-height: 80px; }
.voice { display: flex; align-items: center; gap: 8px; }
.voice audio { width: 220px; max-width: 60vw; height: 40px; }
.typing { padding: 0 16px 4px; }

/* composer */
.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 6px 6px calc(6px + var(--safe-bottom)); }
.inputbar, .recordbar { display: flex; align-items: flex-end; gap: 4px; }
.recordbar { align-items: center; padding: 6px 10px; gap: 12px; }
.recordbar #recordTime { flex: 1; font-variant-numeric: tabular-nums; }
.recordbar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
#text { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 20px; padding: 9px 14px;
  max-height: 140px; outline: none; font-size: 16px; }
.icon.send { color: #fff; background: var(--accent); }

/* sheets */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet-card { width: 100%; max-width: 480px; background: var(--panel); border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; }
.sheet-card > button:not(.link), #pickerList button { padding: 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); text-align: left; width: 100%; }
#pickerList { display: flex; flex-direction: column; gap: 8px; }

/* call */
.callscreen { position: fixed; inset: 0; background: #0b1120; color: #fff; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: space-between; padding: calc(40px + var(--safe-top)) 20px calc(40px + var(--safe-bottom)); }
#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
#localVideo { position: absolute; right: 16px; top: calc(16px + var(--safe-top)); width: 28vw; max-width: 160px; aspect-ratio: 3/4;
  object-fit: cover; border-radius: 12px; display: none; transform: scaleX(-1); z-index: 2; }
.callscreen.video #remoteVideo, .callscreen.video #localVideo { display: block; }
.callinfo { position: relative; z-index: 2; text-align: center; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.callname { font-size: 28px; font-weight: 600; }
.callinfo .muted { color: #cbd5e1; }
.callbuttons { position: relative; z-index: 2; display: flex; gap: 22px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; }
.round svg { width: 28px; height: 28px; fill: currentColor; }
.round.off { background: #fff; color: #0b1120; }
.round.red { background: var(--red); }
.round.green { background: var(--green); }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 40; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: 90vw; text-align: center; }
.mine .muted { color: rgba(255,255,255,.8); }
