/**
 * Shrishan AI — premium full-viewport chat workspace (public homepage).
 * Keeps Playwright IDs: #paiFab #paiOverlay #paiThread #paiInput .pai-msg-bot
 */
:root {
  --pai-bg: #f6f3f1;
  --pai-panel: #ffffff;
  --pai-ink: #171717;
  --pai-muted: #5b5b5b;
  --pai-border: #eadfdb;
  --pai-maroon: #7b0000;
  --pai-orange: #ee5b12;
  --pai-user: #7b0000;
  --pai-bot-bg: #fff7f4;
  --pai-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  --pai-font: 1rem;
  --pai-radius: 14px;
}

.pai-overlay.pai-theme-dark {
  --pai-bg: #121212;
  --pai-panel: #1c1c1e;
  --pai-ink: #f2f2f2;
  --pai-muted: #a8a8a8;
  --pai-border: #333;
  --pai-bot-bg: #26262a;
  --pai-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.pai-overlay.pai-contrast {
  --pai-ink: #000;
  --pai-bg: #fff;
  --pai-bot-bg: #fff;
  --pai-border: #000;
  --pai-muted: #222;
}

.pai-fab {
  position: fixed;
  right: 20px;
  bottom: 22px;
  z-index: 1050;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--pai-maroon, #7b0000);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: var(--pai-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pai-fab:active { transform: scale(0.96); }
.pai-fab:focus-visible { outline: 3px solid var(--pai-orange); outline-offset: 3px; }

.pai-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1051;
  background: rgba(23, 23, 23, 0.55);
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}
.pai-overlay.open { display: flex; }

.pai-panel {
  background: var(--pai-panel);
  color: var(--pai-ink);
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
  display: flex;
  flex-direction: row;
  box-shadow: none;
  overflow: hidden;
  font-size: var(--pai-font);
}

/* ---- Sidebar (history) ---- */
.pai-sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: var(--pai-bg);
  border-right: 1px solid var(--pai-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pai-sidebar-head {
  padding: 14px 14px 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--pai-border);
}
.pai-sidebar-title {
  font-weight: 800;
  font-size: 0.95rem;
  flex: 1;
}
.pai-sidebar-search {
  margin: 10px 12px 0;
  width: calc(100% - 24px);
  border: 1px solid var(--pai-border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--pai-panel);
  color: var(--pai-ink);
  font-size: 0.85rem;
}
.pai-history-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}
.pai-history-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--pai-ink);
  border-radius: 10px;
  padding: 10px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1.35;
  display: block;
  margin-bottom: 4px;
}
.pai-history-item:hover,
.pai-history-item.active { background: var(--pai-bot-bg); }
.pai-history-item small {
  display: block;
  color: var(--pai-muted);
  margin-top: 3px;
  font-size: 0.72rem;
}
.pai-history-empty {
  padding: 16px 12px;
  color: var(--pai-muted);
  font-size: 0.82rem;
}

/* ---- Main column ---- */
.pai-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--pai-panel);
}

.pai-head {
  flex: 0 0 auto;
  background: var(--pai-maroon);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 3px solid var(--pai-orange);
  flex-wrap: wrap;
}
.pai-head-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.pai-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.95rem;
  flex: 0 0 auto;
}
.pai-head-title { font-weight: 800; font-size: 1.05rem; line-height: 1.2; }
.pai-head-desc {
  font-size: 0.74rem;
  opacity: 0.92;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(52vw, 420px);
}
.pai-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.pai-tool-btn {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.2;
}
.pai-tool-btn:hover { background: rgba(255, 255, 255, 0.22); }
.pai-tool-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.pai-close {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 1.25rem;
  line-height: 1;
}

/* Mode awareness banner — always visible above the conversation */
.pai-mode-banner {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 4% 12px;
  color: #fff;
  background: #1d4ed8;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.86rem;
  line-height: 1.4;
}
.pai-mode-banner.pai-mode-stcw { background: linear-gradient(135deg, #1d4ed8, #1e40af); }
.pai-mode-banner.pai-mode-net { background: linear-gradient(135deg, #15803d, #166534); }
.pai-mode-banner.pai-mode-hybrid { background: linear-gradient(135deg, #7c3aed, #5b21b6); }
.pai-mode-banner[hidden] { display: none !important; }
.pai-mode-banner-title {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.pai-mode-banner-desc {
  margin-top: 4px;
  opacity: 0.92;
  font-size: 0.8rem;
  max-width: 920px;
}
.pai-mode-sources {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
  margin-top: 8px;
  max-width: 920px;
}
@media (max-width: 640px) {
  .pai-mode-sources { grid-template-columns: 1fr; }
  .pai-mode-banner { padding: 8px 12px 10px; }
  .pai-mode-banner-desc { display: none; }
}
.pai-mode-sources-h {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 2px;
}
.pai-mode-sources ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.pai-mode-sources li {
  font-size: 0.78rem;
  padding: 1px 0;
}
.pai-source-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed var(--pai-border);
  background: rgba(0, 0, 0, 0.03);
  font-size: 0.78rem;
  color: var(--pai-muted);
}
.pai-overlay.pai-theme-dark .pai-source-box { background: rgba(255, 255, 255, 0.04); }
.pai-source-box-title {
  font-weight: 800;
  color: var(--pai-ink);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.pai-source-box ul {
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
}
.pai-source-box li { padding: 1px 0; }
.pai-source-used li { color: #166534; }
.pai-overlay.pai-theme-dark .pai-source-used li { color: #86efac; }
.pai-source-not li { color: #9a3412; }
.pai-overlay.pai-theme-dark .pai-source-not li { color: #fdba74; }

/* Conversation — majority of viewport; NO max-height on messages */
.pai-thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 4% 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--pai-bg);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.pai-msg-row {
  display: flex;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
}
.pai-msg-row.user { justify-content: flex-end; }
.pai-msg-row.bot { justify-content: flex-start; }

.pai-msg {
  max-width: min(100%, 860px);
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 1em;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.pai-msg-bot {
  background: var(--pai-bot-bg);
  color: var(--pai-ink);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--pai-border);
  width: 100%;
}
.pai-msg-user {
  background: var(--pai-user);
  color: #fff;
  border-bottom-right-radius: 4px;
  max-width: min(92%, 640px);
}
.pai-msg-typing {
  color: var(--pai-muted);
  font-style: italic;
}
.pai-typing-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 2px;
  border-radius: 50%;
  background: var(--pai-muted);
  animation: pai-bounce 1.2s infinite ease-in-out;
}
.pai-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.pai-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pai-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.pai-msg-meta {
  display: block;
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--pai-muted);
  font-style: normal;
  font-weight: 600;
}

/* Markdown body */
.pai-md h1, .pai-md h2, .pai-md h3, .pai-md h4 {
  margin: 1.1em 0 0.45em;
  line-height: 1.25;
  font-weight: 800;
  color: var(--pai-ink);
}
.pai-md h1 { font-size: 1.35em; }
.pai-md h2 { font-size: 1.18em; }
.pai-md h3 { font-size: 1.05em; }
.pai-md p { margin: 0.55em 0; }
.pai-md ul, .pai-md ol { margin: 0.5em 0 0.5em 1.25em; padding: 0; }
.pai-md li { margin: 0.25em 0; }
.pai-md a { color: var(--pai-maroon); text-decoration: underline; }
.pai-theme-dark .pai-md a { color: #ffb08a; }
.pai-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.pai-theme-dark .pai-md code { background: rgba(255, 255, 255, 0.08); }
.pai-md pre {
  background: #1e1e1e;
  color: #f3f3f3;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0.75em 0;
  font-size: 0.88em;
  line-height: 1.45;
}
.pai-md pre code { background: transparent; padding: 0; color: inherit; }
.pai-md table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 0.92em;
  display: block;
  overflow-x: auto;
}
.pai-md th, .pai-md td {
  border: 1px solid var(--pai-border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.pai-md th { background: rgba(123, 0, 0, 0.08); font-weight: 700; }
.pai-md blockquote {
  margin: 0.7em 0;
  padding: 0.4em 0 0.4em 12px;
  border-left: 3px solid var(--pai-orange);
  color: var(--pai-muted);
}
.pai-md img, .pai-md video {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  margin: 0.6em 0;
}
.pai-md .pai-mermaid {
  background: var(--pai-panel);
  border: 1px solid var(--pai-border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.85em;
  white-space: pre-wrap;
}

/* Smart sections + TOC */
.pai-toc {
  border: 1px solid var(--pai-border);
  background: var(--pai-panel);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 12px;
}
.pai-toc-title {
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.pai-toc a {
  display: block;
  color: var(--pai-maroon);
  text-decoration: none;
  font-size: 0.86rem;
  padding: 4px 0;
}
.pai-toc a:hover { text-decoration: underline; }
.pai-theme-dark .pai-toc a { color: #ffb08a; }

.pai-section {
  border: 1px solid var(--pai-border);
  border-radius: 12px;
  margin: 10px 0;
  background: var(--pai-panel);
  overflow: hidden;
}
.pai-section > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 12px;
  font-weight: 800;
  background: rgba(123, 0, 0, 0.06);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pai-section > summary::-webkit-details-marker { display: none; }
.pai-section > summary::before {
  content: '▸';
  color: var(--pai-orange);
  font-size: 0.85em;
}
.pai-section[open] > summary::before { content: '▾'; }
.pai-section-body { padding: 10px 12px 12px; }

/* Cards */
.pai-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0 4px;
}
.pai-card {
  border: 1px solid var(--pai-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--pai-panel);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.pai-card-kicker {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pai-orange);
  margin-bottom: 4px;
}
.pai-card-title { font-weight: 800; font-size: 0.95rem; margin-bottom: 4px; }
.pai-card-meta { font-size: 0.8rem; color: var(--pai-muted); }

/* Actions under each bot message */
.pai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--pai-border);
}
.pai-action {
  border: 1px solid var(--pai-border);
  background: var(--pai-panel);
  color: var(--pai-ink);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}
.pai-action:hover { border-color: var(--pai-orange); color: var(--pai-maroon); }
.pai-action.active { background: var(--pai-maroon); color: #fff; border-color: var(--pai-maroon); }
.pai-action:focus-visible { outline: 2px solid var(--pai-orange); outline-offset: 2px; }

.pai-doc-offer {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--pai-orange);
  background: rgba(238, 91, 18, 0.06);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.pai-doc-offer strong { font-size: 0.88rem; }

/* Chips + composer — compact */
.pai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 4% 0;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  flex: 0 0 auto;
}
.pai-chip {
  border: 1px solid var(--pai-orange);
  background: var(--pai-panel);
  color: var(--pai-maroon);
  border-radius: 18px;
  padding: 6px 11px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}
.pai-chip:active { background: #fff2ef; }

.pai-composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--pai-border);
  background: var(--pai-panel);
  padding: 10px 4% 14px;
}
.pai-mic-status {
  display: none;
  padding: 0 0 8px;
  font-size: 0.78rem;
  color: var(--pai-maroon);
  font-weight: 700;
  max-width: 920px;
  margin: 0 auto;
}
.pai-mic-status.show { display: block; }

.pai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}
.pai-input {
  flex: 1 1 auto;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 0.95rem;
  resize: none;
  min-height: 44px;
  max-height: 176px; /* ~8 lines */
  line-height: 1.4;
  overflow-y: auto;
  background: var(--pai-panel);
  color: var(--pai-ink);
  font-family: inherit;
}
.pai-theme-dark .pai-input { border-color: #444; }
.pai-input:disabled { background: #f4f1f2; opacity: 0.85; }
.pai-theme-dark .pai-input:disabled { background: #2a2a2e; }

.pai-mic {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--pai-orange);
  background: var(--pai-panel);
  color: var(--pai-maroon);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}
.pai-mic.pai-mic-active {
  background: var(--pai-maroon);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(238, 91, 18, 0.35);
}
.pai-mic.pai-mic-unavailable { opacity: 0.55; }
.pai-send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--pai-maroon);
  color: #fff;
  cursor: pointer;
}
.pai-send:disabled { opacity: 0.5; cursor: not-allowed; }

.pai-composer-hint {
  max-width: 920px;
  margin: 6px auto 0;
  font-size: 0.72rem;
  color: var(--pai-muted);
}

/* Settings drawer */
.pai-settings {
  display: none;
  position: absolute;
  right: 12px;
  top: 64px;
  z-index: 6;
  width: min(320px, calc(100vw - 24px));
  background: var(--pai-panel);
  color: var(--pai-ink);
  border: 1px solid var(--pai-border);
  border-radius: 12px;
  box-shadow: var(--pai-shadow);
  padding: 12px;
}
.pai-settings.open { display: block; }
.pai-settings label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  margin: 8px 0;
  font-weight: 600;
}
.pai-settings select, .pai-settings input[type="range"] { max-width: 140px; }

/* Document mode (full-screen reader) */
.pai-docmode {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1060;
  background: var(--pai-panel);
  color: var(--pai-ink);
  flex-direction: column;
}
.pai-docmode.open { display: flex; }
.pai-docmode-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--pai-border);
  background: var(--pai-bg);
}
.pai-docmode-bar input[type="search"] {
  flex: 1 1 180px;
  min-width: 140px;
  border: 1px solid var(--pai-border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--pai-panel);
  color: var(--pai-ink);
}
.pai-docmode-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.pai-docmode-toc {
  width: 240px;
  flex: 0 0 240px;
  overflow-y: auto;
  border-right: 1px solid var(--pai-border);
  padding: 12px;
  background: var(--pai-bg);
}
.pai-docmode-toc a {
  display: block;
  color: var(--pai-maroon);
  text-decoration: none;
  font-size: 0.84rem;
  padding: 5px 0;
}
.pai-docmode-article {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px 5%;
  max-width: 960px;
  margin: 0 auto;
}
.pai-docmode mark.pai-hl { background: #ffe08a; color: #000; padding: 0 2px; }

.pai-sidebar-toggle { display: none; }

@media (max-width: 900px) {
  .pai-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 5;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--pai-shadow);
  }
  .pai-overlay.pai-sidebar-open .pai-sidebar { transform: translateX(0); }
  .pai-sidebar-toggle { display: inline-flex; }
  .pai-docmode-toc { display: none; }
  .pai-head-desc { display: none; }
}

@media (max-width: 575px) {
  .pai-thread { padding: 12px 12px 20px; }
  .pai-composer { padding: 8px 12px 12px; }
  .pai-tool-btn { padding: 6px 8px; font-size: 0.7rem; }
}

@media (min-width: 1400px) {
  .pai-thread { padding-left: 8%; padding-right: 8%; }
}

@media print {
  .pai-fab, .pai-composer, .pai-chips, .pai-head-actions, .pai-actions, .pai-sidebar { display: none !important; }
  .pai-overlay.open { position: static; display: block; background: #fff; }
  .pai-panel { height: auto; display: block; }
  .pai-thread { overflow: visible; background: #fff; }
}
