/* FamilyTime — visual language taken from AlanLabs Communications ("ALP messaging"):
   same dark navy palette, sky-blue accent, card login, list + chat two-pane shell. */
:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #121b2e;
  --surface-raised: #182238;
  --border: #223049;
  --text: #eef2f8;
  --text-dim: #9aa9c2;
  --accent: #38bdf8;
  --accent-dark: #0ea5e9;
  --danger: #f87171;
  --ok: #22c55e;
  --bubble-me: #1d6fa5;
  --bubble-them: #1c2740;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; height: 100dvh; margin: 0; background: var(--bg); color: var(--text); }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.screen { height: 100dvh; width: 100%; display: flex; align-items: center; justify-content: center;
  padding: max(16px, var(--safe-top)) max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left)); }
.center-screen { background: var(--bg); }
.loading-spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ── */
.login-screen { background: radial-gradient(circle at 50% 0%, #14233d 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px 24px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand-mark { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; display: block; }
.brand h1 { font-size: 1.35rem; margin: 0 0 6px; }
.brand-subtitle { color: var(--text-dim); font-size: .9rem; margin: 0; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--text-dim); }
.field input, .field select { background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 1rem; color: var(--text); }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.primary-button { background: var(--accent); color: #06202f; border: none; border-radius: 10px; padding: 13px 16px; font-size: 1rem; font-weight: 600; }
.primary-button:disabled { opacity: .6; cursor: default; }
.secondary-button { background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.danger-button { background: rgba(248,113,113,.14); color: #fca5a5; border: 1px solid rgba(248,113,113,.4); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.small-button { padding: 7px 10px; font-size: .82rem; border-radius: 8px; }
.login-footnote { text-align: center; font-size: .78rem; color: var(--text-dim); margin: 18px 0 0; line-height: 1.45; }
.error-banner { background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.4); color: #fca5a5; border-radius: 8px; padding: 10px 12px; font-size: .85rem; }
.info-banner { background: rgba(56,189,248,.1); border: 1px solid rgba(56,189,248,.35); color: #bae6fd; border-radius: 8px; padding: 10px 12px; font-size: .85rem; line-height: 1.4; }

/* ── App shell ── */
.app-shell { height: 100dvh; width: 100%; display: flex; overflow: hidden; min-height: 0; }
.list-pane, .chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.list-pane { width: 100%; border-right: 1px solid var(--border); background: var(--surface); }
.chat-pane { width: 100%; flex: 1; background: var(--bg); }
.app-shell.show-list .chat-pane { display: none; }
.app-shell.show-chat .list-pane { display: none; }
@media (min-width: 820px) {
  .app-shell.show-list .chat-pane, .app-shell.show-chat .list-pane { display: flex; }
  .list-pane { width: 340px; flex: none; }
  .back-button { display: none; }
}
.empty-chat-placeholder { flex: 1; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; color: var(--text-dim); text-align: center; padding: 24px; }

.pane-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: max(14px, var(--safe-top)) 16px 14px; border-bottom: 1px solid var(--border); flex: none; min-width: 0; }
.pane-title { font-size: 1.2rem; margin: 0; display: flex; align-items: center; gap: 10px; }
.pane-title img { width: 28px; height: 28px; border-radius: 8px; }
.me-label { font-size: .78rem; color: var(--text-dim); }
.header-actions { display: flex; gap: 4px; align-items: center; }
.icon-button { background: transparent; border: none; color: var(--text); font-size: 1.25rem; line-height: 1; padding: 8px; border-radius: 10px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.icon-button:hover { background: var(--surface-raised); }
.icon-button svg { width: 22px; height: 22px; }

.connection-banner { padding: 8px 16px; font-size: .82rem; text-align: center; background: rgba(56,189,248,.12); color: #7dd3fc; }
.connection-banner.offline { background: rgba(248,113,113,.12); color: #fca5a5; }

.push-prompt { margin: 10px 12px 4px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-raised); display: flex; flex-direction: column; gap: 10px; }
.push-prompt strong { font-size: .92rem; }
.push-prompt p { margin: 4px 0 0; color: var(--text-dim); font-size: .85rem; line-height: 1.4; }
.push-prompt-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.section-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); padding: 14px 16px 4px; }
.conversation-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.conversation-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: transparent; border: none; text-align: left; }
.conversation-item:hover, .conversation-item.selected { background: var(--surface-raised); }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); display: flex; align-items: center; justify-content: center; font-weight: 700; color: #06202f; position: relative; font-size: 1.05rem; }
.avatar.small { width: 36px; height: 36px; font-size: .9rem; }
.avatar.huge { width: 112px; height: 112px; font-size: 2.6rem; }
.avatar .presence-dot { position: absolute; right: 0; bottom: 0; border: 2px solid var(--surface); width: 13px; height: 13px; }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.presence-online { background: var(--ok); }
.presence-offline { background: #64748b; }
.conversation-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conversation-top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conversation-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-time { font-size: .75rem; color: var(--text-dim); flex: none; }
.conversation-preview { font-size: .85rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item.unread .conversation-name { font-weight: 700; }
.conversation-item.unread .conversation-preview { color: var(--text); }
.unread-badge { background: var(--accent); color: #06202f; font-size: .72rem; font-weight: 700; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; }
.quick-call { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-raised); display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
.quick-call svg { width: 20px; height: 20px; }

/* ── Chat ── */
.chat-screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-header { gap: 10px; justify-content: flex-start; }
.chat-header-title { display: flex; flex-direction: column; min-width: 0; }
.chat-header-subtitle { font-size: .75rem; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.chat-header-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.call-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--accent); color: #06202f; border: none; border-radius: 999px; padding: 9px 14px; font-weight: 700; min-height: 40px; }
.call-pill svg { width: 20px; height: 20px; }
.call-pill.ghost { background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); padding: 9px 11px; }
.message-list { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 6px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.day-separator { text-align: center; font-size: .72rem; color: var(--text-dim); margin: 10px 0 6px; }
.message-row { display: flex; }
.message-row.from-me { justify-content: flex-end; }
.bubble { max-width: min(78%, 520px); padding: 8px 12px; border-radius: 16px; line-height: 1.35; word-wrap: break-word; white-space: pre-wrap; font-size: .97rem; }
.from-me .bubble { background: var(--bubble-me); border-bottom-right-radius: 4px; }
.from-them .bubble { background: var(--bubble-them); border-bottom-left-radius: 4px; }
.bubble.photo { padding: 4px; background: transparent !important; }
.bubble.photo img { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; cursor: zoom-in; }
.bubble .caption { padding: 6px 8px 2px; }
.bubble-meta { font-size: .68rem; color: rgba(238,242,248,.6); margin-top: 3px; text-align: right; }
.bubble.system { background: transparent; color: var(--text-dim); font-size: .8rem; text-align: center; margin: 0 auto; }
.typing-indicator { font-size: .78rem; color: var(--text-dim); padding: 0 16px 4px; min-height: 18px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px max(10px, var(--safe-bottom)); border-top: 1px solid var(--border); background: var(--surface); flex: none; }
.composer textarea { flex: 1; resize: none; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 20px; padding: 10px 14px; max-height: 140px; min-height: 42px; line-height: 1.3; font-size: 1rem; }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.composer .send-button { background: var(--accent); color: #06202f; border: none; border-radius: 50%; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.composer .send-button svg, .composer .icon-button svg { width: 22px; height: 22px; }
.ephemeral-note { font-size: .72rem; color: var(--text-dim); text-align: center; padding: 6px 12px 0; }

/* ── Modals ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3,7,15,.7); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal-sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px 18px 0 0; padding: 0 0 max(16px, var(--safe-bottom)); }
@media (min-width: 640px) { .modal-sheet { border-radius: 18px; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.admin-user { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: var(--surface-raised); display: flex; flex-direction: column; gap: 10px; }
.admin-user-top { display: flex; align-items: center; gap: 12px; }
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-info .name { font-weight: 700; }
.admin-user-info .sub { color: var(--text-dim); font-size: .8rem; margin-top: 2px; line-height: 1.4; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-block; font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: rgba(56,189,248,.16); color: var(--accent); margin-left: 6px; vertical-align: middle; }
.tag.warn { background: rgba(234,179,8,.16); color: #facc15; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.row .field { flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); }

/* ── Lightbox ── */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 90; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox .icon-button { position: absolute; top: max(10px, var(--safe-top)); right: max(10px, var(--safe-right)); color: #fff; background: rgba(0,0,0,.5); }

/* ── Toasts ── */
.toast-root { position: fixed; top: max(12px, var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); display: flex; gap: 10px; align-items: center; animation: toast-in .25s ease-out; cursor: pointer; }
.toast .toast-text { flex: 1; min-width: 0; font-size: .9rem; }
.toast .toast-text b { display: block; }
.toast .toast-text span { color: var(--text-dim); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes toast-in { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Calls ── */
.call-overlay { position: fixed; inset: 0; z-index: 80; background: #0b0d12; color: #fff; display: flex; flex-direction: column; }
.call-stage { flex: 1; position: relative; min-height: 0; background: #05070b; overflow: hidden; }
.call-remote-video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-stage.contain .call-remote-video { object-fit: contain; }
.call-self { position: absolute; right: max(12px, var(--safe-right)); top: max(70px, calc(var(--safe-top) + 60px)); width: min(30vw, 190px); aspect-ratio: 3 / 4; z-index: 2; border-radius: 14px; overflow: hidden; border: 2px solid rgba(255,255,255,.35); background: #111; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.call-self video { width: 100%; height: 100%; object-fit: cover; display: block; }
.call-self video.mirror { transform: scaleX(-1); }
.call-top { position: absolute; top: 0; left: 0; right: 0; z-index: 3; padding: max(14px, var(--safe-top)) 18px 30px; background: linear-gradient(rgba(0,0,0,.6), transparent); }
.call-top .who { font-size: 1.2rem; font-weight: 700; }
.call-top .status { font-size: .88rem; color: rgba(255,255,255,.78); margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.quality-badge { font-size: .7rem; padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.14); }
.quality-badge.good { background: rgba(34,197,94,.25); }
.quality-badge.poor { background: rgba(248,113,113,.3); }
.call-waiting { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 1; background: radial-gradient(circle at 50% 35%, #14233d 0%, #05070b 70%); }
.call-waiting .avatar { box-shadow: 0 0 0 0 rgba(56,189,248,.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(56,189,248,.55); } 70% { box-shadow: 0 0 0 28px rgba(56,189,248,0); } 100% { box-shadow: 0 0 0 0 rgba(56,189,248,0); } }
.call-waiting .who { font-size: 1.6rem; font-weight: 700; }
.call-waiting .status { color: rgba(255,255,255,.75); }
.call-controls { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; justify-content: center; gap: 18px; padding: 30px 16px max(22px, calc(var(--safe-bottom) + 12px)); background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.call-btn { width: 60px; height: 60px; border-radius: 50%; border: none; background: rgba(255,255,255,.18); color: #fff; display: inline-flex; align-items: center; justify-content: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.call-btn svg { width: 26px; height: 26px; }
.call-btn.off { background: rgba(255,255,255,.9); color: #0b0d12; }
.call-btn.end { background: #ef4444; }
.call-btn.accept { background: #22c55e; width: 72px; height: 72px; }
.call-btn.decline { background: #ef4444; width: 72px; height: 72px; }
.call-btn.accept svg, .call-btn.decline svg { width: 32px; height: 32px; }
.call-btn-label { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: .8rem; color: rgba(255,255,255,.85); }
.incoming-actions { display: flex; gap: 64px; margin-top: 36px; }
.ring-anim { animation: shake 1.2s infinite; }
@keyframes shake { 0%, 50%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(-14deg); } 20%, 40% { transform: rotate(14deg); } }
