/* famchat — warm, all-ages chat UI.
   Signature: the accent colour reflects the account type. Adults get pine
   green; kid accounts switch to violet (via .role-kid on <body>), so a guardian
   glancing at the screen can tell which mode a session is in. */

:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --ink: #1b2a27;
  --muted: #5f726c;
  --border: #e3eae6;
  --accent: #2e9e7b;        /* adult / default */
  --accent-ink: #1f7d60;    /* darker accent for hover/text */
  --accent-soft: #e7f4ee;   /* tint for user bubbles */
  --warm: #f4a63c;
  --danger: #c2452f;
  --radius: 16px;
  --radius-sm: 10px;
  --font-ui: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 1px 2px rgba(27, 42, 39, 0.06), 0 8px 24px rgba(27, 42, 39, 0.06);
}

body.role-kid {
  --accent: #6c5ce7;
  --accent-ink: #5647c4;
  --accent-soft: #ece9fc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

button { font-family: var(--font-ui); cursor: pointer; }

.wordmark {
  font-family: var(--font-ui);
  font-weight: 800;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.wordmark .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

/* ---------------- Login page ---------------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-card .wordmark { font-size: 26px; margin-bottom: 4px; }
.login-card .tagline { color: var(--muted); margin: 0 0 24px; font-size: 15px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--ink);
}
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--surface);
  color: var(--ink);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--accent-ink); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.form-error {
  color: var(--danger);
  font-size: 14px;
  min-height: 20px;
  margin-top: 12px;
  font-weight: 600;
}

/* ---------------- Chat layout ---------------- */
.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: 100%;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-head .wordmark { font-size: 20px; }

.new-chat {
  margin: 0 12px 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent-ink); }

.convo-list { flex: 1; overflow-y: auto; padding: 4px 8px; min-height: 0; }
.convo {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; margin-bottom: 2px;
  border: none; background: transparent; border-radius: var(--radius-sm);
  color: var(--ink); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--font-body);
}
.convo:hover { background: var(--surface-2); }
.convo.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; }
.user-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-family: var(--font-ui); font-weight: 800; font-size: 15px;
}
.user-meta { line-height: 1.2; }
.user-meta .name { font-family: var(--font-ui); font-weight: 700; font-size: 14px; }
.role-badge {
  font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent-ink);
}
.foot-controls {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
/* Model names are long, and a flex item won't shrink below its content by
   default — which pushed the Admin / Sign out links out of the sidebar. Give
   the picker its own full-width row and let it shrink. */
.provider-select {
  flex: 1 1 100%; min-width: 0; max-width: 100%;
  padding: 7px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
  font-family: var(--font-body); font-size: 13px; color: var(--ink);
}
.link-btn {
  border: none; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 13px; padding: 7px 8px;
  flex: none; white-space: nowrap;
}
/* Push "Sign out" to the far end of the links row. */
.foot-controls .link-btn:last-child { margin-left: auto; }
.link-btn:hover { color: var(--danger); }

/* ---------------- Main chat ---------------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.messages { flex: 1; overflow-y: auto; padding: 24px 0; min-height: 0; }
.messages-inner { max-width: 720px; margin: 0 auto; padding: 0 20px; }

.msg { display: flex; margin-bottom: 18px; }
.msg .bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 80%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--accent-soft);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg .who {
  font-family: var(--font-ui); font-weight: 800; font-size: 12px;
  color: var(--muted); margin-bottom: 4px;
}

.empty-state {
  text-align: center; color: var(--muted);
  margin-top: 12vh; padding: 0 20px;
}
.empty-state .big {
  font-family: var(--font-ui); font-weight: 800; font-size: 22px;
  color: var(--ink); margin-bottom: 6px;
}

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Composer */
.composer { border-top: 1px solid var(--border); background: var(--surface); }
.composer-inner {
  max-width: 720px; margin: 0 auto; padding: 14px 20px;
  display: flex; gap: 10px; align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; max-height: 180px;
  padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  color: var(--ink);
}
.composer textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.send-btn {
  border: none; border-radius: 50%; width: 44px; height: 44px;
  background: var(--accent); color: #fff; font-size: 18px;
  display: grid; place-items: center; flex: none;
}
.send-btn:hover { background: var(--accent-ink); }
.send-btn:disabled { opacity: 0.5; cursor: default; }

.banner-error {
  max-width: 720px; margin: 0 auto 8px; padding: 0 20px;
  color: var(--danger); font-weight: 600; font-size: 14px;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 30% 0 0; z-index: 20;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-grid !important; }
}
.menu-toggle {
  display: none;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); width: 40px; height: 40px;
  place-items: center; font-size: 18px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Web search toggle in composer (adults with the feature enabled) */
.web-toggle {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  font-family: var(--font-ui); font-weight: 700; font-size: 13px;
  color: var(--muted); cursor: pointer; user-select: none;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; white-space: nowrap;
}
/* The `hidden` attribute must win over the display rule above, otherwise the
   toggle shows for everyone (including kids). */
.web-toggle[hidden] { display: none; }
.web-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.web-toggle:has(input:checked) {
  color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft);
}
/* Blinking cursor while a reply streams in */
.bubble .stream-cursor {
  display: inline-block; width: 7px; height: 1em; margin-left: 1px;
  background: var(--muted); vertical-align: text-bottom; animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* --- Conversation search (sidebar) --- */
.convo-search { padding: 0 12px 8px; }
.convo-search input {
  width: 100%; box-sizing: border-box; padding: 8px 10px;
  font-family: var(--font-ui); font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.convo-search input:focus { outline: none; border-color: var(--accent); }
.convo-empty { padding: 10px 14px; color: var(--muted); font-size: 13px; }
.convo.result { flex-direction: column; align-items: stretch; height: auto; gap: 3px; }
.result-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-snippet {
  font-size: 12px; color: var(--muted); font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* --- Web-search sources (under an assistant reply) --- */
.sources {
  margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.sources-label {
  font-family: var(--font-ui); font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
a.source-link {
  font-size: 13px; color: var(--accent-ink); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
a.source-link:hover { text-decoration: underline; }
a.source-link::before { content: "🔗 "; }

/* --- Chat row with kebab menu --- */
.convo-row { position: relative; display: flex; align-items: stretch; gap: 2px; }
.convo-row .convo { flex: 1 1 auto; min-width: 0; }
.convo-kebab {
  flex: 0 0 auto; width: 30px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: var(--radius);
  font-size: 18px; line-height: 1; opacity: .55;
}
.convo-kebab:hover, .convo-kebab:focus { opacity: 1; background: var(--accent-soft); outline: none; }
.convo-menu {
  position: fixed; z-index: 50; min-width: 160px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
.convo-menu .menu-item {
  display: block; width: 100%; text-align: left; padding: 9px 11px;
  border: none; background: transparent; border-radius: 7px; cursor: pointer;
  font-family: var(--font-ui); font-size: 14px; font-weight: 700; color: var(--ink);
}
.menu-item.danger { color: #c0392b; }
.menu-item.danger:hover { background: #fdecea; }

/* ===== Account modal (shared: chat + admin) ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(30, 32, 38, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
/* The `hidden` attribute must win over the display rule above, or Close (which
   sets hidden=true) has no visible effect. */
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); color: var(--ink);
  width: min(460px, 100%); max-height: 90vh; overflow-y: auto;
  border-radius: 16px; padding: 22px 24px;
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
  font-family: var(--font-ui);
}
.modal h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.modal h3 { margin: 4px 0 12px; font-size: 15px; font-weight: 800; }
.modal hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.acct-signed { color: var(--muted); font-size: 14px; margin: 0; }
.acct-signed strong { color: var(--ink); }
.modal .field { margin-bottom: 12px; }
.modal .field label {
  display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px;
}
.modal .field input {
  width: 100%; box-sizing: border-box; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: var(--font-body); color: var(--ink);
  background: var(--surface);
}
.modal .field input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.acct-msg { display: none; font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.acct-msg.show { display: block; }
.acct-msg.ok { color: var(--accent-ink); }
.acct-msg.err { color: var(--danger); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px;
}
.btn-ghost {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 16px; font-weight: 700;
  font-family: var(--font-ui); font-size: 14px; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }
.modal .btn-primary { width: auto; padding: 9px 18px; }

/* ===== BDO footer (matches other Bossmin Dot Org projects) ===== */
.bdo-footer {
  text-align: center; padding: 22px 16px 26px;
  font-family: var(--font-ui); font-size: 12.5px; color: var(--muted);
}
.bdo-footer strong { color: var(--ink); font-weight: 800; }
.bdo-footer .bdo-rest { white-space: nowrap; }
.bdo-footer .bdo-bar { opacity: .45; margin: 0 3px; }
/* Leave room for the footer under the centered login card. */
.login-wrap { min-height: calc(100vh - 72px); }
