:root {
  --blue: #27aae1;
  --blue-dark: #1c86b4;
  --blue-tint: #eaf6fc;
  --gray: #adafb2;
  --gray-line: #e2e3e4;
  --ink: #231f20;
  --muted: #6b6e70;
  --paper: #fbfbfb;
  --paper-raised: #ffffff;
  --radius: 8px;
  --font: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, ui-sans-serif, sans-serif;
  --shadow: 0 1px 2px rgba(20,30,33,.06), 0 6px 20px rgba(20,30,33,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 880px;
  margin: 0 auto;
  background: var(--paper);
}

/* ---- Header ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .85rem 1.1rem;
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 5;
}
.topbar .logo { height: 30px; width: auto; display: block; }
.topbar .titles { line-height: 1.15; }
.topbar .titles .t { font-weight: 600; font-size: 1.02rem; }
.topbar .titles .s { font-size: .72rem; opacity: .85; letter-spacing: .02em; }
.topbar .spacer { flex: 1; }
.topbar button.icon {
  background: rgba(255,255,255,.14);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .45rem .7rem;
  font-size: .8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.topbar button.icon:hover { background: rgba(255,255,255,.28); }
.topbar button.icon.active { background: #fff; color: var(--blue-dark); }

/* ---- Mode strip ---- */
.modebar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem 1.1rem;
  font-size: .74rem;
  color: var(--muted);
  background: var(--paper-raised);
  border-bottom: 1px solid var(--gray-line);
}
.modebar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); }
.modebar.ai .dot { background: #2bb673; }

/* ---- Chat area ---- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
.msg { display: flex; gap: .65rem; max-width: 100%; }
.msg .avatar {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: .8rem; font-weight: 600;
}
.msg.bot .avatar { background: var(--blue-tint); color: var(--blue-dark); }
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--ink); color: #fff; }
.bubble {
  padding: .7rem .9rem;
  border-radius: var(--radius);
  font-size: .92rem;
  line-height: 1.5;
  box-shadow: var(--shadow);
  max-width: 78%;
}
.msg.bot .bubble { background: var(--paper-raised); border: 1px solid var(--gray-line); border-top-left-radius: 2px; }
.msg.user .bubble { background: var(--blue); color: #fff; border-top-right-radius: 2px; }
.bubble p { margin: 0 0 .55rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: .3rem 0 .55rem; padding-left: 1.1rem; }
.bubble li { margin: .15rem 0; }
.bubble h4 { margin: .2rem 0 .35rem; font-size: .9rem; color: var(--blue-dark); }
.bubble strong { font-weight: 600; }

/* embedded media in answers */
.bubble figure.media { margin: .55rem 0; }
.bubble figure.media img,
.bubble figure.media video {
  display: block; max-width: 100%; height: auto;
  border: 1px solid var(--gray-line); border-radius: 8px;
}
.bubble figure.media figcaption { font-size: .76rem; color: var(--muted); margin-top: .3rem; }
.bubble .video-embed { position: relative; padding-top: 56.25%; }  /* 16:9 */
.bubble .video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 8px; }
.bubble img.inline-media { max-width: 100%; height: auto; vertical-align: middle; border-radius: 6px; margin: 0 .15rem; }
.bubble figure.media img, .bubble img.inline-media { cursor: zoom-in; }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20,30,33,.88);
  padding: 3vmin; cursor: zoom-out;
  animation: lb-fade .12s ease-out;
}
.lightbox[hidden] { display: none; }
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
.lightbox .lb-figure { margin: 0; max-width: 96%; max-height: 92%; text-align: center; }
.lightbox img {
  display: block; max-width: 100%; max-height: 85vh; height: auto;
  margin: 0 auto; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
  cursor: default;
}
.lightbox .lb-cap { color: #eaf6fc; font-size: .85rem; margin-top: .7rem; }
.lightbox .lb-cap:empty { display: none; }
.lightbox .lb-close {
  position: absolute; top: 14px; right: 18px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff; border: none;
  font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255,255,255,.3); }

/* sources */
.sources { margin-top: .55rem; padding-top: .5rem; border-top: 1px dashed var(--gray-line); }
.sources .lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .3rem; }
.sources a {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .78rem;
  color: var(--blue-dark);
  text-decoration: none;
  background: var(--blue-tint);
  border: 1px solid #cdeaf6;
  border-radius: 999px;
  padding: .2rem .6rem;
  margin: .15rem .3rem .15rem 0;
}
.sources a:hover { background: #dff1fb; }

/* category tag + related questions */
.cat-tag {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .76rem;
  color: var(--blue-dark);
  background: var(--blue-tint);
  border: 1px solid #cdeaf6;
  border-radius: 999px;
  padding: .2rem .6rem;
  margin: .15rem .3rem .15rem 0;
}
.related { margin-top: .55rem; padding-top: .5rem; border-top: 1px dashed var(--gray-line); }
.related .lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .35rem; }
.related .chips { margin-top: 0; }
.related .chip { font-size: .78rem; padding: .3rem .65rem; text-align: left; }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--gray); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* grouped starter suggestions (collapsible) */
.starter-group { margin-top: .45rem; }
.starter-group .starter-cat {
  display: inline-flex; align-items: center; gap: .45rem;
  font-family: inherit;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--blue-dark); font-weight: 600;
  background: var(--blue-tint); border: 1px solid #cdeaf6;
  border-radius: 999px; padding: .34rem .8rem;
  cursor: pointer; transition: background .15s;
}
.starter-group .starter-cat:hover { background: #dff1fb; }
.starter-group .starter-cat::before {
  content: "\25B8"; font-size: .7rem; line-height: 1;
  transition: transform .15s;
}
.starter-group .starter-cat[aria-expanded="true"]::before { transform: rotate(90deg); }
.starter-group .starter-cat .cnt {
  font-weight: 600; color: #fff; background: var(--blue);
  border-radius: 999px; font-size: .64rem;
  min-width: 1.15em; text-align: center; padding: 0 .3em; line-height: 1.4;
}
.starter-group .chips { margin: .4rem 0 .1rem; }
.starter-group .chips[hidden] { display: none; }

/* suggestion chips */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }
.chip {
  font-family: inherit;
  font-size: .8rem;
  color: var(--blue-dark);
  background: var(--paper-raised);
  border: 1px solid var(--gray-line);
  border-radius: 999px;
  padding: .38rem .75rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--blue); background: var(--blue-tint); }

/* ---- Composer ---- */
.composer {
  display: flex;
  gap: .6rem;
  padding: .8rem 1.1rem;
  border-top: 1px solid var(--gray-line);
  background: var(--paper-raised);
}
.composer textarea {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: .92rem;
  line-height: 1.4;
  padding: .6rem .75rem;
  border: 1px solid var(--gray-line);
  border-radius: 10px;
  max-height: 140px;
  outline: none;
}
.composer textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(39,170,225,.15); }
.composer button.send {
  flex: none;
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: .62rem 1.1rem;
  font-family: inherit;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s;
}
.composer button.send:hover { background: var(--blue-dark); }
.composer button.send:disabled { background: var(--gray); cursor: default; }
.composer button.mic {
  flex: none;
  align-self: flex-end;
  background: var(--paper-raised);
  color: var(--blue-dark);
  border: 1px solid var(--gray-line);
  border-radius: 10px;
  padding: .55rem .7rem;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.composer button.mic:hover { border-color: var(--blue); background: var(--blue-tint); }
.composer button.mic.listening {
  background: #e74c3c; color: #fff; border-color: #e74c3c;
  animation: mic-pulse 1.2s infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,.5); }
  50% { box-shadow: 0 0 0 7px rgba(231,76,60,0); }
}

/* ---- Settings dialog ---- */
dialog.settings {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 460px;
  width: 92%;
  box-shadow: 0 12px 48px rgba(20,30,33,.28);
}
dialog.settings::backdrop { background: rgba(20,30,33,.45); }
.settings .head { padding: 1rem 1.2rem; border-bottom: 1px solid var(--gray-line); font-weight: 600; }
.settings .body { padding: 1.1rem 1.2rem; font-size: .88rem; line-height: 1.5; }
.settings label { display: block; font-weight: 600; font-size: .8rem; margin: .8rem 0 .3rem; }
.settings input, .settings select {
  width: 100%;
  font-family: inherit;
  font-size: .88rem;
  padding: .5rem .6rem;
  border: 1px solid var(--gray-line);
  border-radius: 8px;
  outline: none;
}
.settings input:focus, .settings select:focus { border-color: var(--blue); }
.settings .hint { font-size: .76rem; color: var(--muted); margin-top: .3rem; }
.settings hr.sep { border: none; border-top: 1px solid var(--gray-line); margin: 1.1rem 0 .2rem; }
.settings input[type="range"] { width: 100%; accent-color: var(--blue); padding: 0; }
.settings .ghost-btn {
  margin-top: .8rem;
  font-family: inherit; font-size: .82rem; font-weight: 600;
  color: var(--blue-dark); background: var(--blue-tint);
  border: 1px solid #cdeaf6; border-radius: 8px;
  padding: .45rem .8rem; cursor: pointer;
}
.settings .ghost-btn:hover { background: #dff1fb; }
.settings .foot { padding: .9rem 1.2rem; border-top: 1px solid var(--gray-line); display: flex; justify-content: flex-end; gap: .5rem; }
.settings .foot button {
  font-family: inherit; font-size: .86rem; font-weight: 600;
  border-radius: 8px; padding: .5rem .95rem; cursor: pointer; border: 1px solid var(--gray-line); background: #fff;
}
.settings .foot button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.settings .foot button.primary:hover { background: var(--blue-dark); }

.err { color: #b4231f; font-size: .8rem; }

@media (max-width: 640px) {
  .bubble { max-width: 88%; }
}
