/* ── Fonts ──────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;1,400&family=Inter:wght@300;400;500;600&display=swap');

/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --cream:        #F8F3EC;
  --cream-dark:   #EFE8DC;
  --cream-border: #DDD5C8;
  --pearl:        #FBF8F2;
  --sea-glass:    #7EA7A8;
  --sea-glass-dark:#4F7F82;
  --shell-pink:   #D9A79B;
  --navy:         #1A2B3C;
  --navy-light:   #2C4055;
  --sage:         #6B8B6E;
  --sage-light:   #8FAF92;
  --tan:          #C4A882;
  --tan-light:    #D9C4A8;
  --white:        #FFFFFF;
  --text-primary: #1A2B3C;
  --text-secondary:#5A6A7A;
  --text-muted:   #8A9AAA;
  --shadow-sm:    0 1px 3px rgba(26,43,60,.08);
  --shadow-md:    0 4px 16px rgba(26,43,60,.10);
  --shadow-lg:    0 8px 32px rgba(26,43,60,.12);
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    16px;
  --sidebar-w:    180px;
  --font-serif:   'Playfair Display', Georgia, serif;
  --font-sans:    'Inter', system-ui, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 15px; }
body {
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 18% 10%, rgba(126,167,168,.16), transparent 34%),
    radial-gradient(circle at 86% 92%, rgba(217,167,155,.10), transparent 32%),
    var(--cream);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea { font: inherit; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-shell {
  --shell-header-h: 105px;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
  max-width: 100vw;
  position: relative;
}
body.theme-chat .app-shell::before,
body.theme-chat .app-shell::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  z-index: 50;
  pointer-events: none;
}
body.theme-chat .app-shell::before {
  top: 0;
  height: 3px;
  background: var(--page-accent);
}
body.theme-chat .app-shell::after {
  top: calc(var(--shell-header-h) - 1px);
  height: 1px;
  left: var(--sidebar-w);
  background: var(--cream-border);
}
body.theme-chat .app-shell:has(.chat-home) { --shell-header-h: 132px; }
body.theme-chat .app-shell:has(.chat-thread) { --shell-header-h: 105px; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background:
    linear-gradient(180deg, rgba(251,248,242,.96), rgba(239,232,220,.94)),
    radial-gradient(circle at 50% 10%, rgba(126,167,168,.18), transparent 44%);
  border-right: 1px solid var(--cream-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding: 0;
}

.sidebar-brand {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--cream-border);
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.56), rgba(126,167,168,.08));
}
body.theme-chat .sidebar-brand {
  height: var(--shell-header-h);
  min-height: var(--shell-header-h);
  align-items: center;
  border-bottom: 1px solid var(--cream-border);
}

/* Stacked wordmark (Foster / Chat, Foster / Review, Rafael / RFP) */
.brand-stack {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.brand-foster {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: -.01em;
}
.brand-word {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 1px;
}
.brand-leaf-wrap {
  opacity: 1;
  margin-top: 2px;
  flex-shrink: 0;
}
.brand-owl-wrap {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 4px;
  background:
    radial-gradient(circle at 36% 26%, rgba(255,255,255,.86), transparent 36%),
    linear-gradient(135deg, var(--page-accent, var(--sage)), var(--page-accent-2, var(--sea-glass)));
  box-shadow: 0 2px 8px rgba(26,43,60,.12), inset 0 0 0 1px rgba(255,255,255,.54);
}
.brand-owl-wrap img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255,255,255,.72);
}
.brand-logo-img {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  object-fit: contain;
  display: block;
  box-shadow: 0 6px 18px rgba(26,43,60,.12);
}

/* Sidebar coastal scene */
.sidebar-scene {
  --sidebar-scene-fade: #F3EDE4;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  height: 140px;
  background: var(--sidebar-scene-fade);
}
.sidebar-scene img,
.sidebar-scene svg {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
  object-position: center center;
}
.sidebar-scene::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 76px;
  background: linear-gradient(
    to bottom,
    var(--sidebar-scene-fade) 0%,
    var(--sidebar-scene-fade) 16%,
    rgba(243,237,228,.84) 40%,
    rgba(243,237,228,.42) 70%,
    transparent 100%
  );
  z-index: 1;
  pointer-events: none;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 0;
}

.nav-section-label {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 18px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  border-radius: 0;
  color: var(--text-secondary);
  font-size: .88rem;
  font-weight: 400;
  transition: background .12s, color .12s;
  position: relative;
  cursor: pointer;
}
.nav-item:hover { background: rgba(126,167,168,.12); color: var(--navy); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(126,167,168,.18), rgba(255,255,255,.34));
  color: var(--navy);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 999px 999px 0;
  background: var(--sea-glass-dark);
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .72;
}
.nav-icon.audio-note {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  font-size: .65rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(26,43,60,.08);
  width: 26px;
  height: 26px;
  min-width: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  clip-path: path('M 9.5 8.2 C 9 4 11 1 13 1 C 15 1 17 4 16.5 8.2 C 19 6 24 6 24.4 9.3 C 24.5 12 21 14 18.7 14.9 C 21 16 23 21 20.1 22.7 C 18 24 15 22 13 19 C 11 24 5 24 5.9 22.7 C 4.5 21 5 16 7.3 14.9 C 5 14 1 11 1.6 9.3 C 2 7 6 6 9.5 8.2 Z');
}
.nav-badge.badge-triple {
  font-size: .46rem;
  font-weight: 850;
  line-height: 1;
  transform: scale(1.42);
  transform-origin: center;
  margin-left: 15px;
  letter-spacing: -.045em;
  filter: drop-shadow(0 1px 2px rgba(26,43,60,.08));
}
.nav-badge.badge-overflow {
  font-size: .36rem;
  font-weight: 850;
  line-height: 1;
  transform: scale(1.58);
  transform-origin: center;
  margin-left: 20px;
  letter-spacing: -.075em;
  filter: drop-shadow(0 1px 2px rgba(26,43,60,.10));
}
.nav-badge.attention { color: var(--sage); background: rgba(107,139,110,.12); }
.nav-badge.wrong { color: #C0392B; background: rgba(192,57,43,.1); }
.nav-badge.corrected { color: #E67E22; background: rgba(230,126,34,.1); }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--cream-border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
}
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--tan-light);
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--navy);
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: .82rem; font-weight: 500; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: var(--text-muted); }
.btn-logout {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .82rem;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color .12s;
}
.btn-logout:hover { color: var(--navy); }

/* ── Main area ───────────────────────────────────────────────────────────── */
.main-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--white);
}

/* ── Chat home (dashboard) ───────────────────────────────────────────────── */
.chat-home {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 32px 16px;
  border-bottom: 1px solid var(--cream-border);
  flex-shrink: 0;
  background:
    radial-gradient(circle at 92% 12%, rgba(126,167,168,.14), transparent 30%),
    linear-gradient(180deg, rgba(251,248,242,.82), rgba(255,255,255,.94));
}
body.theme-chat .chat-home-header {
  height: var(--shell-header-h);
  min-height: var(--shell-header-h);
  border-top: 0;
  border-bottom: 0;
  box-sizing: border-box;
}
.chat-home-header-text { flex: 1; }
.chat-home-header h1 {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-home-header h1 .header-ornament {
  color: var(--sage);
  font-size: .85em;
  opacity: .6;
  font-weight: 300;
  font-style: italic;
  font-family: Georgia, serif;
  letter-spacing: .02em;
}
.foster-suite-mark {
  width: 92px;
  height: 92px;
  border-radius: 999px;
  object-fit: cover;
  flex: 0 0 auto;
  margin: -10px 18px -12px 12px;
  background: var(--pearl);
  border: 1px solid rgba(126,167,168,.22);
  box-shadow: 0 10px 28px rgba(26,43,60,.10), inset 0 1px 0 rgba(255,255,255,.8);
}
.docs-suite-mark {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  object-fit: cover;
  flex: 0 0 auto;
  margin-right: 2px;
  transform: scale(1.08);
  filter: drop-shadow(0 8px 18px rgba(26,43,60,.10));
}
.chat-home-header p {
  font-size: .84rem;
  color: var(--text-secondary);
}
.btn-new-thread {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--navy), var(--sea-glass-dark));
  color: var(--white);
  border-radius: 10px;
  font-size: .84rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(26,43,60,.13);
  transition: transform .15s, box-shadow .15s, background .15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-new-thread:hover { background: linear-gradient(135deg, var(--navy-light), var(--sea-glass-dark)); transform: translateY(-1px); box-shadow: 0 10px 22px rgba(26,43,60,.16); }
.btn-new-thread svg { width: 14px; height: 14px; }

/* Info cards in the About Foster panel */
.info-cards { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px 26px; flex: 1; overflow-y: auto; min-height: 0; }
.info-card {
  background:
    linear-gradient(145deg, rgba(255,255,255,.74), rgba(248,243,236,.92));
  border: 1px solid rgba(126,167,168,.22);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: 0 1px 0 rgba(255,255,255,.70) inset;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.info-card:hover { border-color: var(--sea-glass); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.info-card-title {
  font-family: var(--font-serif);
  font-size: .95rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 5px;
}
.info-card-body {
  font-size: .83rem;
  color: var(--text-secondary);
  line-height: 1.56;
}

.chat-home-panels {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow: hidden;
}

.panel {
  border-right: 1px solid var(--cream-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(255,255,255,.72);
}
.panel:last-child { border-right: none; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--cream-border);
  flex-shrink: 0;
}
.panel-icon {
  width: 16px; height: 16px;
  color: var(--text-secondary);
}
.panel-title {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.thread-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid rgba(0,0,0,.04);
}
.thread-item:hover { background: var(--cream); }
.thread-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: .85rem;
  font-weight: 600;
}
.thread-icon.pdf { background: #FCEAEA; color: #C0392B; }
.thread-icon.img { background: #EAF3FC; color: #2C78C0; }
.thread-icon.doc { background: #EAF5EC; color: #27AE60; }
.thread-icon.chat { background: #EAF3F1; color: #4F7F82; }
.thread-icon.default { background: var(--cream-dark); color: var(--text-secondary); }

.thread-info { flex: 1; min-width: 0; }
.thread-title {
  font-size: .85rem;
  font-weight: 500;
  color: var(--navy);
  margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-meta {
  font-size: .75rem;
  color: var(--text-muted);
}
.thread-action {
  font-size: .78rem;
  color: var(--sage);
  font-weight: 500;
  white-space: nowrap;
  align-self: center;
  padding: 3px 10px;
  border: 1px solid var(--sage-light);
  border-radius: 6px;
  transition: background .1s;
}
.thread-action:hover { background: rgba(107,139,110,.1); }

.panel-empty {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}

.panel-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--cream-border);
  flex-shrink: 0;
  background: rgba(255,255,255,.88);
}
.view-all-link {
  font-size: .8rem;
  color: var(--sage);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.view-all-link:hover { color: var(--navy); }

/* ── Chat input bar ──────────────────────────────────────────────────────── */
.chat-input-bar {
  border-top: 1px solid var(--cream-border);
  padding: 14px 24px;
  background: linear-gradient(180deg, rgba(255,255,255,.88), rgba(251,248,242,.96));
  flex-shrink: 0;
}
.chat-input-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: rgba(255,255,255,.84);
  border: 1.5px solid rgba(126,167,168,.28);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.86), 0 4px 14px rgba(26,43,60,.05);
  transition: border-color .15s, box-shadow .15s;
}
.chat-input-inner:focus-within {
  border-color: var(--navy);
}
.chat-input-main { flex: 1; }
.chat-input-main textarea {
  width: 100%;
  background: none;
  border: none;
  resize: none;
  outline: none;
  font-size: .9rem;
  color: var(--navy);
  min-height: 22px;
  max-height: 120px;
  line-height: 1.5;
}
.chat-input-main textarea::placeholder { color: var(--text-muted); }

.chat-input-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.btn-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background .1s, color .1s;
}
.btn-icon:hover { background: var(--cream-dark); color: var(--navy); }
.btn-icon svg { width: 18px; height: 18px; }

.btn-send {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--navy-light); }
.btn-send:active { transform: scale(.94); }
.btn-send svg { width: 16px; height: 16px; }
.btn-send:disabled { background: var(--cream-border); cursor: not-allowed; }

/* ── Chat thread view ────────────────────────────────────────────────────── */
.chat-thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-thread-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--cream-border);
  flex-shrink: 0;
}
body.theme-chat .chat-thread-header {
  height: var(--shell-header-h);
  min-height: var(--shell-header-h);
  border-top: 0;
  border-bottom: 0;
  box-sizing: border-box;
}
.chat-thread-back {
  color: var(--text-secondary);
  font-size: .82rem;
  display: flex; align-items: center; gap: 4px;
  cursor: pointer;
}
.chat-thread-back:hover { color: var(--navy); }
.chat-thread-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--navy);
  flex: 1;
}
.chat-thread-meta {
  font-size: .78rem;
  color: var(--text-muted);
}

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Message bubbles */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg-group.user { align-items: flex-end; }
.msg-group.foster { align-items: flex-start; }

.msg-sender {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  color: var(--text-muted);
  font-weight: 500;
}
.msg-sender .sender-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem;
  font-weight: 700;
}
.foster-avatar-sm {
  background: var(--white);
  color: var(--navy);
  border: 1px solid rgba(26,43,60,.10);
  overflow: hidden;
}
.sender-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-avatar-sm {
  background: var(--tan-light);
  color: var(--navy);
}

.msg-bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: .9rem;
  line-height: 1.55;
  position: relative;
}
.msg-group.user .msg-bubble {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}
.msg-group.foster .msg-bubble {
  background: var(--cream);
  color: var(--text-primary);
  border: 1px solid var(--cream-border);
  border-bottom-left-radius: 4px;
}
.msg-bubble strong {
  font-weight: 800;
  color: var(--navy);
}
.msg-group.user .msg-bubble strong {
  color: var(--white);
}
.msg-bubble code {
  background: rgba(26,43,60,.08);
  color: var(--navy);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .9em;
}
.mcsj-path {
  display: inline;
  color: #123E73;
  font-weight: 800;
  background: rgba(18,62,115,.08);
  border: 1px solid rgba(18,62,115,.12);
  border-radius: 7px;
  padding: 1px 6px 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.msg-bubble.queued, .msg-bubble.processing {
  opacity: .7;
  font-style: italic;
  color: var(--text-muted);
}
.msg-bubble.failed {
  background: #FCEAEA;
  border-color: #F5C6C6;
  color: #C0392B;
}

.msg-time {
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 0 2px;
}

/* Foster source citation */
.msg-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  font-size: .74rem;
  color: var(--text-muted);
  background: var(--cream-dark);
  padding: 3px 9px;
  border-radius: 6px;
}
.msg-source svg { width: 12px; height: 12px; }

/* Feedback buttons */
.msg-feedback {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.feedback-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 500;
  border: 1.5px solid transparent;
  transition: all .12s;
}
.feedback-btn.right {
  border-color: #27AE60;
  color: #27AE60;
  background: rgba(39,174,96,.06);
}
.feedback-btn.right:hover, .feedback-btn.right.active {
  background: #27AE60;
  color: var(--white);
}
.feedback-btn.corrected {
  border-color: #E67E22;
  color: #E67E22;
  background: rgba(230,126,34,.06);
}
.feedback-btn.corrected:hover, .feedback-btn.corrected.active {
  background: #E67E22;
  color: var(--white);
}
.feedback-btn.wrong {
  border-color: #C0392B;
  color: #C0392B;
  background: rgba(192,57,43,.06);
}
.feedback-btn.wrong:hover, .feedback-btn.wrong.active {
  background: #C0392B;
  color: var(--white);
}
.feedback-btn.discussion {
  border-color: var(--text-muted);
  color: var(--text-secondary);
  background: rgba(90,106,122,.06);
}
.feedback-btn.discussion:hover, .feedback-btn.discussion.active {
  background: var(--text-secondary);
  color: var(--white);
}
.feedback-btn svg { width: 13px; height: 13px; }

/* Lightweight answer reactions / threaded notes */
.answer-actions {
  max-width: 72%;
  margin-top: 4px;
  padding: 9px 10px 10px;
  border: 1px solid rgba(126,167,168,.24);
  border-radius: 14px;
  background: rgba(251,248,242,.72);
  box-shadow: 0 1px 4px rgba(26,43,60,.05);
}
.answer-actions-label {
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 7px 2px;
}
.answer-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.answer-chip {
  border: 1.5px solid rgba(126,167,168,.30);
  border-radius: 999px;
  padding: 6px 11px;
  background: var(--white);
  color: var(--navy);
  font-size: .78rem;
  font-weight: 750;
  transition: all .12s;
}
.answer-chip:hover,
.answer-chip.active {
  transform: translateY(-1px);
  box-shadow: 0 3px 9px rgba(26,43,60,.08);
}
.answer-chip.perfect,
.answer-chip.great {
  color: #2F6E45;
  border-color: rgba(47,110,69,.28);
  background: rgba(39,174,96,.07);
}
.answer-chip.perfect.active,
.answer-chip.great.active {
  background: #2F6E45;
  color: var(--white);
}
.answer-chip.tweak {
  color: #8A5A17;
  border-color: rgba(230,126,34,.30);
  background: rgba(230,126,34,.07);
}
.answer-chip.tweak.active {
  background: #A8651B;
  color: var(--white);
}
.answer-chip.followup {
  color: #123E73;
  border-color: rgba(18,62,115,.24);
  background: rgba(18,62,115,.06);
}
.answer-chip.followup.active {
  background: #123E73;
  color: var(--white);
}
.answer-note {
  display: none;
  margin-top: 9px;
}
.answer-note.visible { display: block; }
.answer-note textarea {
  width: 100%;
  min-height: 66px;
  resize: vertical;
  border: 1.5px solid var(--cream-border);
  border-radius: 11px;
  padding: 9px 10px;
  font-size: .84rem;
  font-family: var(--font-sans);
  color: var(--navy);
  background: var(--white);
  outline: none;
}
.answer-note textarea:focus { border-color: #123E73; }
.answer-note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.btn-save-correction.secondary {
  background: #123E73;
}
.btn-save-correction.secondary:hover {
  background: #1B4F8C;
}

/* Correction input */
.correction-form {
  margin-top: 10px;
  max-width: 72%;
  background: var(--white);
  border: 1.5px solid var(--cream-border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: none;
}
.correction-form.visible { display: block; }
.correction-form label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 6px;
}
.correction-form textarea {
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--cream-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .85rem;
  resize: vertical;
  outline: none;
  color: var(--navy);
  background: var(--cream);
}
.correction-form textarea:focus { border-color: var(--navy); }
.correction-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.btn-save-correction {
  background: var(--navy);
  color: var(--white);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: .82rem;
  font-weight: 500;
  transition: background .12s;
}
.btn-save-correction:hover { background: var(--navy-light); }
.btn-cancel-correction {
  color: var(--text-secondary);
  font-size: .82rem;
  padding: 6px 10px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--cream);
  border: 1px solid var(--cream-border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.typing-dot {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-pulse 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typing-pulse {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Attachment chips in message area */
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--cream-dark);
  border: 1px solid var(--cream-border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: .78rem;
  color: var(--text-secondary);
  margin: 4px 4px 0 0;
}
.attachment-chip svg { width: 13px; height: 13px; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 22%, rgba(126,167,168,.22), transparent 34%),
    radial-gradient(circle at 20% 80%, rgba(217,167,155,.12), transparent 30%),
    var(--cream);
  padding: 24px;
}
.login-card {
  background: rgba(255,255,255,.86);
  border: 1px solid rgba(126,167,168,.22);
  border-radius: 24px;
  box-shadow: 0 18px 55px rgba(26,43,60,.14), inset 0 1px 0 rgba(255,255,255,.86);
  padding: 40px 44px;
  width: 100%;
  max-width: 420px;
  backdrop-filter: blur(10px);
}
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-brand .brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.login-brand h1 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--navy);
  margin-bottom: 4px;
}
.login-brand p {
  font-size: .85rem;
  color: var(--text-secondary);
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .03em;
}
.form-group input {
  border: 1.5px solid var(--cream-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  color: var(--navy);
  background: var(--cream);
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus { border-color: var(--navy); background: var(--white); }
.btn-login {
  background: linear-gradient(135deg, var(--navy), var(--sea-glass-dark));
  color: var(--white);
  border-radius: 10px;
  padding: 11px;
  font-size: .92rem;
  font-weight: 600;
  letter-spacing: .02em;
  margin-top: 4px;
  box-shadow: 0 8px 18px rgba(26,43,60,.13);
  transition: transform .15s, box-shadow .15s, background .15s;
  width: 100%;
}
.btn-login:hover { background: linear-gradient(135deg, var(--navy-light), var(--sea-glass-dark)); transform: translateY(-1px); box-shadow: 0 10px 22px rgba(26,43,60,.16); }
.btn-login:disabled { background: var(--cream-border); cursor: not-allowed; }
.login-error {
  background: #FCEAEA;
  border: 1px solid #F5C6C6;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .82rem;
  color: #C0392B;
  display: none;
}
.login-error.visible { display: block; }
.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: .78rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── File upload area ────────────────────────────────────────────────────── */
.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 24px 10px;
}

/* ── Toast notifications ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  background: var(--navy);
  color: var(--white);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: .85rem;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
  max-width: 300px;
}
.toast.success { background: #27AE60; }
.toast.error { background: #C0392B; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Foster board polish ─────────────────────────────────────────────────── */
.eyebrow {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--sage);
  margin-bottom: 5px;
}
.board-header .chat-home-header-text {
  max-width: 760px;
}
.board-header p {
  max-width: 760px;
  line-height: 1.55;
}
.messages-area {
  background:
    linear-gradient(180deg, rgba(251,248,242,.38), rgba(255,255,255,.82)),
    radial-gradient(circle at 96% 8%, rgba(126,167,168,.10), transparent 26%);
}
.msg-group {
  width: 100%;
}
.msg-group.user,
.msg-group.foster {
  align-items: stretch;
}
.msg-group.user .msg-sender {
  justify-content: flex-end;
}
.msg-bubble,
.typing-indicator {
  max-width: min(860px, 92%);
  box-shadow: 0 1px 0 rgba(255,255,255,.70) inset, 0 2px 10px rgba(26,43,60,.04);
}
.msg-group.user .msg-bubble {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  border: 1px solid rgba(26,43,60,.10);
}
.msg-group.foster .msg-bubble,
.msg-group.foster .typing-indicator {
  align-self: flex-start;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(126,167,168,.24);
}
.msg-feedback,
.correction-form {
  margin-left: 32px;
}
.correction-form {
  max-width: min(720px, 92%);
}
.thread-item {
  background: rgba(255,255,255,.36);
}
.thread-item + .thread-item {
  border-top: 1px solid rgba(221,213,200,.64);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.loading-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.text-serif { font-family: var(--font-serif); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cream-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--tan-light); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  .sidebar { display: none; }
  .chat-home-panels { grid-template-columns: 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--cream-border); }
  .msg-bubble { max-width: 88%; }
  .correction-form { max-width: 88%; }
}


/* ── Page color systems + clearer sidebar navigation semantics ───────────── */
:root {
  --page-accent: var(--sea-glass-dark);
  --page-accent-2: var(--sea-glass);
  --page-accent-soft: rgba(126,167,168,.16);
  --page-accent-wash: rgba(126,167,168,.08);
}
body.theme-chat {
  --page-accent: #4F7F82;
  --page-accent-2: #7EA7A8;
  --page-accent-soft: rgba(126,167,168,.20);
  --page-accent-wash: rgba(126,167,168,.10);
}
body.theme-review {
  --page-accent: #6B8B6E;
  --page-accent-2: #8FAF92;
  --page-accent-soft: rgba(107,139,110,.22);
  --page-accent-wash: rgba(107,139,110,.11);
}
body.theme-docs {
  --page-accent: #102D4A;
  --page-accent-2: #1A3D5F;
  --page-accent-soft: rgba(16,45,74,.22);
  --page-accent-wash: rgba(16,45,74,.10);
}
body.theme-chat .sidebar,
body.theme-review .sidebar,
body.theme-docs .sidebar {
  background:
    linear-gradient(180deg, rgba(251,248,242,.97), rgba(239,232,220,.94)),
    radial-gradient(circle at 48% 8%, var(--page-accent-soft), transparent 45%);
}
body.theme-chat .sidebar-brand,
body.theme-review .sidebar-brand,
body.theme-docs .sidebar-brand {
  background:
    linear-gradient(135deg, rgba(255,255,255,.66), var(--page-accent-wash)),
    radial-gradient(circle at 88% 20%, var(--page-accent-soft), transparent 38%);
}
body.theme-chat .brand-word,
body.theme-review .brand-word,
body.theme-docs .brand-word { color: var(--page-accent); }
body.theme-docs .sidebar-brand .brand-word,
body.theme-docs .sidebar-brand .brand-foster { color: #fff; }
body.theme-chat .nav-section-label,
body.theme-review .nav-section-label,
body.theme-docs .nav-section-label {
  color: var(--page-accent);
  font-weight: 850;
  letter-spacing: .095em;
}
body.theme-chat .nav-section-label::before,
body.theme-review .nav-section-label::before,
body.theme-docs .nav-section-label::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 999px;
  background: var(--page-accent-2);
  box-shadow: 0 0 0 3px var(--page-accent-wash);
  vertical-align: 1px;
}
.nav-item.nav-page {
  margin: 3px 10px;
  padding: 9px 11px;
  border-radius: 13px;
  border: 1px solid rgba(26,43,60,.07);
  border-left: 4px solid transparent;
  background: rgba(255,255,255,.45);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.56);
}
.nav-item.nav-page:hover {
  transform: translateX(1px);
  background: var(--page-accent-wash);
  border-left-color: var(--page-accent-2);
}
.nav-item.nav-page.active,
.nav-item.nav-page.nav-primary {
  color: var(--navy);
  font-weight: 850;
  background:
    linear-gradient(90deg, var(--page-accent-soft), rgba(255,255,255,.80)),
    linear-gradient(135deg, rgba(255,255,255,.50), var(--page-accent-wash));
  border-color: rgba(26,43,60,.08);
  border-left-color: var(--page-accent);
  box-shadow: 0 3px 10px rgba(26,43,60,.07), inset 0 1px 0 rgba(255,255,255,.74);
}
.nav-item.nav-page.active::before,
.nav-item.nav-page.nav-primary::before { background: var(--page-accent); }
.nav-item.nav-feature {
  font-size: .83rem;
  padding-top: 8px;
  padding-bottom: 8px;
  border-left: 3px solid transparent;
}
.nav-item.nav-feature:hover { background: var(--page-accent-wash); }
.nav-item.nav-feature.active {
  background: linear-gradient(90deg, rgba(255,255,255,.34), var(--page-accent-wash));
  border-left-color: var(--page-accent-2);
  font-weight: 700;
}
.nav-item.nav-feature.active::before { background: var(--page-accent-2); }
.nav-item.nav-feature .nav-badge,
.nav-item.nav-feature.active .nav-badge {
  color: var(--page-accent);
  background: var(--page-accent-wash);
}
body.theme-docs .review-stats-bar,
body.theme-review .review-stats-bar { border-top: 3px solid var(--page-accent); }
body.theme-chat .board-header { border-top: 0; }

/* Chat home: use the chat blue as the real main-page theme, not just the nav accent. */
body.theme-chat .main-area {
  background:
    radial-gradient(circle at 92% 8%, rgba(79,127,130,.14), transparent 32%),
    linear-gradient(180deg, rgba(247,252,252,.96), rgba(255,255,255,.92) 42%, rgba(234,243,241,.38));
}
body.theme-chat .chat-home { position: relative; }
body.theme-chat .chat-home-header {
  background:
    radial-gradient(circle at 94% 16%, rgba(126,167,168,.20), transparent 32%),
    linear-gradient(180deg, rgba(244,250,250,.98), rgba(255,255,255,.92));
  border-top-color: var(--page-accent);
  border-bottom-color: rgba(79,127,130,.22);
}
body.theme-chat .eyebrow,
body.theme-chat .panel-title,
body.theme-chat .view-all-link { color: var(--page-accent); }
body.theme-chat .chat-home-panels {
  grid-template-columns: 1fr;
  padding: 18px 24px 0;
  gap: 0;
  background:
    linear-gradient(180deg, rgba(234,243,241,.50), rgba(255,255,255,.80));
}
body.theme-chat .chat-home-panels > .panel {
  border: 1px solid rgba(79,127,130,.20);
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(26,43,60,.08);
  background: rgba(255,255,255,.86);
}
body.theme-chat .chat-home-panels > .panel .panel-header {
  background: linear-gradient(90deg, rgba(79,127,130,.10), rgba(255,255,255,.90));
  border-bottom-color: rgba(79,127,130,.18);
}
body.theme-chat .question-history-header {
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.panel-title-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  background: transparent;
  color: var(--page-accent);
  box-shadow: none;
  border-radius: 999px;
  cursor: pointer;
}
.panel-title-button:hover { color: var(--navy); }
.sort-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(79,127,130,.10);
  color: var(--page-accent);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
}
.history-search-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: min(320px, 100%);
  padding: 7px 11px;
  border: 1px solid rgba(79,127,130,.24);
  border-radius: 999px;
  background: rgba(255,255,255,.86);
  color: var(--page-accent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.70);
}
.history-search-pill svg { width: 14px; height: 14px; flex: 0 0 auto; }
.history-search-pill input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--navy);
  font-size: .82rem;
}
.history-search-pill input::placeholder { color: var(--text-muted); }
body.theme-chat .thread-icon.chat { background: rgba(79,127,130,.12); color: var(--page-accent); }
.thread-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: linear-gradient(135deg, rgba(79,127,130,.20), rgba(255,255,255,.88));
  border: 1px solid rgba(79,127,130,.26);
  color: var(--page-accent);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .025em;
  font-variant-numeric: tabular-nums;
}
.thread-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.thread-author { color: var(--text-secondary); }
.thread-status {
  align-self: center;
  flex: 0 0 auto;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(79,127,130,.18);
  background: rgba(79,127,130,.08);
  color: var(--page-accent);
  font-size: .70rem;
  font-weight: 850;
  white-space: nowrap;
}
.thread-status.status-reviewed_right { background: rgba(39,174,96,.11); color: #1E8449; border-color: rgba(39,174,96,.22); }
.thread-status.status-corrected { background: rgba(230,126,34,.10); color: #A55316; border-color: rgba(230,126,34,.20); }
.thread-status.status-wrong,
.thread-status.status-failed { background: rgba(192,57,43,.10); color: #B33A2E; border-color: rgba(192,57,43,.20); }
.thread-status.status-discussion { background: rgba(90,106,122,.10); color: var(--text-secondary); border-color: rgba(90,106,122,.18); }
.thread-status.status-not_answered { background: rgba(138,154,170,.10); color: var(--text-muted); border-color: rgba(138,154,170,.18); }
body.theme-chat .thread-action {
  color: var(--page-accent);
  border-color: rgba(79,127,130,.34);
  background: rgba(255,255,255,.86);
}
body.theme-chat .thread-action:hover { background: rgba(79,127,130,.10); }
body.theme-chat .chat-input-bar {
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(234,243,241,.74));
  border-top-color: rgba(79,127,130,.20);
}
body.theme-chat .chat-input-inner { border-color: rgba(79,127,130,.34); }
body.theme-chat .chat-help-panel { display: none; }
.chat-onboarding {
  position: absolute;
  right: 160px;
  top: 12px;
  z-index: 20;
  width: min(330px, calc(100vw - 240px));
  border: 1px solid rgba(79,127,130,.24);
  border-radius: 18px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 14px 34px rgba(26,43,60,.16);
  padding: 10px;
  max-height: 118px;
  overflow-y: auto;
}
.chat-onboarding.hidden { display: none; }
.chat-onboarding-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--page-accent);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.chat-onboarding-close {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(79,127,130,.08);
  color: var(--page-accent);
  font-size: 1rem;
  line-height: 1;
}
.chat-tip-bubble {
  border: 1px solid rgba(79,127,130,.16);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(234,243,241,.86), rgba(255,255,255,.96));
  padding: 9px 11px;
  color: var(--text-secondary);
  font-size: .82rem;
  line-height: 1.38;
}
.chat-tip-bubble + .chat-tip-bubble { margin-top: 8px; }
.chat-tip-bubble strong {
  display: block;
  margin-bottom: 2px;
  color: var(--navy);
  font-family: var(--font-serif);
  font-size: .94rem;
}

.nav-item.nav-callout {
  background: linear-gradient(90deg, var(--page-accent-soft), rgba(255,255,255,.55));
  border-left-color: var(--page-accent);
  font-weight: 800;
}
.nav-item.nav-callout::after {
  content: 'open';
  margin-left: auto;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: .56rem;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: #fff;
  background: var(--page-accent);
}
.nav-item.nav-callout .nav-badge { margin-left: 4px; }
