/* ── Chat Assistant ───────────────────────────────────────────── */
.chat-container {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 128px);
  background: var(--bg2);
  border: 1px solid rgba(37,99,235,.12);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(37,99,235,.10), 0 1px 4px rgba(0,0,0,.05);
}

.chat-history {
  flex: 1;
  padding: 28px 28px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: #f7faff;
}

.chat-message {
  max-width: 76%;
  padding: 0;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-message.ai {
  align-self: flex-start;
  max-width: 84%;
  background: transparent;
  color: var(--text);
  padding: 0;
  border: none;
  box-shadow: none;
}

.chat-message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
  color: #fff;
  font-weight: 500;
  padding: 12px 18px;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 18px rgba(37,99,235,.26);
  white-space: normal;
}

/* ── AI message with avatar ────────────────────────────────────── */
.chat-ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.chat-ai-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.chat-ai-name {
  font-size: 11px;
  font-weight: 700;
  color: #3b82f6;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.chat-ai-body {
  background: #ffffff;
  border: 1px solid rgba(37,99,235,.12);
  border-radius: 14px;
  border-top-left-radius: 4px;
  padding: 14px 18px;
  box-shadow: 0 2px 8px rgba(37,99,235,.06);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.65;
}

/* ── Input Area ─────────────────────────────────────────────────── */
.chat-input-area {
  padding: 14px 20px 18px;
  background: #ffffff;
  border-top: 1px solid rgba(37,99,235,.09);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-suggestions {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chat-suggestions::-webkit-scrollbar { display: none; }

.suggest-chip {
  background: #f0f5ff;
  border: 1px solid rgba(37,99,235,.18);
  color: #1e40af;
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all .18s;
  letter-spacing: .01em;
}

.suggest-chip:hover {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #f0f5ff;
  border: 1.5px solid rgba(37,99,235,.18);
  border-radius: 12px;
  padding: 6px 6px 6px 14px;
  transition: border-color .2s, box-shadow .2s;
}

.input-row:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.10);
  background: #fff;
}

#chatInput {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 0;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: var(--font);
}

#chatInput::placeholder { color: #94a3b8; }

.btn-primary {
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  cursor: pointer;
  transition: opacity .18s, transform .1s;
  white-space: nowrap;
  letter-spacing: .02em;
}

.btn-primary:hover  { opacity: .92; }
.btn-primary:active { transform: scale(0.98); }

/* ── Analytical Response Styles ────────────────────────────────── */

/* Override pre-wrap for AI messages that render HTML */
.chat-message.ai {
  white-space: normal;
}

.chat-analytical {
  line-height: 1.65;
  font-size: 13.5px;
}

.chat-analytical p {
  margin: 0 0 10px;
}

.chat-section-head {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(37,99,235,0.2);
}

.chat-section-head:first-child {
  margin-top: 0;
}

.chat-section-subhead {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin: 12px 0 6px;
}

.chat-bullets {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chat-bullets li {
  padding-left: 16px;
  position: relative;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.chat-bullets li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--gold);
  font-size: 11px;
  top: 2px;
}

/* Flags used badge */
.chat-flags-used {
  margin-top: 12px;
  padding: 6px 12px;
  background: rgba(37,99,235,0.06);
  border: 1px solid rgba(37,99,235,0.15);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chat-flags-used code {
  background: rgba(37,99,235,0.08);
  border: 1px solid rgba(37,99,235,0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10.5px;
  color: var(--gold);
  font-family: monospace;
}

/* Data tables below AI response */
.chat-data-table {
  max-width: 100%;
  margin-top: 10px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.chat-data-label {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  padding: 7px 14px;
  font-size: 10.5px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: none;
}

/* Markdown tables rendered inside AI messages */
.chat-md-table-wrap {
  margin: 10px 0;
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid rgba(37,99,235,.14);
  box-shadow: 0 2px 8px rgba(37,99,235,.06);
}

.chat-md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 320px;
}

.chat-md-table thead tr {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}

.chat-md-table thead th {
  padding: 9px 14px;
  color: #fff;
  font-weight: 600;
  text-align: left;
  font-size: 11.5px;
  letter-spacing: .04em;
  white-space: nowrap;
}

.chat-md-table tbody tr {
  border-bottom: 1px solid rgba(37,99,235,.08);
}

.chat-md-table tbody tr:nth-child(even) {
  background: #f0f5ff;
}

.chat-md-table tbody tr:last-child {
  border-bottom: none;
}

.chat-md-table tbody td {
  padding: 8px 14px;
  color: var(--text);
  vertical-align: middle;
}

/* Error */
.chat-error {
  color: #dc2626;
  font-size: 13px;
}

/* Chart type toggle bar */
.chart-type-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.chart-type-toggle-label {
  font-size: 10.5px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-right: 4px;
}

.chart-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 20px;
  border: 1.5px solid rgba(37,99,235,.2);
  background: #f8faff;
  color: #64748b;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}

.chart-type-btn:hover {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

.chart-type-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

/* Inline Charts */
.chat-chart-container {
  margin-top: 10px;
  padding: 16px;
  background: #f0f5ff;
  border: 1px solid rgba(37,99,235,.12);
  border-radius: 10px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.chat-chart-container canvas {
  max-width: 100% !important;
  height: auto !important;
}

/* ── Session History Panel ───────────────────────────────────── */
.chat-hist-panel {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 285px;
  background: #fff;
  border-right: 1px solid rgba(37,99,235,.13);
  box-shadow: 6px 0 28px rgba(30,58,138,.12);
  z-index: 80;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
}
.chat-hist-panel.open { transform: translateX(0); }

.chat-hist-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(37,99,235,.1);
  background: #f8faff;
  flex-shrink: 0;
}
.chat-hist-panel-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #1e3a8a;
  flex: 1;
}
.chat-hist-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
}
.chat-hist-new-btn:hover { background: #1d4ed8; }
.chat-hist-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: #94a3b8;
  cursor: pointer;
  padding: 0 2px;
}
.chat-hist-close-btn:hover { color: #475569; }

.chat-hist-uid-badge {
  padding: 6px 14px;
  font-size: 10.5px;
  color: #64748b;
  background: #f0f5ff;
  border-bottom: 1px solid rgba(37,99,235,.08);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.chat-hist-uid-badge:empty { display: none; }

.chat-hist-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.chat-hist-empty {
  padding: 36px 16px;
  text-align: center;
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.7;
}

.chat-hist-item {
  position: relative;
  padding: 10px 14px 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .12s;
}
.chat-hist-item:hover { background: #f0f5ff; }
.chat-hist-item.active {
  background: #eff6ff;
  border-left-color: #2563eb;
}
.chat-hist-item-body { padding-right: 56px; }
.chat-hist-item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.chat-hist-item.active .chat-hist-item-title { color: #1d4ed8; }
.chat-hist-item-meta {
  font-size: 10.5px;
  color: #94a3b8;
}
.chat-hist-item-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  gap: 2px;
  align-items: center;
}
.chat-hist-item:hover .chat-hist-item-actions { display: flex; }
.chat-hist-act-btn {
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
  color: #64748b;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.chat-hist-act-btn:hover { background: #dbeafe; color: #2563eb; }
.chat-hist-act-btn.del-btn:hover { background: #fee2e2; color: #dc2626; }

.chat-hist-rename-input {
  width: 100%;
  border: 1.5px solid #3b82f6;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12.5px;
  font-family: var(--font);
  outline: none;
  box-sizing: border-box;
  margin-bottom: 3px;
}
