:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-muted: #efefeb;
  --ink: #1c2522;
  --muted: #66716d;
  --line: #dfe3df;
  --green: #23845f;
  --green-soft: #dff2e9;
  --amber: #b26a1b;
  --red: #c84845;
  --blue: #276c9e;
  --shadow: 0 14px 38px rgb(28 37 34 / 10%);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgb(39 108 158 / 30%); outline-offset: 2px; }

.app-shell { min-height: 100dvh; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.topbar { position: sticky; top: 0; z-index: 10; height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 20px; background: rgb(247 247 244 / 94%); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 21px; font-weight: 750; }
.brand img { width: 34px; height: 34px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.content { width: min(1060px, 100%); margin: 0 auto; padding: 28px 20px 52px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.section-heading h1 { margin: 0; font-size: clamp(26px, 5vw, 38px); line-height: 1.05; letter-spacing: 0; }
.section-heading p { margin: 7px 0 0; color: var(--muted); }

.icon-button { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); }
.icon-button:hover { border-color: #bdc7c1; background: #fafbf9; }
.icon-button svg, .call-button svg, .back-button svg { width: 21px; height: 21px; }
.primary-button, .secondary-button, .danger-button { min-height: 46px; padding: 0 18px; border-radius: 7px; border: 1px solid transparent; font-weight: 700; }
.primary-button { color: white; background: var(--green); }
.secondary-button { color: var(--ink); background: var(--surface); border-color: var(--line); }
.danger-button { color: white; background: var(--red); }
.text-button { border: 0; background: transparent; color: var(--blue); padding: 8px; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.family-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; }
.person-card { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 1px 0 rgb(28 37 34 / 3%); }
.person-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.avatar-wrap { position: relative; flex: 0 0 auto; width: 62px; height: 62px; padding: 3px; border: 3px solid #aab2ae; border-radius: 50%; }
.avatar-wrap.online { border-color: var(--green); }
.avatar-wrap.dnd { border-color: var(--amber); }
.avatar { width: 100%; height: 100%; display: grid; place-items: center; border-radius: 50%; object-fit: cover; background: var(--surface-muted); color: #46514d; font-size: 20px; font-weight: 800; }
.person-copy { min-width: 0; }
.person-copy h2 { overflow: hidden; margin: 0; font-size: 18px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.person-copy p { overflow: hidden; margin: 6px 0 0; color: var(--muted); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.person-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; }
.call-button { height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); font-weight: 700; }
.call-button.video { color: var(--blue); }
.call-button.audio { color: var(--green); }
.call-button:disabled { cursor: not-allowed; opacity: .45; }

.auth-layout { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)); }
.auth-panel { width: min(410px, 100%); }
.auth-logo { width: 76px; height: 76px; display: block; margin: 0 auto 22px; }
.auth-panel h1 { margin: 0; text-align: center; font-size: 34px; }
.auth-panel > p { margin: 9px 0 28px; text-align: center; color: var(--muted); }
.form-stack { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field span { color: #4b5753; font-size: 14px; font-weight: 700; }
.field input, .field textarea, .field select { width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid #cbd2ce; border-radius: 7px; background: var(--surface); color: var(--ink); }
.field textarea { min-height: 82px; resize: vertical; }
.form-error { min-height: 20px; margin: 0; color: var(--red); font-size: 14px; }

.panel { padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.settings-grid { display: grid; grid-template-columns: minmax(180px, 280px) minmax(0, 1fr); gap: 18px; }
.settings-nav { display: grid; align-content: start; gap: 6px; }
.settings-nav button { min-height: 44px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); text-align: left; }
.settings-nav button.active { background: var(--green-soft); color: #145b40; font-weight: 700; }
.admin-list { display: grid; gap: 10px; margin-top: 18px; }
.admin-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.admin-row strong, .admin-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-row small { color: var(--muted); margin-top: 3px; }

.call-screen { position: fixed; inset: 0; z-index: 100; display: grid; grid-template-rows: 1fr auto; min-height: 100dvh; background: #17201d; color: white; }
.call-stage { position: relative; display: grid; place-items: center; overflow: hidden; }
.remote-video { width: 100%; height: 100%; object-fit: cover; background: #17201d; }
.local-video { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: 18px; width: min(29vw, 180px); aspect-ratio: 3 / 4; object-fit: cover; border: 1px solid rgb(255 255 255 / 35%); border-radius: 8px; background: #2a3632; box-shadow: var(--shadow); }
.call-person { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 14px; pointer-events: none; }
.call-person .avatar-wrap { width: 106px; height: 106px; border-color: #77c9a6; animation: ring 1.7s ease-in-out infinite; }
.call-person h2 { margin: 0; font-size: 26px; }
.call-person p { margin: 0; color: #c7d0cc; }
.call-controls { z-index: 2; min-height: 104px; display: flex; align-items: center; justify-content: center; gap: 13px; padding: 16px max(18px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)); background: rgb(15 22 20 / 90%); }
.call-control { width: 54px; height: 54px; display: grid; place-items: center; border: 0; border-radius: 50%; background: #33413c; color: white; }
.call-control.active { background: white; color: #26312d; }
.call-control.end { background: var(--red); }
.incoming-actions .call-control.accept { background: var(--green); }

.toast-region { position: fixed; z-index: 200; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.toast { max-width: 340px; padding: 12px 15px; border-radius: 7px; background: #24302c; color: white; box-shadow: var(--shadow); }
.empty { padding: 48px 20px; color: var(--muted); text-align: center; border: 1px dashed #c8ceca; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@keyframes ring { 50% { box-shadow: 0 0 0 13px rgb(119 201 166 / 12%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; } }
@media (max-width: 680px) {
  .topbar { height: 60px; padding-inline: 14px; }
  .content { padding: 22px 14px 40px; }
  .family-grid { grid-template-columns: 1fr; }
  .person-card { padding: 16px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav { grid-template-columns: 1fr 1fr; }
  .section-heading { align-items: start; flex-direction: column; }
}
