/* =============================================================
   SiteBrain AI – Stylesheet  v2.7
   Changes vs v2.6: Borderless search pill + elevated story cards.
============================================================= */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --sb-bg:        #f9f7f4;
  --sb-surface:   #ffffff;
  --sb-sidebar:   #f2efe9;
  --sb-border:    #e4e0d8;
  --sb-ink:       #141210;
  --sb-muted:     #7a756c;
  --sb-accent:    #c6c6c6;
  --sb-accent-h:  #c6c6c6;
  --sb-user-bg:   #edeae3;
  --sb-radius:    10px;
  --sb-shadow:    0 24px 64px rgba(0,0,0,.14), 0 4px 12px rgba(0,0,0,.06);
  --sb-font-body: "DM Sans", sans-serif;
  --sb-font-disp: "DM Serif Display", serif;
  --sb-content-width: 700px;
}

#sitebrain-ai-button {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--sb-ink);
  color: #fff;
  border: none;
  padding: 13px 22px;
  font-family: var(--sb-font-body);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .02em;
  border-radius: 40px;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  transition: background .18s ease, transform .14s ease, box-shadow .18s ease;
}

#sitebrain-ai-button:hover {
  background: #2a2520;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
}

/* ── Header AI button (injected next to the theme's search icon) ── */

#sitebrain-ai-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0 10px 0 0;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--sb-accent);
  cursor: pointer;
  vertical-align: middle;
  transition: color .16s ease, background .16s ease, transform .14s ease;
  -webkit-tap-highlight-color: transparent;
}

#sitebrain-ai-header-btn svg,
#sitebrain-ai-header-btn img {
  width: 22px;
  height: 22px;
  display: block;
  transition: transform .3s ease;
}

#sitebrain-ai-header-btn:hover {
  color: var(--sb-accent-h);
  background: color-mix(in srgb, var(--sb-accent) 10%, transparent);
}

#sitebrain-ai-header-btn:hover svg,
#sitebrain-ai-header-btn:hover img {
  transform: rotate(15deg) scale(1.08);
}

#sitebrain-ai-header-btn:focus-visible {
  outline: 2px solid var(--sb-accent);
  outline-offset: 2px;
}

#sitebrain-ai-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  z-index: 99999;
  background: #ffffff;
  animation: sb-backdrop-in .2s ease;
}

@keyframes sb-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#ai-panel {
  display: flex;
  width: 100%;
  height: 100%;
  background: var(--sb-surface);
  overflow: hidden;
  animation: sb-panel-in .22s cubic-bezier(.22,.68,0,1.2);
  font-family: var(--sb-font-body);
  color: var(--sb-ink);
}

@keyframes sb-panel-in {
  from { opacity: 0; transform: scale(.97) translateY(10px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* ── Sidebar ────────────────────────────────────────────────── */

#ai-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sb-sidebar);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  min-height: 0;
  overflow: hidden;
}

.ai-sidebar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--sb-border);
  min-width: 0;
  flex-shrink: 0;
}

.ai-sidebar-logo img {
  width: 100%;
  height: auto;
  max-height: 48px;
  border-radius: 0;
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
}

#ai-new-chat {
  width: 100%;
  padding: 11px 14px;
  background: var(--sb-ink);
  color: #fff;
  border: none;
  border-radius: var(--sb-radius);
  font-family: var(--sb-font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 20px;
  letter-spacing: .02em;
  transition: background .16s ease;
  flex-shrink: 0;
}

#ai-new-chat:hover { background: #2a2520; }

.ai-sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--sb-muted);
  margin-bottom: 10px;
  flex-shrink: 0;
}

#ai-chat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

#ai-chat-list::-webkit-scrollbar { width: 4px; }
#ai-chat-list::-webkit-scrollbar-thumb { background: var(--sb-border); border-radius: 4px; }

.ai-chat-item {
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 400;
  color: var(--sb-ink);
  cursor: pointer;
  transition: background .13s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.ai-chat-item:hover { background: var(--sb-border); }

.ai-chat-item.active {
  background: var(--sb-border);
  font-weight: 500;
}

/* ── Main area ──────────────────────────────────────────────── */

#ai-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background: var(--sb-surface);
}

.ai-close {
  position: absolute;
  top: 14px;
  right: 18px;
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--sb-muted);
  cursor: pointer;
  z-index: 10;
  pointer-events: all;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color .14s, background .14s;
}
.ai-close:hover {
  color: var(--sb-ink);
  background: var(--sb-bg);
}

/* ── Start screen ───────────────────────────────────────────── */

#ai-start {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 52px 48px 36px;
  overflow-y: auto;
  min-height: 0;
}

#ai-start::-webkit-scrollbar { width: 4px; }
#ai-start::-webkit-scrollbar-thumb { background: var(--sb-border); border-radius: 4px; }

.ai-start-hero { text-align: center; margin-bottom: 28px; }

.ai-start-hero h2 {
  font-family: var(--sb-font-disp);
  font-size: 38px;
  font-weight: 400;
  color: var(--sb-ink);
  margin: 0 0 6px;
  line-height: 1.15;
  letter-spacing: -.01em;
}

.ai-start-hero p {
  font-size: 14.5px;
  color: var(--sb-muted);
  margin: 0;
  letter-spacing: .01em;
}

.ai-search-bar-wrap {
  width: 100%;
  max-width: var(--sb-content-width);
  margin-bottom: 40px;
}

.ai-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--sb-bg);
  border: none;
  border-radius: 50px;
  padding: 7px 9px 7px 20px;
  transition: background .18s ease, box-shadow .18s ease;
}

.ai-search-bar:focus-within {
  background: #fff;
  box-shadow:
    0 1px 3px rgba(20, 18, 16, .06),
    0 10px 30px rgba(20, 18, 16, .10);
}

.ai-search-icon { width: 18px; height: 18px; color: var(--sb-muted); flex-shrink: 0; transition: color .16s; }
.ai-search-bar:focus-within .ai-search-icon { color: var(--sb-accent); }

.ai-search-bar input {
Border:0!important;
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--sb-font-body);
  font-size: 15.5px;
  color: var(--sb-ink);
  outline: none;
  padding: 9px 0;
  min-width: 0;
}

.ai-search-bar input::placeholder { color: var(--sb-muted); }

.ai-search-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--sb-border);
  color: var(--sb-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .12s ease;
}

.ai-search-send svg { width: 17px; height: 17px; }

.ai-search-send.active,
.ai-search-bar:focus-within .ai-search-send {
  background: var(--sb-accent);
  color: #fff;
}

.ai-search-send:hover.active,
.ai-search-bar:focus-within .ai-search-send:hover {
  background: var(--sb-accent-h);
  transform: scale(1.06);
}

.ai-hint {
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--sb-muted);
  letter-spacing: .03em;
  text-align: center;
}

/* ── Top Stories ───────────────────────────────────────────── */

.ai-top-stories {
  width: 100%;
  max-width: var(--sb-content-width);
  animation: sb-msg-in .3s ease;
}

.ai-top-stories-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.ai-stories-divider-line { flex: 1; height: 1px; background: var(--sb-border); }

.ai-stories-divider-text {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--sb-muted);
  white-space: nowrap;
}

.ai-stories-grid { display: flex; flex-direction: column; gap: 14px; }

.ai-story-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px 14px 14px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .18s ease;
  background: #fff;
  text-decoration: none;
  color: var(--sb-ink);
  box-shadow:
    0 1px 2px rgba(20, 18, 16, .05),
    0 6px 20px rgba(20, 18, 16, .07);
}

.ai-story-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 2px 5px rgba(20, 18, 16, .06),
    0 14px 36px rgba(20, 18, 16, .12);
}

.ai-story-card:hover .ai-story-arrow { color: var(--sb-accent); transform: translateX(3px); }

.ai-story-thumb {
  width: 88px;
  height: 72px;
  border-radius: 11px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--sb-bg);
}

.ai-story-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ai-story-thumb--empty { display: flex; align-items: center; justify-content: center; color: var(--sb-border); }
.ai-story-thumb--empty svg { width: 26px; height: 26px; }

.ai-story-body { flex: 1; min-width: 0; }

.ai-story-title {
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--sb-ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-story-excerpt {
  font-size: 12px;
  color: var(--sb-muted);
  margin-top: 3px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-story-arrow { flex-shrink: 0; color: var(--sb-border); transition: color .16s ease, transform .16s ease; }
.ai-story-arrow svg { width: 16px; height: 16px; display: block; }

.ai-story-card--skeleton { pointer-events: none; cursor: default; }

.ai-skeleton-block {
  background: linear-gradient(90deg, var(--sb-bg) 25%, var(--sb-border) 50%, var(--sb-bg) 75%);
  background-size: 200% 100%;
  animation: sb-shimmer 1.4s infinite;
}

.ai-skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--sb-bg) 25%, var(--sb-border) 50%, var(--sb-bg) 75%);
  background-size: 200% 100%;
  animation: sb-shimmer 1.4s infinite;
}

@keyframes sb-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Chat screen ────────────────────────────────────────────── */

#ai-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: var(--sb-surface);
}

.ai-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--sb-border);
  padding: 0 max(28px, calc(50% - var(--sb-content-width) / 2));
  flex-shrink: 0;
  background: var(--sb-surface);
}

.ai-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--sb-font-body);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sb-muted);
  cursor: pointer;
  padding: 14px 16px 12px;
  margin-bottom: -1px;
  letter-spacing: .01em;
  transition: color .14s ease, border-color .14s ease;
}

.ai-tab:hover { color: var(--sb-ink); }
.ai-tab.active { color: var(--sb-accent); border-bottom-color: var(--sb-accent); }

.ai-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--sb-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  border-radius: 20px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: middle;
}

#ai-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 32px max(28px, calc(50% - var(--sb-content-width) / 2)) 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: #ffffff !important;
  isolation: isolate;
}

#ai-results::-webkit-scrollbar { width: 4px; }
#ai-results::-webkit-scrollbar-thumb { background: var(--sb-border); border-radius: 4px; }

/* ── Messages ────────────────────────────────────────────── */

.ai-msg-row {
  display: flex;
  margin-bottom: 10px;
}

.ai-msg-row.user      { justify-content: flex-end; }
.ai-msg-row.assistant { justify-content: flex-start; }

.ai-msg-user {
  background: var(--sb-user-bg);
  color: var(--sb-ink);
  padding: 12px 16px;
  border-radius: 12px 12px 2px 12px;
  max-width: 80%;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  animation: sb-msg-in .2s ease;
}

.ai-msg-assistant {
  max-width: 100%;
  font-size: 15px;
  line-height: 1.75;
  color: var(--sb-ink);
  animation: sb-msg-in .2s ease;
  background: var(--sb-surface);
}

.ai-msg-html {
  line-height: 1.75;
  color: var(--sb-ink);
  background: #ffffff;
}

@keyframes sb-msg-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-msg-html p,
.ai-msg-html .sb-p {
  margin: 0 0 .85em;
  line-height: 1.75;
  font-size: 15px;
}

.ai-msg-html p:last-child,
.ai-msg-html .sb-p:last-child { margin-bottom: 0; }

.ai-msg-html .sb-gap { height: .5em; }

.ai-msg-html ol, .ai-msg-html .sb-ol {
  margin: .4em 0 1em;
  padding-left: 0;
  list-style: none;
  counter-reset: sb-counter;
  display: block;
}

.ai-msg-html ol li, .ai-msg-html .sb-ol li {
  counter-increment: sb-counter;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: baseline;
  font-size: 15px;
  line-height: 1.7;
  color: var(--sb-ink);
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  margin-bottom: .6em;
}

.ai-msg-html ol li::before, .ai-msg-html .sb-ol li::before {
  content: counter(sb-counter) ".";
  color: var(--sb-muted);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--sb-font-body);
  text-align: right;
}

.ai-msg-html ul, .ai-msg-html .sb-ul {
  margin: .5em 0 1em;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-msg-html ul li, .ai-msg-html .sb-ul li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 15px;
  line-height: 1.65;
  color: var(--sb-ink);
}

.ai-msg-html ul li::before, .ai-msg-html .sb-ul li::before {
  content: "–";
  color: var(--sb-accent);
  font-weight: 700;
  flex-shrink: 0;
}

.ai-msg-html strong { font-weight: 600; color: var(--sb-ink); }
.ai-msg-html em     { font-style: italic; color: var(--sb-muted); }
.ai-msg-html code {
  font-family: "SF Mono", "Fira Mono", monospace;
  font-size: 13px;
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--sb-accent);
}

.ai-msg-html .sb-h3 {
  font-family: var(--sb-font-disp);
  font-size: 17px;
  font-weight: 400;
  color: var(--sb-ink);
  margin: .75em 0 .4em;
}

.ai-msg-html .sb-h4 {
  font-family: var(--sb-font-body);
  font-size: 13px;
  font-weight: 700;
  color: var(--sb-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: .75em 0 .4em;
}

/* ── Bold lead-in links (clickable article titles) ─────────── */

.ai-msg-html a.sb-bold-link {
  color: var(--sb-ink);
  text-decoration: none;
  border-bottom: 1.5px solid var(--sb-accent);
  transition: color .14s ease, border-color .14s ease;
}

.ai-msg-html a.sb-bold-link:hover {
  color: var(--sb-accent);
}

.ai-msg-html a.sb-bold-link strong {
  font-weight: 600;
  color: inherit;
}

/* ── Answer cards (thumbnail + linked title in Answer tab) ─── */

.ai-answer-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 1em;
}

.ai-answer-card:last-child { margin-bottom: 0; }

.ai-answer-thumb {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--sb-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: opacity .16s ease, transform .14s ease;
}

.ai-answer-thumb:hover {
  opacity: 0.85;
  transform: scale(1.03);
}

.ai-answer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ai-answer-thumb--empty {
  color: var(--sb-border);
}

.ai-answer-thumb--empty svg {
  width: 28px;
  height: 28px;
}

.ai-answer-card-body {
  flex: 1;
  min-width: 0;
}

.ai-answer-card-body p {
  margin: 0;
  line-height: 1.75;
  font-size: 15px;
}

.ai-answer-card-body strong a {
  color: var(--sb-ink);
  text-decoration: none;
  border-bottom: 1.5px solid var(--sb-accent);
  transition: color .14s ease, border-color .14s ease;
}

.ai-answer-card-body strong a:hover {
  color: var(--sb-accent);
}

sup.sb-cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  background: var(--sb-accent);
  color: #fff;
  font-size: 8px;
  font-weight: 700;
  font-style: normal;
  border-radius: 50%;
  vertical-align: super;
  line-height: 1;
  margin-left: 2px;
  flex-shrink: 0;
  font-family: var(--sb-font-body);
}

.ai-msg-html .sb-sources,
p.sb-sources {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--sb-muted);
  border-top: 1px solid var(--sb-border);
  padding-top: 10px;
}

.ai-msg-html .sb-sources a,
p.sb-sources a.sb-source-link {
  color: var(--sb-accent);
  text-decoration: none;
  margin-right: 8px;
}

.ai-msg-html .sb-sources a:hover,
p.sb-sources a.sb-source-link:hover { text-decoration: underline; }

/* ── Typing indicator ───────────────────────────────────── */

.ai-typing { display: flex; gap: 5px; align-items: center; padding: 6px 0; }
.ai-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--sb-muted);
  display: inline-block;
  animation: sb-dot 1.1s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .18s; }
.ai-typing span:nth-child(3) { animation-delay: .36s; }

@keyframes sb-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Links grid ────────────────────────────────────────── */

.ai-link-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding-top: 6px;
}

.ai-link-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--sb-ink);
  background: #fff;
  border: 1px solid var(--sb-border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color .16s ease, transform .14s ease, box-shadow .16s ease;
}

.ai-link-card:hover {
  border-color: var(--sb-accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--sb-accent) 14%, transparent);
}

.ai-link-thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  background: var(--sb-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-link-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ai-link-thumb--empty { color: var(--sb-border); }
.ai-link-thumb--empty svg { width: 40px; height: 40px; }

.ai-link-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.ai-link-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--sb-ink);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-link-domain {
  font-size: 11.5px;
  color: var(--sb-muted);
  letter-spacing: .02em;
  margin-top: auto;
  padding-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-link-card--loading { pointer-events: none; }

/* ── Images grid ──────────────────────────────────────── */

.ai-images-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding-top: 4px;
}

.ai-image-thumb-btn {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0;
  border: 1px solid var(--sb-border);
  border-radius: 8px;
  background: var(--sb-bg);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .16s ease, transform .14s ease, box-shadow .16s ease;
  display: block;
}

.ai-image-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .3s ease;
}

.ai-image-thumb-btn:hover {
  border-color: var(--sb-accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--sb-accent) 14%, transparent);
}

.ai-image-thumb-btn:hover img { transform: scale(1.04); }

.ai-image-thumb-btn:focus-visible {
  outline: 2px solid var(--sb-accent);
  outline-offset: 2px;
}

/* Legacy .ai-images-grid > img rule kept for backwards compat */
.ai-images-grid > img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--sb-border);
}

/* ── Lightbox ───────────────────────────────────────── */

.ai-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 72px 72px;
  animation: sb-lightbox-in .18s ease;
}

@keyframes sb-lightbox-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.ai-lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  border: none;
  font-size: 28px;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
  z-index: 2;
}

.ai-lightbox-close:hover {
  background: rgba(255, 255, 255, .18);
  transform: scale(1.06);
}

.ai-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  border: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .15s ease;
  z-index: 2;
}

.ai-lightbox-nav svg { width: 22px; height: 22px; }

.ai-lightbox-nav:hover {
  background: rgba(255, 255, 255, .18);
}

.ai-lightbox-prev { left: 22px; }
.ai-lightbox-next { right: 22px; }

.ai-lightbox-figure {
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: sb-lightbox-fig-in .22s ease;
}

@keyframes sb-lightbox-fig-in {
  from { opacity: 0; transform: scale(.98); }
  to   { opacity: 1; transform: scale(1); }
}

.ai-lightbox-img {
  max-width: min(90vw, 1400px);
  max-height: calc(100vh - 200px);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  display: block;
}

.ai-lightbox-caption {
  color: rgba(255,255,255,.92);
  font-family: var(--sb-font-body);
  font-size: 13.5px;
  text-align: center;
  max-width: min(90vw, 800px);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-lightbox-cap-text {
  color: #fff;
  font-size: 14px;
}

.ai-lightbox-cap-source a {
  color: rgba(255,255,255,.7);
  font-size: 12.5px;
  text-decoration: none;
  transition: color .15s ease;
}

.ai-lightbox-cap-source a:hover { color: #fff; }

.ai-lightbox-cap-counter {
  color: rgba(255,255,255,.5);
  font-size: 11.5px;
  letter-spacing: .04em;
  margin-top: 4px;
}

/* ── Follow-up suggestion chips ──────────────────────────── */

.sb-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.sb-followup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 9px 14px;
  font-family: var(--sb-font-body);
  font-size: 13.5px;
  line-height: 1.4;
  text-align: left;
  color: var(--sb-accent);
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .14s ease, background .14s ease, color .14s ease;
}

.sb-followup:hover {
  border-color: var(--sb-accent);
  background: color-mix(in srgb, var(--sb-accent) 7%, var(--sb-surface));
}

.sb-followup:focus-visible {
  outline: none;
  border-color: var(--sb-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sb-accent) 12%, transparent);
}

.sb-followup-text { min-width: 0; }

.sb-followup-arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: .7;
}

.sb-followup:hover .sb-followup-arrow { opacity: 1; }

.sb-followup:disabled {
  opacity: .5;
  cursor: default;
}

.sb-followup:disabled:hover {
  border-color: var(--sb-border);
  background: var(--sb-bg);
}

/* Start-screen example questions: same chip, centred under the search bar. */

.ai-examples {
  justify-content: center;
  margin-top: 20px;
}

/* ── First-run coach mark ─────────────────────────────────── */

.sb-coachmark {
  position: fixed;
  z-index: 999998;
  width: 268px;
  max-width: calc(100vw - 24px);
  padding: 16px 18px 14px;
  background: var(--sb-surface, #fff);
  border: 1px solid var(--sb-border);
  border-radius: 12px;
  box-shadow: 0 6px 28px rgba(20, 18, 16, .16);
  font-family: var(--sb-font-body);
  color: var(--sb-ink);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .18s ease, transform .18s ease;
}

.sb-coachmark.is-visible { opacity: 1; transform: translateY(0); }

.sb-coachmark::before {
  content: "";
  position: absolute;
  top: -6px;
  left: var(--sb-cm-arrow, 50%);
  width: 11px;
  height: 11px;
  margin-left: -5.5px;
  background: var(--sb-surface, #fff);
  border-left: 1px solid var(--sb-border);
  border-top: 1px solid var(--sb-border);
  transform: rotate(45deg);
}

.sb-coachmark--above { transform: translateY(4px); }
.sb-coachmark--above.is-visible { transform: translateY(0); }

.sb-coachmark--above::before {
  top: auto;
  bottom: -6px;
  border-left: none;
  border-top: none;
  border-right: 1px solid var(--sb-border);
  border-bottom: 1px solid var(--sb-border);
}

.sb-coachmark-title {
  font-family: var(--sb-font-disp, var(--sb-font-body));
  font-size: 16px;
  line-height: 1.3;
  margin: 0 0 6px;
  padding-right: 18px;
}

.sb-coachmark-body {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--sb-muted);
}

.sb-coachmark-actions { margin-top: 12px; }

.sb-coachmark-try {
  font-family: var(--sb-font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  color: #fff;
  background: var(--sb-accent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: opacity .14s ease;
}

.sb-coachmark-try:hover { opacity: .88; }

.sb-coachmark-try:focus-visible,
.sb-coachmark-close:focus-visible {
  outline: 2px solid var(--sb-accent);
  outline-offset: 2px;
}

.sb-coachmark-close {
  position: absolute;
  top: 6px;
  right: 8px;
  padding: 2px 6px;
  font-size: 19px;
  line-height: 1;
  color: var(--sb-muted);
  background: none;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: color .14s ease;
}

.sb-coachmark-close:hover { color: var(--sb-ink); }

@media (prefers-reduced-motion: reduce) {
  .sb-coachmark { transition: none; transform: none; }
  .sb-coachmark.is-visible { transform: none; }
}

/* ── Empty state ──────────────────────────────────────── */

.ai-empty { color: var(--sb-muted); font-size: 14px; text-align: center; margin-top: 40px; }

/* ── Follow-up bar ──────────────────────────────────────── */

#ai-input-bar {
  border-bottom: 1px solid var(--sb-border);
  padding: 16px max(28px, calc(50% - var(--sb-content-width) / 2));
  /* Clear the absolutely-positioned .ai-close (right: 18px, ~36px wide) */
  padding-right: max(64px, calc(50% - var(--sb-content-width) / 2));
  background: var(--sb-surface);
  flex-shrink: 0;
}

#ai-chat-input {
  width: 100%;
  padding: 14px 18px;
  font-family: var(--sb-font-body);
  font-size: 15px;
  border: 1.5px solid var(--sb-border);
  border-radius: 10px;
  outline: none;
  color: var(--sb-ink);
  background: var(--sb-bg);
  box-sizing: border-box;
  transition: border-color .16s ease, box-shadow .16s ease;
}

#ai-chat-input::placeholder { color: var(--sb-muted); }
#ai-chat-input:focus {
  border-color: var(--sb-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sb-accent) 12%, transparent);
}

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 1100px) {
  .ai-link-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  :root { --sb-content-width: 100%; }

  .ai-tabs { padding: 0 20px; }
  #ai-results { padding: 24px 20px 12px; }
  #ai-input-bar { padding: 12px 20px; padding-right: 64px; }
}

@media (max-width: 760px) {
  #ai-panel { flex-direction: column; }

  #ai-sidebar {
    width: 100%;
    flex-direction: row;
    height: auto;
    max-height: 100px;
    border-right: none;
    border-bottom: 1px solid var(--sb-border);
    padding: 12px;
    overflow-x: auto;
  }

  #ai-new-chat { margin-bottom: 0; margin-right: 12px; white-space: nowrap; width: auto; flex-shrink: 0; }
  #ai-chat-list { flex-direction: row; gap: 6px; align-items: center; }
  .ai-chat-item { white-space: nowrap; padding: 7px 12px; }
  .ai-sidebar-label { display: none; }
  .ai-images-grid { grid-template-columns: repeat(2, 1fr); }
  #ai-start { padding: 36px 20px 24px; }
  .ai-start-hero h2 { font-size: 28px; }
  .ai-search-bar-wrap { max-width: 100%; margin-bottom: 28px; }
  .ai-top-stories { max-width: 100%; }
  .ai-story-thumb { width: 64px; height: 54px; }
  .ai-msg-user { max-width: 95%; }
  .ai-msg-assistant { max-width: 100%; }

  #sitebrain-ai-header-btn { width: 30px; height: 30px; margin-right: 6px; }
  #sitebrain-ai-header-btn svg,
  #sitebrain-ai-header-btn img { width: 19px; height: 19px; }

  .ai-lightbox { padding: 48px 16px 56px; }
  .ai-lightbox-prev { left: 8px; }
  .ai-lightbox-next { right: 8px; }
  .ai-lightbox-nav { width: 38px; height: 38px; }
  .ai-lightbox-img { max-height: calc(100vh - 180px); }

  .ai-answer-thumb { width: 56px; height: 56px; }
  .ai-answer-card { gap: 12px; }
}

@media (max-width: 640px) {
  .ai-examples { flex-direction: column; align-items: stretch; }
  .ai-examples .sb-followup { justify-content: space-between; }

  .ai-link-grid { grid-template-columns: 1fr; gap: 12px; }
  .ai-link-thumb { aspect-ratio: 2 / 1; }
}