/* Family app — restyled to Jessica 2.0 design system. */
:root {
  --fg: #111;
  --bg: #fafafa;
  --accent: #0040a0;
  --bad: #b00020;
  --panel: #fff;
  --muted: #666;
  --border: #d8d8de;
  --danger: #b00020;
  --bot-bubble: #e9e9ee;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

/* ---- Shell ---- */
main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.view { display: none; }
.view.active { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.view.hidden { display: none !important; }

/* Non-chat views scroll themselves */
.view.active:not(#chat-view) {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding: 1rem;
}

/* ---- Login ---- */
#login-view.active { padding: 1.25rem 1.1rem 3rem; }
#login-head {
  display: flex; align-items: center; gap: .75rem;
  padding-bottom: .75rem; border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
#login-head .avatar {
  width: 3rem; height: 3rem; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
#login-title { margin: 0; font-size: 1.4rem; }
#login-head .household { color: var(--muted); font-size: .85rem; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
}
.lede { font-size: 1.05rem; margin: 0 0 1rem; }
.field { display: block; margin: .75rem 0; font-size: .95rem; color: var(--muted); }
.field select {
  display: block; margin-top: .35rem;
  font: inherit; padding: .55rem .7rem;
  width: 100%; max-width: 22rem;
  border: 1px solid var(--border); border-radius: .7rem;
  background: #fff; color: var(--fg);
}
.fine { color: var(--muted); font-size: .85rem; margin: .5rem 0 0; }

/* ---- Buttons (shared) ---- */
button {
  font: inherit;
  padding: .55rem .95rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
  line-height: 1.1;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }
button.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
button.ghost { background: transparent; border-color: transparent; }

/* ---- Chat head (Jessica 2.0 identity) ---- */
#chat-view.active {
  display: flex; flex-direction: column;
  min-height: 0; flex: 1 1 auto;
}
#chat-head {
  position: absolute;
  top: calc(env(safe-area-inset-top) + .35rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  pointer-events: none; text-align: center;
}
#chat-head-main {
  display: flex; align-items: center; gap: .45rem;
}
#chat-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.4rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.avatar-improve {
  pointer-events: auto;
  font-size: .7rem;
  padding: .25rem .55rem;
  border-radius: 1rem;
  background: rgba(255,255,255,.92);
  color: var(--accent);
  border: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(0,0,0,.10);
}
#chat-name {
  font-weight: 600; font-size: 1rem;
  background: rgba(255,255,255,.88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 1rem;
  padding: .1rem .7rem;
  box-shadow: 0 1px 6px rgba(0,0,0,.10);
}
#chat-status {
  font-size: .75rem; color: #2a7d2a;
  background: rgba(255,255,255,.75);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 1rem;
  padding: 0 .6rem;
}

/* Frosted band behind chat head */
#chat-view::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  z-index: 4; pointer-events: none;
  height: calc(env(safe-area-inset-top) + 6.4rem);
  background: linear-gradient(rgba(250,250,250,.66),
                              rgba(250,250,250,0));
  -webkit-backdrop-filter: blur(9px) saturate(1.4);
  backdrop-filter: blur(9px) saturate(1.4);
  -webkit-mask-image: linear-gradient(black 52%, transparent);
  mask-image: linear-gradient(black 52%, transparent);
}

/* ---- Messages ---- */
.messages {
  display: flex; flex-direction: column; gap: .45rem;
  padding: calc(env(safe-area-inset-top) + 7.4rem) .9rem 1.1rem;
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.msg {
  max-width: 78%;
  padding: .55rem .8rem;
  border-radius: 1.1rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: .3rem;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bot-bubble);
  color: var(--fg);
  border-bottom-left-radius: .3rem;
}
/* Calm alert bubble: normal assistant bubble colors, normal weight.
   (Fixed safety messages must not look alarming.) */
.msg.alert {
  align-self: flex-start;
  background: var(--bot-bubble);
  color: var(--fg);
  border-bottom-left-radius: .3rem;
  font-weight: 400;
}

/* ---- Compose dock ---- */
#compose-dock {
  /* In-flow, NOT floating (Nov 26): as an absolutely-positioned overlay
     the dock covered the newest messages whenever its real height beat
     the scroll area's fixed bottom padding - the padding math could
     never keep up (tall dock + nav + safe area). In the chat view's
     flex column the messages area simply ends where the dock begins,
     so a message can never go under it on any device. */
  position: relative;
  margin: .35rem .6rem .55rem;
  z-index: 6;
  flex: 0 0 auto;
}
#compose {
  display: flex; gap: .5rem; align-items: flex-end;
  background: rgba(255,255,255,.93);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(0,0,0,.07);
  border-radius: 1.6rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.15);
  padding: .35rem .45rem;
  margin: 0;
}
#compose-text {
  flex: 1 1 auto;
  font: inherit;
  font-size: 16px; /* iOS no-zoom rule */
  border: none;
  background: transparent;
  outline: none;
  border-radius: 1.1rem;
  padding: .55rem .75rem;
  resize: none;
  overflow-y: auto;
  line-height: 1.35;
  color: var(--fg);
}
#compose-send {
  border-radius: 1.1rem;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  padding: .55rem 1rem;
  flex: 0 0 auto;
  align-self: flex-end;
}

/* ---- Alerts view ---- */
.view-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin: 0 0 .6rem;
}
.view-head h2 { margin: 0; font-size: 1.3rem; }
.alert-list { list-style: none; padding: 0; margin: 0; }
.alert-list li {
  padding: .6rem .7rem;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.alert-list li .level {
  font-weight: 700;
  color: var(--danger);
  margin-right: .25em;
}

/* ---- Files view ---- */
.files-toolbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin: 0 0 .75rem;
}
#files-input { display: none; }
#files-cap { margin-left: auto; }
.files-list { list-style: none; padding: 0; margin: 0; }
.files-list li {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .3rem;
  border-bottom: 1px solid var(--border);
}
.files-list .fname {
  flex: 1 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600;
}
.files-list .fmeta {
  color: var(--muted); font-size: .8rem;
}
.files-list .fact {
  padding: .35rem .7rem;
  border-radius: 1rem;
  font-size: .85rem;
}
.files-list .fact.danger { color: var(--danger); border-color: var(--danger); }
.files-empty { color: var(--muted); font-style: italic; padding: 1rem .2rem; }

/* ---- Badge ---- */
.badge {
  display: inline-block; min-width: 1.2em;
  padding: 0 .35em; margin-left: .3em;
  border-radius: 1em;
  background: var(--danger); color: #fff;
  font-size: .75em;
}

/* ---- Top bar actions (floating) ---- */
#topbar-actions {
  position: fixed;
  top: calc(env(safe-area-inset-top) + .5rem);
  right: .6rem;
  z-index: 7;
  display: flex; gap: .4rem;
}
#topbar-actions.hidden { display: none; }
#topbar-actions button {
  background: rgba(255,255,255,.92);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 1rem;
  padding: .35rem .7rem;
  font-size: .85rem;
  box-shadow: 0 1px 6px rgba(0,0,0,.10);
}
#topbar-actions button.hidden { display: none; }

/* ---- Tab bar ---- */
#tabbar {
  /* In-flow (Nov 26): as a fixed overlay it floated over the chat
     view's bottom rows - first the newest messages, then, once the
     compose dock moved in-flow, the dock and the help bar crushed
     under it. In the body's flex column it takes its own height
     at the bottom and nothing overlaps anything. */
  position: relative;
  margin: .35rem .6rem calc(.55rem + env(safe-area-inset-bottom));
  flex: 0 0 auto;
  z-index: 5;
  display: flex;
  width: auto;
  background: rgba(255,255,255,.88);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  backdrop-filter: blur(16px) saturate(1.5);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 1.5rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.15);
  overflow: hidden;
  padding-bottom: 0;
}
#tabbar.hidden { display: none; }
#tabbar button {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  padding: .45rem .2rem;
  border: none;
  background: transparent;
  color: #666;
  cursor: pointer;
  border-radius: 0;
}
#tabbar button.active { color: var(--accent); }
#tabbar button.hidden { display: none; }
#tabbar svg { width: 22px; height: 22px; }
#tabbar .tab-label { font-size: 10px; line-height: 1; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(8.9rem + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: min(92vw, 30rem);
  background: rgba(20,20,24,.94);
  color: #fff;
  padding: .65rem 1rem;
  border-radius: .9rem;
  font-size: .9rem;
  text-align: center;
}
#toast.hidden { display: none; }

/* ---- House-down card ---- */
#house-card {
  position: fixed;
  left: .6rem; right: .6rem;
  bottom: calc(8.9rem + env(safe-area-inset-bottom));
  z-index: 80;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.2);
  padding: .8rem 1rem;
}
#house-card.hidden { display: none; }
#house-card-title { font-weight: 700; margin-bottom: .25rem; }
#house-card-body { color: var(--muted); font-size: .9rem; }

/* ---- Big-text mode (Mary) ---- */
[data-big-text="true"] { font-size: 125%; }
[data-big-text="true"] button { padding: .75rem 1.15rem; }
[data-big-text="true"] #compose-text { font-size: 1.15rem; }
[data-big-text="true"] .msg { max-width: 85%; }
[data-big-text="true"] #chat-avatar { width: 76px; height: 76px; }

/* ---- Face avatars + person rows (v2) ---- */
.avatar-img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
#chat-avatar .avatar-img, .avatar .avatar-img { border-radius: 50%; }
.people-rows { display: flex; flex-direction: column; gap: .5rem; margin: 0 0 1rem; }
.person-row {
  display: flex; align-items: center; gap: .75rem;
  width: 100%; text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: .55rem .8rem;
  font: inherit; color: var(--fg);
  cursor: pointer;
}
.person-row .avatar-img {
  width: 42px; height: 42px; flex: 0 0 auto;
  border: 2px solid var(--border);
}
.person-row.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.person-who { display: flex; flex-direction: column; }
.person-name { font-weight: 600; font-size: 1rem; }
.person-who small { color: var(--muted); font-size: .8rem; }

/* ---- Files view, premium pass (v2) ---- */
.files-list { display: flex; flex-direction: column; gap: .55rem; }
.files-list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 1rem;
  padding: .7rem .8rem;
  gap: .75rem;
}
.ficon {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: .8rem;
  display: flex; align-items: center; justify-content: center;
  font-size: .62rem; font-weight: 700; letter-spacing: .04em;
  background: #eef1f5; color: #44506b;
}
.ficon.pdf { background: #fdecec; color: #b3261e; }
.ficon.img { background: #e8f5e9; color: #256d2a; }
.ficon.doc { background: #e8eefc; color: #0040a0; }
.ficon.arc { background: #f3e8fd; color: #5e35b1; }
.ficon.aud { background: #fff4e0; color: #a15c00; }
.ficon.vid { background: #e0f2f1; color: #00695c; }
.fmain { flex: 1 1 auto; display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.files-list .fname { font-weight: 600; font-size: .98rem; }
.files-list .fmeta { font-size: .82rem; }
.files-list .fact {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
}

.fthumb {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: .8rem;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #eef1f5;
}

/* ---- Avatar editor (Stage 1) ---- */
.avatar-panel { padding: 1rem; }
.avatar-section-title { margin: 1rem 0 .5rem; font-size: 1rem; }
.avatar-section-title:first-child { margin-top: 0; }
.avatar-current {
  width: min(100%, 18rem);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  margin: 0 auto .5rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: #eef1f5;
}
.avatar-upload-row {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
}
#avatar-input { display: none; }
.avatar-thumbs {
  display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem;
}
.avatar-thumb {
  width: 64px; height: 64px; border-radius: .8rem;
  object-fit: cover; border: 1px solid var(--border);
  background: #eef1f5;
}
.avatar-candidates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: .6rem;
  margin-top: .6rem;
}
.avatar-candidate {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 1rem;
  border: 2px solid transparent;
  background: #eef1f5;
  cursor: pointer;
}
.avatar-candidate.selected {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
#avatar-pending.hidden,
#avatar-empty.hidden,
#avatar-error.hidden,
#btn-avatar-use.hidden {
  display: none;
}
@media (max-width: 600px) {
  .avatar-candidates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


/* ---- Phase 2: voice + guided help ---- */
.mic-btn.listening {
  background: #b3261e; color: #fff; border-color: #b3261e;
}
.listen-btn {
  display: block; margin-top: .45rem; font-size: .85rem;
  padding: .35rem .8rem; border-radius: 999px;
}
#help-bar { padding: .6rem .75rem 0; }
.help-btn {
  width: 100%; font-size: 1.05rem; padding: .8rem;
  border-radius: 12px; background: var(--accent); color: #fff;
  border-color: var(--accent);
}
[data-big-text="true"] .help-btn { font-size: 1.3rem; padding: 1.05rem; }
[data-big-text="true"] .listen-btn { font-size: 1rem; padding: .55rem 1.1rem; }

/* ---- Big-text layout repair (2026-11-24) ----
   Big-text mode used to only inflate fonts + button padding inside a
   fixed geometry, which crushed the compose row, the header, and the
   floating cards into each other. These rules give big-text a layout
   that actually reflows: stacked compose, roomier clearances. */
[data-big-text="true"] #chat-head {
  width: 100%;
  padding: 0 6.2rem;
  box-sizing: border-box;
}
[data-big-text="true"] .avatar-improve {
  font-size: .85rem;
  padding: .4rem .8rem;
}
[data-big-text="true"] .messages {
  padding-top: calc(env(safe-area-inset-top) + 8.8rem);
  padding-bottom: 1.1rem;
}
[data-big-text="true"] #compose-dock {
  bottom: auto;
}
[data-big-text="true"] #compose {
  flex-wrap: wrap;
}
[data-big-text="true"] #compose-text {
  flex: 1 1 100%;
  min-height: 3.4rem;
}
[data-big-text="true"] #btn-mic,
[data-big-text="true"] #compose-send {
  flex: 1 1 0;
  padding: .95rem .5rem;
  font-size: 1.12rem;
  align-self: stretch;
}
[data-big-text="true"] #tabbar button {
  padding: .7rem .2rem;
}
[data-big-text="true"] #tabbar svg { width: 26px; height: 26px; }
[data-big-text="true"] #tabbar .tab-label { font-size: 12px; }
[data-big-text="true"] #topbar-actions button {
  font-size: 1rem;
  padding: .5rem .9rem;
}
[data-big-text="true"] #house-card,
[data-big-text="true"] #toast {
  bottom: calc(17rem + env(safe-area-inset-bottom));
}
[data-big-text="true"] .person-row { padding: .9rem 1rem; }
[data-big-text="true"] .person-name { font-size: 1.15rem; }
[data-big-text="true"] #btn-login { width: 100%; }
[data-big-text="true"] .msg { max-width: 88%; }

/* Attachments — mirrored from Jessica's own app (Nov 25, 2026) */
#attach-btn { border-radius: 50%; width: 2.6rem; height: 2.6rem; flex: 0 0 auto;
              font-size: 1.15rem; align-self: flex-end; padding: 0;
              display: inline-flex; align-items: center; justify-content: center;
              line-height: 1; border: 1px solid var(--line, #ccc);
              background: var(--card, #fff); cursor: pointer; }
#attach-chip { flex: 0 0 auto; display: flex; align-items: center; gap: .5rem;
               background: #eef3fb; border: 1px solid #c9d8f2; color: #123;
               border-radius: .8rem; padding: .35rem .6rem; margin: 0 .45rem .4rem;
               font-size: .9rem; }
#attach-chip[hidden] { display: none; }
#attach-clear { margin-left: auto; }
#attach-sticker.on { background: #123; color: #fff; }
#attach-input { position: fixed; left: .4rem; bottom: .4rem; width: 2.6rem;
                height: 2.6rem; opacity: 0; pointer-events: none; z-index: 1; }
.msg img, .msg video { max-width: 100%; border-radius: .8rem; display: block; }
.msg img { min-height: 6rem; background: #dfe5ec; }
.msg .filechip { font-weight: 600; }
.msg audio { max-width: 100%; }

/* Family messages view (Nov 25, 2026) */
#msg-contact { width: 100%; font: inherit; font-size: 16px; padding: .5rem;
               border-radius: .7rem; border: 1px solid var(--line, #ccc);
               margin: .3rem 0 .6rem; background: var(--card, #fff);
               color: var(--ink, #111); }
#msg-log { min-height: 30vh; max-height: 52vh; overflow-y: auto;
           display: flex; flex-direction: column; gap: .4rem; padding: .4rem 0; }
#msg-compose { display: flex; gap: .5rem; align-items: flex-end;
               background: rgba(255,255,255,.93); border: 1px solid rgba(0,0,0,.07);
               border-radius: 1.6rem; padding: .35rem .45rem; }
#msg-text { flex: 1 1 auto; font: inherit; font-size: 16px; border: none;
            background: transparent; outline: none; padding: .55rem .75rem;
            resize: none; }
#msg-send { border-radius: 999px; padding: .55rem 1.1rem; border: none;
            background: #0b57d0; color: #fff; font: inherit; cursor: pointer; }
#msg-badge { position: relative; }

/* Message attachments (Nov 25, 2026) — same attach pattern as chat */
#msg-attach-btn { border-radius: 50%; width: 2.6rem; height: 2.6rem; flex: 0 0 auto;
                  font-size: 1.15rem; align-self: flex-end; padding: 0;
                  display: inline-flex; align-items: center; justify-content: center;
                  line-height: 1; border: 1px solid var(--line, #ccc);
                  background: var(--card, #fff); cursor: pointer; }
#msg-attach-chip { display: flex; align-items: center; gap: .5rem;
                   background: #eef3fb; border: 1px solid #c9d8f2; color: #123;
                   border-radius: .8rem; padding: .35rem .6rem; margin: 0 0 .4rem;
                   font-size: .9rem; }
#msg-attach-chip[hidden] { display: none; }
#msg-attach-clear { margin-left: auto; }
#msg-attach-input { position: fixed; left: .4rem; bottom: .4rem; width: 2.6rem;
                    height: 2.6rem; opacity: 0; pointer-events: none; z-index: 1; }
