:root {
  color-scheme: light;
  --ink: #17312d;
  --muted: #61736f;
  --paper: #f7fbfa;
  --white: #ffffff;
  --line: #d7e5e1;
  --green: #117a65;
  --green-dark: #0c594b;
  --mint: #d9f3e9;
  --gold: #f5b82e;
  --gold-soft: #fff0bd;
  --coral: #e86759;
  --coral-soft: #ffe2dd;
  --blue: #3b82b7;
  --blue-soft: #dceffa;
  --shadow: 0 18px 50px rgba(21, 58, 50, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

.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;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px;
  background: linear-gradient(120deg, #d9f3e9 0 52%, #f7fbfa 52% 100%);
}

.auth-shell {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, 0.95fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 460px;
  padding: 48px 40px;
  background: var(--mint);
  border-right: 1px solid #bedfd5;
}

.auth-avatar {
  width: clamp(128px, 17vw, 190px);
  aspect-ratio: 1;
  object-fit: cover;
  border: 5px solid var(--white);
  border-radius: 50%;
  box-shadow: 0 14px 28px rgba(20, 92, 76, 0.18);
}

.auth-brand h1 {
  max-width: 10ch;
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand-line { max-width: 28ch; margin: 18px 0 0; color: #42645c; line-height: 1.55; }
.auth-panel { align-self: center; padding: 40px; }
.panel-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.panel-heading h2 { margin: 0 0 4px; font-size: 1.45rem; }
.panel-heading p { margin: 0; color: var(--muted); }
.heading-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; background: var(--gold-soft); font-size: 1.4rem; }

.form-stack { display: grid; gap: 9px; }
.form-stack label { margin-top: 8px; font-size: 0.86rem; font-weight: 750; }
.form-stack input, .composer input {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid #b9cbc6;
  border-radius: 6px;
  color: var(--ink);
  background: var(--white);
  outline: none;
}
.form-stack input:focus, .composer input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(17, 122, 101, 0.14); }

.primary-button, .secondary-button, .start-button, .choice-button, .download-button {
  min-height: 42px;
  border-radius: 6px;
  font-weight: 750;
  text-decoration: none;
}
.primary-button { margin-top: 18px; border: 0; color: var(--white); background: var(--green); }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { padding: 0 14px; border: 1px solid var(--green); color: var(--green); background: var(--white); }
.secondary-button:hover { color: var(--white); background: var(--green); }

.alert { padding: 12px 14px; border: 1px solid; border-radius: 6px; font-size: 0.9rem; line-height: 1.4; }
.alert-error { color: #8c2f27; border-color: #f0aaa1; background: var(--coral-soft); }
.alert-success { color: #155f50; border-color: #8bcab9; background: var(--mint); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
  grid-template-areas: "top top" "side chat";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
  z-index: 2;
}
.wordmark { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.wordmark img { width: 44px; height: 44px; object-fit: cover; border-radius: 50%; }
.wordmark span { display: grid; line-height: 1.1; }
.wordmark strong { font-size: 0.96rem; }
.wordmark small { margin-top: 4px; color: var(--muted); font-size: 0.72rem; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { display: contents; }
.user-chip { display: flex; align-items: center; gap: 6px; margin-right: 4px; color: #32564e; font-size: 0.88rem; font-weight: 700; }
.icon-link, .icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--white);
  text-decoration: none;
}
.icon-link:hover, .icon-button:hover { border-color: var(--green); background: var(--mint); }

.side-panel {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 32px 24px 24px;
  color: var(--white);
  background: #126d5d;
}
.side-panel .eyebrow { color: #bfe8dc; }
.side-intro h2 { margin: 0; font-size: 1.65rem; }
.side-intro p:last-child { margin: 7px 0 0; color: #d9eee8; }
.start-button { display: flex; align-items: center; gap: 10px; width: 100%; margin: 28px 0; padding: 0 14px; border: 0; color: #4e3b07; background: var(--gold); }
.start-button:hover { background: #ffd05a; }
.status-list { display: grid; gap: 12px; padding: 20px 0; border-top: 1px solid rgba(255, 255, 255, 0.18); border-bottom: 1px solid rgba(255, 255, 255, 0.18); }
.status-list span { display: flex; align-items: center; gap: 9px; color: #e6f4f0; font-size: 0.82rem; }
.status-dot { flex: 0 0 auto; display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-green { background: #50d19f; }
.status-gold { background: var(--gold); }
.status-blue { background: #68bff0; }
.family-note { display: flex; align-items: center; gap: 11px; margin-top: auto; padding-top: 24px; color: #d8f0e9; }
.family-note > span { color: #ff9c91; font-size: 1.25rem; }
.family-note p { margin: 0; font-size: 0.78rem; line-height: 1.5; }

.chat-panel {
  grid-area: chat;
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  height: calc(100vh - 72px);
  background: var(--paper);
}
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 24px clamp(20px, 4vw, 52px) 16px; }
.chat-header h1 { margin: 0; font-size: 1.55rem; }
.online-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.8rem; }
.chat-log { overflow-y: auto; padding: 6px clamp(20px, 4vw, 52px) 24px; scroll-behavior: smooth; }
.message { width: fit-content; max-width: min(720px, 86%); margin: 15px 0; }
.message p { margin: 4px 0 0; padding: 14px 16px; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.message-label { color: var(--muted); font-size: 0.7rem; font-weight: 800; }
.message-bot p { border: 1px solid var(--line); background: var(--white); box-shadow: 0 6px 18px rgba(30, 72, 63, 0.06); }
.message-user { margin-left: auto; text-align: right; }
.message-user p { color: var(--white); background: var(--green); text-align: left; }
.message-error p { color: #8c2f27; border: 1px solid #f0aaa1; background: var(--coral-soft); }
.chat-actions { display: flex; flex-wrap: wrap; gap: 8px; min-height: 50px; padding: 8px clamp(20px, 4vw, 52px) 10px; }
.choice-button, .download-button { display: inline-flex; align-items: center; min-height: 38px; padding: 8px 13px; border: 1px solid #a9c7bf; color: #175f50; background: var(--white); }
.choice-button:hover { border-color: var(--green); background: var(--mint); }
.download-button { color: #155577; border-color: #96c7df; background: var(--blue-soft); }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) 46px; gap: 9px; padding: 10px clamp(20px, 4vw, 52px) 22px; }
.composer[hidden] { display: none; }
.composer input { min-width: 0; box-shadow: 0 8px 24px rgba(30, 72, 63, 0.06); }
.composer button { width: 46px; height: 46px; border: 0; border-radius: 6px; color: var(--white); background: var(--coral); font-size: 1.25rem; }
.composer button:hover { background: #c94d41; }
.composer button:disabled, .choice-button:disabled { cursor: wait; opacity: 0.55; }

.simple-header { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 0 clamp(20px, 5vw, 70px); border-bottom: 1px solid var(--line); background: var(--white); }
.back-link { color: var(--green); font-weight: 750; text-decoration: none; }
.admin-main { width: min(1040px, calc(100% - 40px)); margin: 42px auto; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.section-heading h1 { margin: 0; font-size: 2rem; }
.admin-badge, .role-badge, .pending-badge, .ready-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 5px; font-size: 0.72rem; font-weight: 800; }
.admin-badge, .role-admin { color: #5c460d; background: var(--gold-soft); }
.role-member { color: #155f50; background: var(--mint); }
.pending-badge { color: #8c2f27; background: var(--coral-soft); }
.ready-badge { color: #155577; background: var(--blue-soft); }
.user-list { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
.user-row { display: grid; grid-template-columns: 46px minmax(180px, 1fr) auto auto; align-items: center; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-avatar { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: var(--white); background: var(--green); font-weight: 850; }
.user-identity h2 { margin: 0 0 4px; font-size: 1rem; }
.user-identity p { margin: 0; color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }
.user-flags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

@media (max-width: 760px) {
  .auth-page { padding: 0; background: var(--paper); }
  .auth-shell { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; box-shadow: none; }
  .auth-brand { min-height: auto; padding: 28px 24px; border-right: 0; border-bottom: 1px solid #bedfd5; }
  .auth-avatar { width: 92px; }
  .auth-brand h1 { font-size: 2rem; }
  .brand-line { margin-top: 10px; font-size: 0.9rem; }
  .auth-panel { padding: 28px 24px 38px; }
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 64px auto minmax(0, 1fr); grid-template-areas: "top" "side" "chat"; }
  .topbar { padding: 0 14px; }
  .wordmark img { width: 38px; height: 38px; }
  .user-chip { display: none; }
  .side-panel { padding: 16px 18px; }
  .side-intro, .status-list, .family-note { display: none; }
  .start-button { width: auto; margin: 0; }
  .chat-panel { height: calc(100vh - 122px); grid-template-rows: auto minmax(180px, 1fr) auto auto; }
  .chat-header { padding-top: 16px; }
  .message { max-width: 92%; }
  .chat-actions { max-height: 128px; overflow-y: auto; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .user-row { grid-template-columns: 42px minmax(0, 1fr); }
  .user-flags, .user-row form { grid-column: 2; justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
