:root {
  color-scheme: light;
  --ink: #18233f;
  --muted: #64708a;
  --navy: #17213b;
  --blue: #315fc4;
  --blue-soft: #eaf0ff;
  --paper: #f5f7fb;
  --line: #dce2ee;
  --white: #ffffff;
  --green: #30a46c;
  --danger: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--ink); background: var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 12% 15%, rgba(83, 121, 211, .28), transparent 34%),
    radial-gradient(circle at 88% 85%, rgba(74, 171, 143, .18), transparent 30%),
    linear-gradient(145deg, #111a31, #23345b);
}

.auth-card {
  width: min(100%, 430px);
  background: rgba(255, 255, 255, .97);
  border-radius: 24px;
  padding: 38px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .28);
}
.auth-card.wide { width: min(100%, 520px); }
.family-mark {
  width: 54px; height: 54px; border-radius: 18px;
  display: grid; place-items: center; margin-bottom: 25px;
  color: white; background: var(--blue); font-weight: 800; font-size: 25px;
  box-shadow: 0 10px 24px rgba(49, 95, 196, .28);
}
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.auth-card h1 { margin: 0; font-size: clamp(30px, 7vw, 42px); letter-spacing: -.04em; }
.auth-intro { color: var(--muted); line-height: 1.55; margin: 12px 0 25px; }
.auth-form { display: grid; gap: 9px; }
.auth-form label { margin-top: 8px; font-weight: 700; font-size: 14px; }
.auth-form input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; outline: none; background: white;
}
.auth-form input:focus, .composer textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(49, 95, 196, .12); }
.auth-form button, .composer button {
  border: 0; border-radius: 12px; background: var(--blue); color: white;
  font-weight: 800; padding: 14px 18px; margin-top: 14px;
}
.auth-form button:hover, .composer button:hover { background: #244da9; }
.privacy-note { margin: 24px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.error { color: var(--danger); background: #fff0ef; border: 1px solid #ffc9c5; border-radius: 12px; padding: 12px; margin-bottom: 15px; }

.chat-page { height: 100dvh; overflow: hidden; }
.chat-shell { height: 100%; display: grid; grid-template-rows: auto 1fr auto; max-width: 1100px; margin: auto; background: white; box-shadow: 0 0 50px rgba(18, 34, 65, .10); position: relative; }
.chat-header {
  min-height: 82px; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 14px 24px; color: white; background: var(--navy);
  border-bottom: 3px solid #5276cd;
}
.chat-header h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.chat-header .eyebrow { color: #9eb9ff; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.header-actions form { margin: 0; }
.signed-in { color: #d5def4; font-size: 14px; }
.secondary { border: 1px solid rgba(255,255,255,.28); background: rgba(255,255,255,.08); color: white; border-radius: 10px; padding: 9px 12px; }
.secondary:hover { background: rgba(255,255,255,.16); }
.admin-link { text-decoration: none; }

.messages { overflow-y: auto; padding: 26px 28px; scroll-behavior: smooth; background: linear-gradient(180deg, #f7f9fd, #eef2f8); }
.loading { color: var(--muted); text-align: center; padding: 40px; }
.message { max-width: min(74%, 640px); margin: 0 0 16px; }
.message.mine { margin-left: auto; }
.message-meta { display: flex; align-items: baseline; gap: 9px; padding: 0 5px 5px; color: var(--muted); font-size: 12px; }
.message.mine .message-meta { justify-content: flex-end; }
.message-meta strong { color: var(--ink); }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.48; padding: 12px 15px; border-radius: 7px 18px 18px 18px; background: white; box-shadow: 0 3px 14px rgba(31, 49, 84, .10); }
.message.mine p { color: white; background: var(--blue); border-radius: 18px 7px 18px 18px; }

.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px 18px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: white; }
.composer textarea { resize: none; width: 100%; min-height: 48px; max-height: 160px; border: 1px solid var(--line); border-radius: 15px; padding: 13px 15px; outline: none; line-height: 1.4; }
.composer button { align-self: end; min-height: 48px; margin: 0; }
.composer button:disabled { opacity: .55; cursor: wait; }
.composer-error { grid-column: 1 / -1; min-height: 0; color: var(--danger); font-size: 13px; }

.family-panel { position: absolute; z-index: 10; right: 18px; top: 72px; width: 230px; max-height: calc(100% - 110px); overflow: auto; background: white; border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: 0 18px 50px rgba(23, 33, 59, .24); }
.family-panel h2 { margin: 0 0 12px; font-size: 18px; }
.family-panel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.family-panel li { display: flex; align-items: center; gap: 9px; }
.status { width: 9px; height: 9px; border-radius: 50%; background: #b7becb; }
.status.online { background: var(--green); box-shadow: 0 0 0 3px rgba(48, 164, 108, .14); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.admin-page { min-height: 100vh; background: #eef2f8; }
.admin-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 60px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 25px 28px; margin-bottom: 20px; color: white; background: var(--navy); border-radius: 20px; box-shadow: 0 14px 34px rgba(23,33,59,.16); }
.admin-header h1 { margin: 0; font-size: clamp(28px, 5vw, 40px); }
.admin-header p:last-child { margin: 8px 0 0; color: #c9d5ef; }
.button-link { display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; padding: 11px 15px; font-weight: 750; text-decoration: none; white-space: nowrap; }
.secondary-link { color: white; border: 1px solid rgba(255,255,255,.32); background: rgba(255,255,255,.08); }
.notice { color: #17613e; background: #e9f8f0; border: 1px solid #b7e3ca; border-radius: 12px; padding: 12px 15px; margin-bottom: 15px; }
.admin-card { margin-bottom: 20px; padding: 25px; background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 25px rgba(23,33,59,.07); }
.admin-card h2 { margin: 2px 0 0; font-size: 23px; }
.section-help { margin: 7px 0 0; color: var(--muted); }
.create-card { display: grid; grid-template-columns: minmax(220px, .65fr) 1.35fr; align-items: end; gap: 30px; }
.create-user-form { display: grid; grid-template-columns: 1fr 1fr 1.15fr auto; align-items: end; gap: 10px; }
.create-user-form label { color: var(--muted); font-size: 12px; font-weight: 750; }
.create-user-form input, .reset-form input { width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; outline: none; }
.create-user-form input:focus, .reset-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(49,95,196,.11); }
.create-user-form button, .reset-form button, .quiet-button, .danger-button { min-height: 41px; border: 0; border-radius: 10px; padding: 9px 12px; font-weight: 750; }
.create-user-form button, .reset-form button { color: white; background: var(--blue); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 18px; }
.member-count { color: var(--muted); font-size: 13px; }
.user-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.user-card { padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: #fbfcff; }
.user-card.inactive { opacity: .7; background: #f4f5f7; }
.user-summary { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.avatar { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; color: white; background: var(--blue); font-size: 18px; font-weight: 850; }
.user-summary h3 { margin: 0; font-size: 18px; }
.user-summary p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.badges { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.badge { border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 750; }
.admin-badge { color: #244da9; background: var(--blue-soft); }
.active-badge { color: #17613e; background: #e9f8f0; }
.inactive-badge { color: #5b6270; background: #e8eaf0; }
.password-badge { color: #8a5211; background: #fff4df; }
.user-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; color: var(--muted); font-size: 11px; }
.user-meta div { min-width: 0; }
.user-meta dt { font-weight: 750; }
.user-meta dd { margin: 3px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: end; }
.user-actions form { margin: 0; }
.reset-form { display: grid; grid-template-columns: minmax(110px,1fr) auto; gap: 7px; flex: 1 1 100%; }
.quiet-button { color: var(--ink); background: #e9edf5; }
.danger-button { color: var(--danger); background: #fff0ef; }
.audit-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 0; }
.audit-list li { display: grid; grid-template-columns: 1fr auto; gap: 15px; padding: 11px 0; border-top: 1px solid var(--line); font-size: 14px; }
.audit-list time { color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  .auth-card { padding: 28px 22px; border-radius: 20px; }
  .chat-header { min-height: 70px; padding: 11px 13px; }
  .chat-header h1 { font-size: 20px; }
  .signed-in { display: none; }
  .header-actions { gap: 6px; }
  .secondary { padding: 8px 9px; font-size: 13px; }
  .messages { padding: 18px 12px; }
  .message { max-width: 88%; }
  .composer { padding: 10px 10px max(10px, env(safe-area-inset-bottom)); }
  .composer button { padding-inline: 15px; }
  .family-panel { right: 10px; top: 62px; }
  .admin-shell { width: min(100% - 20px, 1180px); padding-top: 10px; }
  .admin-header { align-items: flex-start; padding: 20px; }
  .admin-card { padding: 18px; }
  .create-card { grid-template-columns: 1fr; gap: 18px; }
  .create-user-form { grid-template-columns: 1fr; }
  .user-grid { grid-template-columns: 1fr; }
  .audit-list li { grid-template-columns: 1fr; gap: 4px; }
}

@media (max-width: 900px) and (min-width: 641px) {
  .create-card { grid-template-columns: 1fr; }
  .create-user-form { grid-template-columns: 1fr 1fr; }
}
