/* ============================================================
   GSB.ai — Claude-app-style chat surface in the GSB design system
   Loads after style.css; overrides the legacy bubble/chrome look.
   Layout contract with gsb-ai-app.js:
   - #gsbai-shell gets .gsbai-fresh when chatHistory is empty →
     hero greeting + centered composer; otherwise messages column
     with the composer pinned at the bottom.
   ============================================================ */

/* ---- Shell & panels ---- */
#gsbai-screen .gsbai-shell {
  display: flex;
  gap: 0;
  width: 100%;
  height: calc(100vh - 210px);
  min-height: 460px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

/* ---- Sidebar: flat recents list, Claude-style ---- */
#gsbai-sidebar {
  display: flex;
  flex-direction: column;
  width: 248px;
  min-width: 248px;
  border-right: 1px solid var(--border);
  background: #FAF7F0;
  transition: all 0.25s ease;
  overflow: hidden;
}
#gsbai-sidebar .gsbai-side-top {
  padding: 12px;
}
#gsbai-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--color-surface, #fff);
  font-size: 13px;
  font-weight: 600;
  color: var(--gsb-soil-ink, #221E18);
  cursor: pointer;
}
#gsbai-new-chat:hover { background: #EDE7DA; }
.gsbai-side-label {
  padding: 10px 16px 4px;
  font-family: var(--font-mono, ui-monospace);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gsb-stone, #6F695B);
}
#gsbai-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#gsbai-history-list .gsbai-history-item {
  border: none;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
}
#gsbai-history-list .gsbai-history-item:hover { background: #EDE7DA; border: none; }
#gsbai-history-list .gsbai-history-item.active {
  background: #EDE7DA;
  color: var(--gsb-soil-ink, #221E18);
  font-weight: 600;
}

/* ---- Main column ---- */
#gsbai-shell-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}
.gsbai-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--color-surface, #fff);
}
.gsbai-topbar .ghost-btn {
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
}
#gsbai-chat-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-muted, #6F695B);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Messages column ---- */
#gsbai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}
#gsbai-messages > .gsbai-message {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}
.gsbai-fresh #gsbai-messages { display: none; }

/* Claude-like: user turns are quiet oat bubbles right-aligned;
   assistant turns are plain ink on paper, full column width. */
.gsbai-message { animation: gsbai-message-appear 0.2s ease-out; }
.gsbai-message-user {
  align-self: auto;
  background: transparent;
  color: inherit;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.gsbai-message-user .gsbai-message-content {
  background: #EDE7DA;
  color: var(--gsb-soil-ink, #221E18);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
  max-width: 85%;
  font-size: 14px;
}
.gsbai-message-user .gsbai-message-time { text-align: right; }
.gsbai-message-assistant {
  align-self: auto;
  background: transparent;
  border-radius: 0;
  padding: 0;
  color: var(--gsb-soil-ink, #221E18);
}
.gsbai-message-assistant .gsbai-message-content {
  font-size: 14px;
  line-height: 1.65;
}
.gsbai-message-error .gsbai-message-content {
  background: #F7EDE7;
  border: 1px solid #EAD3C8;
  color: #9A4527;
  border-radius: 10px;
  padding: 10px 14px;
}

/* ---- Markdown typography (Claude-app-grade, GSB voice) ----
   Scoped hard so style.css's bare table/td/th rules can't leak in. */
.gsbai-message-assistant .gsbai-message-content p { margin: 0 0 10px; }
.gsbai-message-assistant .gsbai-message-content > *:last-child { margin-bottom: 0; }
.gsbai-message-assistant .gsbai-message-content h1,
.gsbai-message-assistant .gsbai-message-content h2 {
  font-family: var(--font-display, Georgia, serif);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--gsb-soil-ink, #221E18);
  margin: 18px 0 8px;
}
.gsbai-message-assistant .gsbai-message-content h1 { font-size: 21px; }
.gsbai-message-assistant .gsbai-message-content h2 { font-size: 18px; }
.gsbai-message-assistant .gsbai-message-content h3 {
  font-size: 14.5px;
  font-weight: 650;
  margin: 16px 0 6px;
}
.gsbai-message-assistant .gsbai-message-content h4 {
  font-family: var(--font-mono, ui-monospace);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gsb-stone, #6F695B);
  margin: 14px 0 4px;
}
.gsbai-message-assistant .gsbai-message-content ul,
.gsbai-message-assistant .gsbai-message-content ol {
  margin: 8px 0 10px;
  padding-left: 24px;
}
.gsbai-message-assistant .gsbai-message-content li { margin: 3px 0; }
.gsbai-message-assistant .gsbai-message-content li > ul,
.gsbai-message-assistant .gsbai-message-content li > ol { margin: 3px 0; }
.gsbai-message-assistant .gsbai-message-content blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--gsb-leaf, #82BB90);
  background: #FAF7F0;
  border-radius: 0 8px 8px 0;
  color: var(--gsb-stone, #6F695B);
}
.gsbai-message-assistant .gsbai-message-content blockquote p:last-child { margin-bottom: 0; }
.gsbai-message-assistant .gsbai-message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.gsbai-message-assistant .gsbai-message-content a {
  color: #2F6B45;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.gsbai-message-assistant .gsbai-message-content strong { font-weight: 650; }
.gsbai-message-assistant .gsbai-message-content code {
  background: #EDE7DA;
  color: var(--gsb-soil-ink, #221E18);
  font-family: var(--font-mono, ui-monospace);
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
}

/* Tables scroll inside their own wrapper, never the page */
.gsbai-table-wrap { overflow-x: auto; margin: 10px 0; max-width: 100%; }
.gsbai-message-assistant .gsbai-message-content table {
  border-collapse: collapse;
  margin: 0;
  font-size: 13px;
  background: var(--color-surface, #fff);
}
.gsbai-message-assistant .gsbai-message-content th,
.gsbai-message-assistant .gsbai-message-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-variant-numeric: tabular-nums;
  text-align: left;
  white-space: nowrap;
}
.gsbai-message-assistant .gsbai-message-content th {
  background: #FAF7F0;
  font-family: var(--font-mono, ui-monospace);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gsb-stone, #6F695B);
}
.gsbai-message-assistant .gsbai-message-content tbody tr:nth-child(even) td { background: #FCFAF5; }

/* Code blocks: hairline card with a language bar + copy button */
.gsbai-codeblock {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 10px 0;
  background: #FAF7F0;
}
.gsbai-codeblock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  background: #F3EEE3;
  font-family: var(--font-mono, ui-monospace);
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gsb-stone, #6F695B);
}
.gsbai-codeblock pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
}
.gsbai-message-assistant .gsbai-message-content .gsbai-codeblock pre code,
.gsbai-codeblock pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
}

/* Copy buttons */
.gsbai-copy-btn {
  font-family: var(--font-mono, ui-monospace);
  font-size: 10px;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--color-surface, #fff);
  color: var(--gsb-stone, #6F695B);
  cursor: pointer;
}
.gsbai-copy-btn:hover { background: #EDE7DA; }
.gsbai-msg-copy { margin-left: 8px; opacity: 0; transition: opacity 0.15s; }
.gsbai-message-assistant:hover .gsbai-msg-copy { opacity: 1; }

/* ---- Activity strip: one quiet line for a turn's whole tool run ---- */
.gsbai-activity {
  border: 1px solid var(--border);
  background: #FAF7F0;
  border-radius: 10px;
  margin: 0 0 12px;
  overflow: hidden;
}
.gsbai-activity-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono, ui-monospace);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gsb-stone, #6F695B);
}
.gsbai-activity-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gsb-leaf, #82BB90);
  flex: 0 0 auto;
}
.gsbai-activity.running .gsbai-activity-dot { animation: gsbai-act-pulse 1.2s ease-in-out infinite; }
@keyframes gsbai-act-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
.gsbai-activity-label {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gsbai-activity-chev { font-size: 9px; transition: transform 0.15s; }
.gsbai-activity.expanded .gsbai-activity-chev { transform: rotate(90deg); }
.gsbai-activity-body { display: none; border-top: 1px solid var(--border); padding: 4px 12px 10px; }
.gsbai-activity.expanded .gsbai-activity-body { display: block; }
.gsbai-act-row { padding: 7px 0; border-bottom: 1px dashed var(--border); }
.gsbai-act-row:last-child { border-bottom: none; }
.gsbai-act-rowhead {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--font-mono, ui-monospace);
  font-size: 11.5px;
  color: var(--gsb-soil-ink, #221E18);
}
.gsbai-act-done { color: #2F6B45; }
.gsbai-act-run { color: #B98B32; }
.gsbai-act-stop { color: var(--gsb-stone, #6F695B); }
.gsbai-act-sql {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono, ui-monospace);
  font-size: 11px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre;
  color: var(--gsb-soil-ink, #221E18);
}

/* ---- Hero (fresh-chat state) ---- */
#gsbai-hero {
  display: none;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  text-align: center;
  padding: 24px 20px 18px;
}
.gsbai-fresh #gsbai-hero { display: flex; }
.gsbai-hero-mark {
  color: var(--gsb-leaf, #82BB90);
  font-size: 26px;
  line-height: 1;
  margin-bottom: 10px;
}
.gsbai-hero-title {
  font-family: var(--font-display, Georgia, serif);
  font-weight: 400;
  font-size: 34px;
  letter-spacing: -0.01em;
  color: var(--gsb-soil-ink, #221E18);
  margin: 0;
}
.gsbai-hero-sub {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--color-text-muted, #6F695B);
}

/* ---- Composer ---- */
.gsbai-composer-zone {
  padding: 10px 20px 16px;
  position: relative;
}
.gsbai-fresh .gsbai-composer-zone { padding-top: 18px; }
.gsbai-composer {
  max-width: 780px;
  margin: 0 auto;
  background: var(--color-surface, #fff);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(34, 30, 24, 0.06);
  padding: 6px 8px 8px;
  position: relative;
}
.gsbai-fresh .gsbai-composer { box-shadow: 0 6px 24px rgba(34, 30, 24, 0.09); }
#gsbai-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14.5px;
  font-family: var(--font-body, inherit);
  line-height: 1.45;
  padding: 10px 10px 6px;
  color: var(--gsb-soil-ink, #221E18);
  resize: none;
  max-height: 132px;
  overflow-y: auto;
}
#gsbai-send.gsbai-stop { background: #9A4527; }
.gsbai-composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 6px 0 10px;
}
.gsbai-composer-status {
  font-family: var(--font-mono, ui-monospace);
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gsb-stone, #6F695B);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gsbai-composer-status .gsbai-dot { color: var(--gsb-leaf, #82BB90); }
.gsbai-composer-actions { display: flex; align-items: center; gap: 6px; }
#gsbai-mic {
  position: static;
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
#gsbai-mic:hover { background: #EDE7DA; }
#gsbai-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--gsb-soil-ink, #221E18);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#gsbai-send:hover { background: #3A342B; }
#gsbai-send:disabled { opacity: 0.4; cursor: default; }

/* Spacer keeps the hero+composer vertically centered when fresh */
#gsbai-below-spacer { display: none; }
.gsbai-fresh #gsbai-below-spacer { display: block; flex: 1 1 auto; }

/* Typing indicator sits just above the composer */
#gsbai-typing {
  padding: 0 20px 6px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

/* Autocomplete panel anchors to the composer */
.gsbai-composer .gsbai-autocomplete-panel {
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
}

/* ---- Mobile ----
   style.css stacks the sidebar above the chat (the shell carries the old
   .gsbai-container-wrapper class) but sets height:auto !important, which
   lets the composer scroll off-screen. Re-pin everything: fixed dynamic-
   viewport height, sidebar collapsed by default (JS adds .collapsed on
   phones), composer always visible at the bottom. */
@media (max-width: 768px) {
  #gsbai-screen .gsbai-shell {
    height: calc(100dvh - 150px) !important;
    min-height: 420px;
  }
  #gsbai-shell-main { min-height: 0; flex: 1; }
  #gsbai-sidebar { height: 170px !important; }
  #gsbai-sidebar.collapsed { height: 0 !important; }
  .gsbai-hero-title { font-size: 25px; }
  .gsbai-hero-sub { font-size: 12px; }
  #gsbai-hero { padding: 12px 14px 10px; }
  #gsbai-messages { padding: 14px 12px 6px; }
  #gsbai-messages > .gsbai-message,
  .gsbai-composer { max-width: 100%; }
  .gsbai-composer-zone { padding: 8px 10px 12px; }
  /* 16px stops iOS Safari's auto-zoom on focus */
  #gsbai-input { font-size: 16px; }
  .gsbai-composer-status { max-width: 46vw; }
  .gsbai-topbar { padding: 8px 10px; }
  #gsbai-toggle-sidebar span { display: none; } /* icon-only on phones */
  .gsbai-message-user .gsbai-message-content { max-width: 92%; }
  .gsbai-message-assistant .gsbai-message-content { font-size: 14.5px; }
}
