/* ================================================================
   Ask COL AI — Design System
   Premium financial terminal. COL Financial branded.
   ================================================================ */

/* Auth Gate */
.auth-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-gate[hidden] { display: none; }
.auth-container { text-align: center; max-width: 400px; width: 100%; }
.auth-brand { margin-bottom: 4px; }
.auth-ask { font-size: 32px; font-weight: 700; color: #f29a45; }
.auth-col { font-size: 32px; font-weight: 700; color: var(--primary, #004482); }
.auth-ai { font-size: 32px; font-weight: 700; color: var(--primary, #004482); }
.auth-beta {
  font-size: 11px; font-weight: 700; color: #f29a45;
  background: #fef6ee; padding: 2px 8px; border-radius: 4px;
  margin-left: 6px; vertical-align: top;
}
.auth-tagline {
  font-size: 13px; color: var(--text-muted, #8896a4);
  margin-bottom: 32px; letter-spacing: 0.5px; text-transform: uppercase;
}
.auth-card {
  background: var(--bg-white, #fff); border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px; padding: 32px; box-shadow: 0 4px 24px rgba(0,0,0,.08);
  text-align: left;
}
.auth-title { font-size: 20px; font-weight: 700; color: var(--primary, #004482); margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--text-muted, #8896a4); margin-bottom: 24px; }
.auth-error {
  background: #FEE2E2; color: #991B1B; padding: 10px 14px;
  border-radius: 6px; font-size: 13px; margin-bottom: 16px;
}
.auth-field { margin-bottom: 16px; }
.auth-field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-secondary, #64748b); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.auth-field input {
  width: 100%; padding: 10px 14px; font-size: 14px;
  border: 1px solid var(--border, #e2e8f0); border-radius: 6px;
  background: var(--bg, #f8fafc); color: var(--text, #1e293b);
  outline: none; transition: border-color .15s;
  box-sizing: border-box;
}
.auth-field input:focus {
  border-color: var(--primary, #004482);
  box-shadow: 0 0 0 3px rgba(0,68,130,.08);
}
.auth-field input::placeholder { color: var(--text-muted, #8896a4); }
.auth-submit-btn {
  width: 100%; padding: 12px; font-size: 14px; font-weight: 600;
  color: #fff; background: var(--primary, #004482); border: none;
  border-radius: 6px; cursor: pointer; transition: background .15s; margin-top: 8px;
}
.auth-submit-btn:hover { background: var(--primary-hover, #003366); }
.auth-submit-btn:disabled { background: var(--border, #e2e8f0); cursor: not-allowed; }
.auth-toggle { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-muted, #8896a4); }
.auth-link-btn {
  color: var(--primary, #004482); font-weight: 600; font-size: 13px;
  text-decoration: underline; text-underline-offset: 2px;
  background: none; border: none; cursor: pointer;
}
.auth-footer { margin-top: 24px; font-size: 11px; color: var(--text-muted, #8896a4); }

:root {
  /* COL Brand — Primary Blues */
  --primary:        #004482;
  --primary-light:  #006ab4;
  --primary-hover:  #003366;
  --primary-surface: #daebf1;

  /* COL Brand — Accent */
  --accent:         #00ade9;
  --accent-light:   #e8f7fc;
  --accent-hover:   #0095cc;

  /* COL Brand — Warm Accent (for CTAs, highlights) */
  --warm:           #f29a45;
  --warm-light:     #fef6ee;
  --warm-hover:     #e0872e;

  /* Backgrounds */
  --bg:             #f2f5ff;
  --bg-white:       #FFFFFF;
  --bg-sidebar:     #FFFFFF;

  /* Text */
  --text:           #1A1A1A;
  --text-secondary: #5F6368;
  --text-muted:     #8892a0;
  --text-on-dark:   #c8d6e5;
  --text-on-dark-bright: #FFFFFF;

  /* Borders */
  --border:         #E0E4EA;
  --border-light:   #EEF0F4;
  --border-dark:    rgba(255,255,255,0.12);

  /* Layout */
  --sidebar-width:  280px;
  --content-max:    960px;

  /* Radius */
  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      16px;

  /* Shadows */
  --shadow-sm:      0 1px 3px rgba(0,68,130,.06);
  --shadow-md:      0 2px 12px rgba(0,68,130,.08);
  --shadow-lg:      0 8px 32px rgba(0,68,130,.12);

  /* Typography */
  --font:           "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:      "SF Mono", "Consolas", "Menlo", monospace;
}


/* ----------------------------------------------------------------
   Reset & Base
   ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Prevent iOS auto-zoom on input focus (requires >= 16px) */
input, textarea, select { font-size: 16px !important; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
textarea { font: inherit; color: inherit; }

/* Global focus ring */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}


/* ----------------------------------------------------------------
   Sidebar
   ---------------------------------------------------------------- */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback for older browsers */
  overflow: hidden;
  transition: transform .2s ease;
  z-index: 200;
}

@supports (height: 100dvh) {
  #sidebar { height: 100dvh; }
}

.sidebar-header {
  padding: 24px 20px;
}

.brand { display: flex; align-items: baseline; gap: 2px; cursor: pointer; }

.brand-ask {
  font-size: 22px;
  font-weight: 700;
  color: #f29a45;
  letter-spacing: -.3px;
}

.brand-col {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -.3px;
}

.brand-ai {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: .5px;
}

.brand-beta {
  font-size: 9px;
  font-weight: 700;
  color: #f29a45;
  background: rgba(242,154,69,0.12);
  padding: 2px 5px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: super;
  letter-spacing: .5px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: .5px;
  margin-top: 4px;
  text-transform: uppercase;
}

#new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 16px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background .15s, border-color .15s, color .15s;
}

#new-chat-btn:hover {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
}

#new-chat-btn svg { flex-shrink: 0; }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Collapsible sections */
.sidebar-section {
  border-bottom: 1px solid var(--border-light);
}

.sidebar-section:last-child { border-bottom: none; }

.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 20px;
  text-align: left;
  transition: background .1s;
}

.section-toggle:hover { background: var(--bg); }

.section-title {
  font-size: 10px;
  font-weight: 700;
  color: #004482;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.section-toggle .chevron {
  color: var(--text-muted);
  transition: transform .2s ease;
  flex-shrink: 0;
}

.section-toggle[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

.section-panel {
  padding: 0 20px 12px;
  overflow: hidden;
}

.section-panel.collapsed { display: none; }

.empty-state {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 4px;
  line-height: 1.5;
}

/* Document categories (collapsible folders) */
.doc-category {
  margin-bottom: 4px;
}

.doc-category:last-child { margin-bottom: 0; }

.doc-category-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  transition: background .1s;
  text-align: left;
}

.doc-category-toggle:hover { background: var(--bg); }

.doc-category-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.doc-category-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-category-count {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 10px;
  padding: 0 6px;
  line-height: 18px;
  flex-shrink: 0;
}

.doc-category-toggle .chevron-sm {
  color: var(--text-muted);
  transition: transform .15s ease;
  flex-shrink: 0;
}

.doc-category-toggle[aria-expanded="false"] .chevron-sm {
  transform: rotate(-90deg);
}

.doc-category-items {
  padding: 4px 0 8px 12px;
}

.doc-category-items.collapsed { display: none; }

.doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  transition: background .12s;
}

.doc-item.clickable { cursor: pointer; }
.doc-item.clickable:hover { background: var(--bg); }

.doc-ticker {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  min-width: 48px;
}

.doc-name {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-item.clickable:hover .doc-name,
.doc-item.clickable:hover .doc-ticker {
  color: var(--accent);
}

.doc-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

.doc-status {
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 8px;
  margin-top: 4px;
}

/* Conversation history */
.history-item {
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
}

.history-item:hover { background: var(--bg); }
.history-item:active { background: var(--border-light); }
.history-item.active {
  background: var(--primary);
  color: #FFFFFF;
  border-radius: var(--radius-md);
  border-left: none;
}

.history-item.active .history-query { color: #FFFFFF; }
.history-item.active .history-time { color: rgba(255,255,255,0.7); }

.history-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.history-text {
  flex: 1;
  min-width: 0;
}

.history-query {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.history-actions {
  position: relative;
  flex-shrink: 0;
}

.history-menu-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  border-radius: 4px;
  opacity: 0;
  transition: opacity .12s, background .12s;
}

.history-item:hover .history-menu-btn { opacity: 1; }
.history-menu-btn:hover { background: var(--bg); color: var(--text); }

.history-dropdown {
  position: absolute;
  right: 0;
  top: 28px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 100;
  min-width: 120px;
  padding: 4px 0;
}

.history-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 12px;
  text-align: left;
  color: var(--text);
  transition: background .1s;
}

.history-dropdown-item:hover { background: var(--bg); }

.history-pin-icon {
  font-size: 12px;
  margin-right: 4px;
  color: #f29a45;
}

/* COL Pulse sidebar */
.guide-description {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 10px;
}

.open-guide-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
  transition: background .12s, border-color .12s;
}

.open-guide-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.open-guide-btn svg {
  color: var(--accent);
  flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
}

.disclaimer-text {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

a.sidebar-link-item { text-decoration: none; color: inherit; }

/* Override gray for sidebar footer links — use body text color */
.sidebar-footer .theme-toggle-btn {
  color: var(--text);
  font-size: 13px;
  text-align: left;
}
/* Settings button stays muted gray */
#settings-toggle { color: var(--text-muted) !important; }

.settings-dropdown-wrap { position: relative; }
.settings-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 4px;
  right: 4px;
  background: var(--bg-white, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 0;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  z-index: 100;
}
.settings-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.settings-item:hover {
  background: var(--hover);
}

.message-ai .bubble {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}


/* Sidebar collapse toggle */
.sidebar-collapse-btn {
  position: fixed;
  top: 16px;
  left: calc(var(--sidebar-width) - 40px);
  z-index: 201;
  width: 28px;
  height: 28px;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
}

@media (min-width: 769px) {
  .sidebar-collapse-btn { display: flex; }
}

.sidebar-collapse-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}

body.sidebar-collapsed #sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

body.sidebar-collapsed .sidebar-collapse-btn {
  left: 12px;
  background: var(--bg-white);
  box-shadow: var(--shadow-sm);
}

/* ----------------------------------------------------------------
   Main area
   ---------------------------------------------------------------- */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
  overflow: hidden;
  background: var(--bg);
}

@supports (height: 100dvh) {
  #main { height: 100dvh; }
}

/* Top bar (mobile only) */
#top-bar {
  display: none;
  align-items: center;
  padding: 0 16px;
  height: 48px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

#sidebar-toggle {
  color: var(--text-secondary);
  padding: 10px;
  border-radius: var(--radius-sm);
  transition: background .12s;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#sidebar-toggle:hover { background: var(--bg); }

.top-bar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}


/* ----------------------------------------------------------------
   Split Pane Layout
   ---------------------------------------------------------------- */

.split-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* Left pane (document/guide) */
.left-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 300px;
  background: var(--bg);
}

.left-pane[hidden] { display: none; }

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pane-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  border-radius: 50%;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}

.pane-close:hover {
  background: var(--bg);
  color: var(--text);
}

.pane-content {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.pane-view[hidden] { display: none !important; }

/* Divider */
.split-divider {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background .15s;
}

.split-divider:hover,
.split-divider.dragging {
  background: var(--primary);
}

.split-divider[hidden] { display: none; }

.divider-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--text-muted);
  opacity: 0;
  transition: opacity .15s;
}

.split-divider:hover .divider-handle,
.split-divider.dragging .divider-handle {
  opacity: .5;
}

/* Right pane (chat) */
.right-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 320px;
  background: var(--bg);
}


/* ----------------------------------------------------------------
   Chat area
   ---------------------------------------------------------------- */

#chat-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#messages {
  flex: 1;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}


/* ----------------------------------------------------------------
   Welcome / Landing state
   ---------------------------------------------------------------- */

#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 20px 60px;
}

.welcome-logo {
  text-align: center;
  margin-bottom: 16px;
}

.welcome-heading {
  font-size: 24px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.4;
  margin: 0 0 28px 0;
}

.welcome-input-wrapper {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 640px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 4px 4px 4px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: border-color .15s, box-shadow .15s;
}

.welcome-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 2px 12px rgba(0,68,130,0.1);
}

.welcome-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--text);
  background: transparent;
  padding: 12px 0;
}

.welcome-input::placeholder {
  color: var(--text-muted);
}

.welcome-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f29a45;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
  transition: background .15s;
}

.welcome-send-btn:hover {
  background: #e0872e;
}

.welcome-suggestions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.suggestion-card {
  width: 200px;
  padding: 14px 16px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
}

.suggestion-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,68,130,0.08);
  transform: translateY(-1px);
}

.card-label {
  font-size: 11px;
  font-weight: 700;
  color: #004482;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.card-question {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

.input-disclaimers {
  text-align: center;
  margin-top: 8px;
}

.input-disclaimers .input-hint {
  margin-top: 4px;
}


/* ----------------------------------------------------------------
   Message bubbles
   ---------------------------------------------------------------- */

.message { display: flex; flex-direction: column; gap: 4px; }

.message-user { align-items: flex-end; }
.message-user .bubble {
  background: var(--primary);
  color: #FFFFFF;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  padding: 12px 16px;
  max-width: 70%;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.message-ai { align-items: flex-start; }
.message-ai .bubble {
  background: var(--bg-white);
  color: var(--text);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding: 18px 20px;
  max-width: 100%;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.7;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}

.message-ai .bubble p { margin-bottom: 12px; }
.message-ai .bubble p:last-child { margin-bottom: 0; }
.message-ai .bubble strong { font-weight: 600; }
.message-ai .bubble ul, .message-ai .bubble ol { padding-left: 20px; margin-bottom: 10px; }
.message-ai .bubble li { margin-bottom: 4px; }

.message-ai .bubble h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin: 16px 0 6px;
}

.message-ai .bubble h3:first-child { margin-top: 0; }

.message-ai .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.message-ai .bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Chat tables */
.table-wrap {
  overflow-x: auto;
  margin: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.chat-table {
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
  min-width: 600px;
}

.chat-table th,
.chat-table td {
  padding: 8px 12px;
  white-space: nowrap;
}

.chat-table th {
  background: var(--bg);
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
}

.chat-table td {
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.chat-table tbody tr:hover {
  background: var(--bg);
}

.chat-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Citations */
.citation {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  color: var(--primary-light);
  background: var(--accent-light);
  border-radius: 4px;
  padding: 2px 8px;
  margin: 0 2px;
  white-space: nowrap;
  cursor: pointer;
  transition: all .15s;
  border: 1px solid transparent;
}

.citation:hover {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
}

/* Numbered footnote citations [1] [2] [3] */
.citation-num {
  font-size: 0.75em;
  vertical-align: super;
  color: var(--primary);
  font-weight: 600;
  margin: 0 1px;
}

/* Sources section at bottom of response */
.sources-section {
  margin-top: 20px;
  margin-bottom: 20px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 0.82em;
  color: var(--text-secondary, #475569);
}

.sources-section strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary, #64748b);
}

.source-item {
  padding: 3px 0;
}

.source-link {
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.source-link.no-link {
  color: var(--text-secondary, #475569);
  cursor: default;
}

.source-link.no-link:hover {
  text-decoration: none;
}

/* Inline links in AI responses */
.inline-link {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.inline-link:hover { color: var(--primary-light); }

/* Follow-ups */
.follow-up-label {
  color: #f29a45;
  font-weight: 700;
  font-size: inherit;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}

.follow-up-btns { display: flex; flex-direction: column; gap: 6px; }

.follow-up-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  margin-bottom: 6px;
  font-size: 13px;
  color: #004482;
  background: #f2f5ff;
  border: 1px solid #e0e4ea;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
}

.follow-up-btn:hover {
  background: #004482;
  color: #FFFFFF;
  border-color: #004482;
}

/* Handoff / no-source */
.card-message {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  max-width: 540px;
}

.card-message.handoff { border-left: 3px solid var(--accent); }
.card-message.no-source { border-left: 3px solid var(--text-muted); }
.card-message p { font-size: 14px; line-height: 1.6; color: var(--text); }

.card-advisor-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background .15s;
}

.card-advisor-btn:hover { background: var(--primary-light); text-decoration: none; }

/* Advisor CTA card — prominent in-bubble call-to-action */
.advisor-cta-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  padding: 14px 20px;
  background: #004482;
  color: #fff;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background .15s;
}
.advisor-cta-card:hover {
  background: #003366;
}
.advisor-cta-icon { display: none; }
.advisor-cta-body {
  flex: 1;
  min-width: 0;
}
.advisor-cta-body strong {
  display: block;
  font-size: 14px;
  color: #fff;
  margin-bottom: 2px;
}
.advisor-cta-body p {
  font-size: 12px;
  color: rgba(255,255,255,.75);
  margin: 0;
  line-height: 1.5;
}
.advisor-cta-arrow {
  flex-shrink: 0;
  color: rgba(255,255,255,.6);
  transition: color .15s;
}
.advisor-cta-card:hover .advisor-cta-arrow { color: #fff; }

body.dark-mode .advisor-cta-card {
  background: #004482;
}
body.dark-mode .advisor-cta-card:hover {
  background: #003366;
}

.gray-zone-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  font-style: italic;
}

.loading-indicator {
  display: flex;
  align-items: center;
  padding: 12px 16px;
}

.thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  margin-right: 8px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: .2s; }
.thinking-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: .3; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1); }
}

.thinking-text {
  font-size: 13px;
  color: var(--text-muted);
}


/* ----------------------------------------------------------------
   Input area
   ---------------------------------------------------------------- */

#input-area {
  flex-shrink: 0;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  padding: 14px 24px 12px;
}

/* Landing state: input-area hidden via inline style + JS */

#chat-form {
  max-width: var(--content-max);
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 4px 4px 14px;
  background: var(--bg-white);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,173,233,.1);
}

#query-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 0;
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 140px;
  outline: none;
}

#query-input::placeholder { color: var(--text-muted); }

#send-btn {
  width: 44px;
  height: 44px;
  background: var(--warm);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}

#send-btn:hover:not(:disabled) { background: var(--warm-hover); }
#send-btn:active:not(:disabled) { transform: scale(0.95); }
#send-btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
#send-btn svg { width: 16px; height: 16px; }

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}

.input-hint a,
.input-hint .link-btn { color: var(--accent); }

.link-btn {
  background: none;
  border: none;
  font: inherit;
  color: #004482 !important;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-btn:hover { color: #003366 !important; }


/* ----------------------------------------------------------------
   Document Viewer
   ---------------------------------------------------------------- */

#doc-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
}

#doc-viewer-body {
  flex: 1;
  overflow: hidden;
  width: 100%;
  min-height: 0;
}

.pdf-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.pdf-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 15px;
}

.pdf-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--text-muted);
  font-size: 15px;
}

.pdf-open-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s;
}

.pdf-open-link:hover {
  background: var(--primary-hover);
}


/* ----------------------------------------------------------------
   Guide / Coverage Table
   ---------------------------------------------------------------- */

#guide-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-white);
}

#guide-viewer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.guide-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

#coverage-filter {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

#coverage-search {
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 180px;
}

#coverage-search:focus { border-color: var(--primary); }
#coverage-search::placeholder { color: var(--text-muted); }

#coverage-rating-filter:focus { border-color: var(--primary); }

#coverage-rating-filter {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

#coverage-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0;
}

#coverage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#coverage-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

#coverage-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

#coverage-table th:hover { color: var(--primary); }
#coverage-table th.num { text-align: right; }
#coverage-table th.sort-asc::after { content: " \u25B2"; font-size: 8px; }
#coverage-table th.sort-desc::after { content: " \u25BC"; font-size: 8px; }

#coverage-table th:first-child,
#coverage-table td:first-child { padding-left: 24px; }
#coverage-table th:last-child,
#coverage-table td:last-child { padding-right: 24px; }

#coverage-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  vertical-align: middle;
}

#coverage-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#coverage-table tbody tr:nth-child(even) { background: #FAFBFC; }
#coverage-table tbody tr:hover { background: #F0F2F5; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

.badge-buy  { background: #DEF7EC; color: #03543F; }
.badge-hold { background: var(--warm-light); color: #92400E; }
.badge-sell { background: #FEE2E2; color: #991B1B; }
.badge-review { background: #E5E7EB; color: #6B7280; }

.trend-up   { color: #059669; font-weight: 600; }
.trend-down { color: #DC2626; font-weight: 600; }
.trend-side { color: #D97706; font-weight: 600; }

.rec-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 99px;
  letter-spacing: .2px;
}

.rec-buy      { background: #DEF7EC; color: #03543F; }
.rec-hold     { background: var(--warm-light); color: #92400E; }
.rec-sell     { background: #FEE2E2; color: #991B1B; }
.rec-lighten  { background: var(--warm-light); color: #92400E; }
.rec-profits  { background: #DBEAFE; color: #1E40AF; }
.rec-other    { background: #E5E7EB; color: #6B7280; }

.narrative-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  white-space: normal;
  max-width: 280px;
}


/* ----------------------------------------------------------------
   Advisor Modal
   ---------------------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-muted);
  border-radius: 50%;
  transition: color .12s, background .12s;
  line-height: 1;
}

.modal-close:hover { color: var(--text); background: var(--bg); }

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
}

.modal-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-contacts { display: flex; flex-direction: column; gap: 8px; }

.contact-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  transition: border-color .12s, background .12s;
}

.contact-btn:hover {
  border-color: var(--primary);
  background: var(--bg);
  text-decoration: none;
}

.contact-btn svg { color: var(--primary); flex-shrink: 0; }

.modal-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 14px;
  text-align: center;
}


/* ----------------------------------------------------------------
   Scrollbar
   ---------------------------------------------------------------- */

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }


/* ----------------------------------------------------------------
   No-select during drag
   ---------------------------------------------------------------- */

body.resizing {
  cursor: col-resize;
  user-select: none;
}

body.resizing iframe,
body.resizing embed,
body.resizing object {
  pointer-events: none;
}


/* ----------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------- */

/* Sidebar overlay backdrop (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}

.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100%;
    transform: translateX(-100%);
    pointer-events: none;
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
  }

  #top-bar { display: flex; }

  /* Welcome page mobile fixes */
  .welcome-suggestions { flex-direction: column; align-items: center; }
  .suggestion-card,
  .suggestion-card[style] { width: 100% !important; max-width: 340px; }
  .welcome-heading { font-size: 20px; }
  .welcome-heading br { display: none; }

  #messages { padding: 16px 14px; }

  .message-user .bubble { max-width: 85%; }
  .message-ai .bubble { max-width: 100%; padding: 14px 16px; }

  #input-area { padding: 10px 14px 8px; }

  #coverage-filter { flex-wrap: wrap; margin-left: 0; }
  #coverage-search { width: 100%; }

  /* On mobile, split goes vertical — left pane on top */
  .split-container {
    flex-direction: column;
  }

  .left-pane {
    min-width: 0;
    max-height: 60vh;
    flex: 1 1 auto !important;
  }

  .left-pane .pdf-frame {
    min-height: 50vh;
  }

  .split-divider {
    width: 100%;
    height: 5px;
    cursor: row-resize;
  }

  .right-pane {
    min-width: 0;
  }

  /* Welcome section — fix min-height for mobile dvh */
  #welcome[style] { min-height: calc(100dvh - 60px) !important; }
}

/* Phone-specific tightening */
@media (max-width: 480px) {
  #messages { padding: 12px 10px; gap: 16px; }
  .message-ai .bubble { padding: 12px 14px; font-size: 14px; }
  .message-user .bubble { padding: 10px 14px; font-size: 14px; }

  #input-area { padding: 8px 10px 6px; }
  .input-wrapper { padding: 2px 2px 2px 12px; }
  .input-disclaimers { display: none; }

  .follow-up-btn { padding: 8px 12px; font-size: 12px; }

  /* Welcome page on small phones */
  #welcome[style] { padding: 0 16px !important; }
  .suggestion-card[style] { padding: 12px 14px !important; }
}

@media (min-width: 769px) {
  #top-bar { display: none; }
}

/* Theme toggle */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 100%;
  transition: background .15s, color .15s;
  margin-bottom: 8px;
}

.theme-toggle-btn:hover {
  background: var(--bg);
  color: var(--text);
}

/* Dark mode */
body.dark-mode {
  --bg: #1a1a2e;
  --bg-white: #16213e;
  --bg-sidebar: #0f1629;
  --text: #e0e0e0;
  --text-secondary: #a0a0b0;
  --text-muted: #6b7280;
  --border: #2a2a4a;
  --border-light: #222240;
}

body.dark-mode #sidebar {
  background: var(--bg-sidebar);
  border-right-color: var(--border);
}

body.dark-mode .section-title,
body.dark-mode .doc-category-name { color: var(--accent); }
body.dark-mode .doc-name,
body.dark-mode .history-query { color: var(--text); }

body.dark-mode .message-ai .bubble {
  background: var(--bg-white);
  border-color: var(--border);
}

body.dark-mode .suggestion-card {
  background: var(--bg-white);
  border-color: var(--border);
}

body.dark-mode .card-question {
  color: var(--text);
}

body.dark-mode .card-label {
  color: var(--accent);
}

body.dark-mode .welcome-input-wrapper {
  background: var(--bg-white);
  border-color: var(--border);
}

body.dark-mode .welcome-input {
  color: var(--text);
}

body.dark-mode .welcome-heading {
  color: var(--text-muted);
}

body.dark-mode .input-wrapper {
  background: var(--bg-white);
  border-color: var(--border);
}

body.dark-mode #query-input {
  color: var(--text);
}

/* Force welcome centering — but NOT display, so JS can hide it */
#welcome { flex:1!important;flex-direction:column!important;align-items:center!important;justify-content:center!important; }
