:root {
  --ink: #0E1116; --surface: #171B22; --raised: #1F242E; --border: #2A303B;
  --text: #E8EBF0; --muted: #8A93A3; --primary: #7C83FB; --primary-in: #10131a;
  --secure: #4ADE9E; --danger: #F4526A; --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
/* The hidden attribute must always win, even over class display rules below.
   Without this, screens/overlays with their own display value ignore [hidden]. */
[hidden] { display: none !important; }

.screen { height: 100%; }
.center { display: grid; place-items: center; padding: 24px; background: radial-gradient(1000px 560px at 50% -10%, rgba(124,131,251,0.10), transparent 70%), var(--ink); }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---- cards / auth ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.auth-card { width: 100%; max-width: 380px; padding: 30px; text-align: center; }
.mark { display: inline-grid; place-items: center; width: 50px; height: 50px; border-radius: 14px; color: var(--secure); background: var(--raised); border: 1px solid var(--border); margin-bottom: 18px; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; font-weight: 640; margin: 0 0 10px; }
.lede { color: var(--muted); line-height: 1.55; margin: 0 0 22px; }
.fine { color: #5c6472; font-size: 0.8rem; margin: 18px 0 0; line-height: 1.5; }
#google-btn { display: flex; justify-content: center; min-height: 44px; }

input[type=text], input[type=password] { width: 100%; background: var(--raised); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 1rem; padding: 12px 13px; }
input::placeholder { color: #5c6472; }
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,131,251,0.18); }
.primary { width: 100%; margin-top: 12px; background: var(--primary); color: var(--primary-in); border: none; border-radius: 10px; font-weight: 640; padding: 12px; }
.primary:hover { filter: brightness(1.08); }
.err { color: var(--danger); font-size: 0.9rem; margin: 12px 0 0; }

/* ---- app layout ---- */
.app { display: grid; grid-template-columns: 320px 1fr; height: 100%; }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.me { display: flex; align-items: center; gap: 11px; padding: 16px; border-bottom: 1px solid var(--border); }
.me-text { flex: 1; min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-username { color: var(--muted); font-size: 0.85rem; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--raised); flex: 0 0 auto; }
.avatar.sm { width: 34px; height: 34px; }
.avatar.lg { width: 88px; height: 88px; }
.icon-btn { background: transparent; border: none; color: var(--muted); padding: 6px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--raised); }

.add-form { display: flex; gap: 8px; padding: 14px 16px 6px; }
.add-form input { flex: 1; }
.add-form button { width: 42px; border: 1px solid var(--border); background: var(--raised); color: var(--text); border-radius: 10px; font-size: 1.2rem; }
.add-form button:hover { border-color: var(--primary); color: var(--primary); }
.add-msg { margin: 0 16px; font-size: 0.85rem; padding: 6px 0; }
.add-msg.ok { color: var(--secure); }
.add-msg.err { color: var(--danger); }

.block { padding: 10px 16px; }
.block h2 { font-size: 0.78rem; color: var(--muted); font-weight: 600; margin: 8px 0; }
.friends-block { flex: 1; min-height: 0; overflow-y: auto; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.friend, .request { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.friend:hover { background: var(--raised); }
.friend.active { background: var(--raised); }
.friend-text { flex: 1; min-width: 0; }
.friend-name { font-weight: 550; font-size: 0.94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-username { color: var(--muted); font-size: 0.8rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #3a424f; flex: 0 0 auto; }
.status-dot.on { background: var(--secure); box-shadow: 0 0 0 3px rgba(74,222,158,0.16); }
.empty { color: var(--muted); font-size: 0.86rem; padding: 4px 10px; line-height: 1.5; }

.request { cursor: default; }
.req-actions { display: flex; gap: 6px; }
.mini { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--raised); color: var(--text); }
.mini.ok:hover { border-color: var(--secure); color: var(--secure); }
.mini.no:hover { border-color: var(--danger); color: var(--danger); }

/* ---- conversation ---- */
.conversation { display: flex; flex-direction: column; min-width: 0; }
.convo-empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.convo { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.convo-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.convo-peer { display: flex; align-items: center; gap: 11px; }
.peer-name { font-weight: 600; }
.peer-status { font-size: 0.82rem; color: var(--muted); }
.peer-status.on { color: var(--secure); }
.call-btn { display: flex; align-items: center; gap: 8px; background: var(--secure); color: #06110b; border: none; border-radius: 10px; padding: 9px 16px; font-weight: 640; }
.call-btn:hover { filter: brightness(1.08); }
.call-btn:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

.chat-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 68%; padding: 9px 13px; border-radius: 14px; line-height: 1.4; font-size: 0.95rem; word-wrap: break-word; }
.bubble.mine { align-self: flex-end; background: var(--primary); color: var(--primary-in); border-bottom-right-radius: 4px; }
.bubble.theirs { align-self: flex-start; background: var(--raised); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-form { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.msg-form input { flex: 1; }
.msg-form button { background: var(--primary); color: var(--primary-in); border: none; border-radius: 10px; padding: 0 18px; font-weight: 600; }

/* ---- ring (incoming) ---- */
.ring { position: fixed; inset: 0; background: rgba(8,10,14,0.7); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; }
.ring-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px 40px; text-align: center; }
.ring-name { font-size: 1.3rem; font-weight: 640; margin-top: 14px; }
.ring-sub { color: var(--muted); margin-top: 4px; }
.ring-actions { display: flex; gap: 14px; margin-top: 26px; justify-content: center; }
.ring-actions .ctrl { width: auto; padding: 0 22px; height: 46px; border-radius: 12px; font-weight: 600; }

/* ---- call overlay ---- */
.call-overlay { position: fixed; inset: 0; background: #06080b; z-index: 60; }
.remote-video { width: 100%; height: 100%; object-fit: contain; background: #06080b; }
.local-video { position: absolute; right: 18px; bottom: 100px; width: 200px; max-width: 34vw; border-radius: 12px; border: 1px solid var(--border); object-fit: cover; transform: scaleX(-1); box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
.call-status { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); color: var(--muted); font-size: 1rem; }
.secure-badge { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 7px; color: var(--secure); font-size: 0.8rem; font-weight: 550; background: rgba(74,222,158,0.1); border: 1px solid rgba(74,222,158,0.24); padding: 6px 12px; border-radius: 999px; z-index: 2; }

.controls { position: absolute; bottom: 24px; left: 0; right: 0; display: flex; justify-content: center; gap: 14px; }
.ctrl { width: 54px; height: 54px; border-radius: 15px; border: 1px solid var(--border); background: rgba(31,36,46,0.85); backdrop-filter: blur(8px); color: var(--text); display: grid; place-items: center; transition: background .15s, color .15s, border-color .15s; }
.ctrl:hover { border-color: #3a424f; }
.ctrl.off { background: rgba(244,82,106,0.16); border-color: rgba(244,82,106,0.4); color: var(--danger); }
.ctrl.leave { background: var(--danger); border-color: var(--danger); color: #14060a; }
.ctrl.accept { background: var(--secure); border-color: var(--secure); color: #06110b; }
.ctrl.active { background: rgba(124,131,251,0.22); border-color: rgba(124,131,251,0.5); color: var(--primary); }
.ctrl.leave:hover, .ctrl.accept:hover { filter: brightness(1.08); }

/* ---- call top bar + timer ---- */
.call-top { position: absolute; top: 16px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 2; }
.call-timer { color: var(--text); font-size: 0.9rem; font-variant-numeric: tabular-nums; background: rgba(10,12,16,0.6); backdrop-filter: blur(6px); padding: 4px 12px; border-radius: 999px; }
.secure-badge { position: static; transform: none; }

/* ---- back button (mobile nav) ---- */
.back-btn { display: none; }

/* ---- unread badge ---- */
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: var(--primary-in); font-size: 0.74rem; font-weight: 700; display: grid; place-items: center; flex: 0 0 auto; }

/* ---- hints ---- */
.notif-hint, .ios-hint { margin: 8px 16px 0; padding: 10px 12px; border: 1px solid var(--border); background: var(--raised); border-radius: 10px; font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 10px; line-height: 1.4; }
.notif-hint button { flex: 0 0 auto; background: var(--primary); color: var(--primary-in); border: none; border-radius: 8px; padding: 6px 12px; font-weight: 600; }
.ios-hint button { flex: 0 0 auto; background: transparent; border: none; color: var(--muted); font-size: 1rem; padding: 2px 6px; }
.ios-hint button:hover { color: var(--text); }

/* ---- responsive ---- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .conversation { display: none; }
  .app.show-convo .sidebar { display: none; }
  .app.show-convo .conversation { display: flex; }
  .back-btn { display: grid; }
  .convo-head { padding-top: max(14px, env(safe-area-inset-top)); }
  .local-video { width: 130px; bottom: 110px; right: 14px; }
  .controls { bottom: max(24px, env(safe-area-inset-bottom)); gap: 10px; }
  .ctrl { width: 58px; height: 58px; }
  .me { padding-top: max(16px, env(safe-area-inset-top)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
