/* ── Assistant View: Chat, SQL Cards, History Drawer & Data Visualizations ── */

/* ── Assistant Chat ──────────────────────────────────────────────────────── */
.chatwrap {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 880px;
  width: 100%;
}
.msg-u {
  align-self: flex-end;
  max-width: 78%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px 16px 4px 16px;
  padding: 12px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.msg-a {
  display: flex;
  gap: 12px;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--ok-bg);
  color: var(--ok-fg);
  display: grid;
  place-items: center;
  flex: none;
  margin-top: 2px;
}
.msg-a .body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  padding: 4px 0;
}
.step { display: flex; align-items: center; gap: 6px; }
.step.done { color: var(--ok-fg); font-weight: 500; }
.step.active { color: var(--brand-primary); font-weight: 500; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.answer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.answer p { margin: 0 0 14px; line-height: 1.65; }
.answer-foot {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-3);
}
.linkbtn {
  background: none;
  border: none;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 0;
  display: inline-flex;
  gap: 5px;
  align-items: center;
  cursor: pointer;
}
.linkbtn:hover { color: var(--brand-primary); }
details.sql { margin-top: 12px; }
details.sql summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
details.sql pre {
  background: var(--ink);
  color: #C9D6D1;
  padding: 14px;
  border-radius: var(--r);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  margin: 10px 0 0;
}
.chat-container {
  max-width: 880px;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Formatted Answer Typography & Bidirectional Support */
.answer-content {
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.65;
}
.answer-content[dir="rtl"] {
  direction: rtl;
  text-align: right;
}
.answer-content[dir="ltr"] {
  direction: ltr;
  text-align: left;
}

.ans-para {
  margin: 0 0 10px 0;
  line-height: 1.65;
}
.ans-para:last-child {
  margin-bottom: 0;
}
.ans-heading {
  margin: 10px 0 6px 0;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 700;
}
.ans-list, .ans-numbered {
  margin: 8px 0 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ans-list[dir="rtl"], .ans-numbered[dir="rtl"] {
  direction: rtl;
  text-align: right;
  padding-right: 22px;
  padding-left: 0;
}
.ans-list[dir="ltr"], .ans-numbered[dir="ltr"] {
  direction: ltr;
  text-align: left;
  padding-left: 22px;
  padding-right: 0;
}
.ans-list li, .ans-numbered li {
  line-height: 1.6;
}
.ans-para[dir="rtl"], .ans-list li[dir="rtl"], .ans-numbered li[dir="rtl"], .ans-heading[dir="rtl"] {
  direction: rtl;
  text-align: right;
}
.ans-para[dir="ltr"], .ans-list li[dir="ltr"], .ans-numbered li[dir="ltr"], .ans-heading[dir="ltr"] {
  direction: ltr;
  text-align: left;
}
bdi, .bidi-iso {
  unicode-bidi: isolate !important;
  direction: ltr !important;
  display: inline-block;
  vertical-align: baseline;
}
.msg-u[dir="rtl"] {
  direction: rtl;
  text-align: right;
}
.msg-u[dir="ltr"] {
  direction: ltr;
  text-align: left;
}
/* ── Assistant Two-Column Layout (Main Chat + Right History Sidebar) ────── */
.view.view-assistant {
  max-width: 100%;
  padding: 12px 28px 14px;
  height: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.assistant-layout {
  display: flex;
  gap: 20px;
  width: 100%;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  position: relative;
  align-items: stretch;
  overflow: hidden;
}

.assistant-main {
  flex: 1;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow: hidden;
  position: relative;
}

.assistant-main .chatwrap {
  max-width: 100%;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
  padding-bottom: 16px;
  scroll-behavior: smooth;
}

[dir="rtl"] .assistant-main .chatwrap {
  padding-right: 0;
  padding-left: 8px;
}

.assistant-main .chatwrap::-webkit-scrollbar {
  width: 6px;
}
.assistant-main .chatwrap::-webkit-scrollbar-track {
  background: transparent;
}
.assistant-main .chatwrap::-webkit-scrollbar-thumb {
  background: var(--line-strong, rgba(255, 255, 255, 0.15));
  border-radius: 3px;
}

/* Fixed Bottom Area (Always visible, never pushed below fold) */
.assistant-bottom {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  background: var(--bg);
  border-top: 1px solid var(--line-soft);
  position: relative;
  z-index: 5;
  width: 100%;
}

/* Right History Sidebar */
.assistant-history-sidebar {
  width: 320px;
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  max-height: 100%;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, width 0.25s ease;
  z-index: 10;
}

.assistant-history-sidebar.collapsed {
  display: none;
}

.history-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.history-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-sidebar-title h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.history-sidebar-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  transition: all 0.15s ease;
}

.history-sidebar-close:hover {
  color: var(--text);
  background: var(--line);
}

.history-sidebar-action {
  width: 100%;
  padding-bottom: 2px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  width: 100%;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  flex: 1;
  padding: 4px 4px 6px 2px;
}

[dir="rtl"] .history-list {
  padding: 4px 2px 6px 4px;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: start;
}

.history-item:hover {
  border-color: var(--brand-primary);
  background: var(--surface);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.history-item.active {
  border-color: var(--brand-primary);
  background: rgba(47, 143, 232, 0.08);
}

.history-item.pinned {
  border-color: rgba(234, 179, 8, 0.35);
  background: rgba(234, 179, 8, 0.03);
}
.history-item.pinned:hover {
  border-color: #eab308;
  background: rgba(234, 179, 8, 0.06);
}
.history-item.pinned.active {
  border-color: var(--brand-primary);
  background: rgba(47, 143, 232, 0.1);
}

.history-item-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
}

.history-item-icon {
  font-size: 13px;
  flex: none;
  opacity: 0.8;
  margin-top: 1px;
}

.history-pin-indicator {
  font-size: 12px;
  flex: none;
  line-height: 1;
  margin-top: 2px;
  filter: drop-shadow(0 1px 2px rgba(234, 179, 8, 0.4));
}

.history-pulse-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--brand-primary, #2F8FE8);
  margin-inline-start: auto;
  flex: none;
  margin-top: 5px;
  box-shadow: 0 0 6px rgba(47, 143, 232, 0.7);
  animation: pulse-dot-anim 1.4s ease-in-out infinite;
}

@keyframes pulse-dot-anim {
  0% { transform: scale(0.85); opacity: 0.5; }
  50% { transform: scale(1.35); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.5; }
}

.history-item-title {
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.35;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1;
  word-break: break-word;
}

.history-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 11px;
  color: var(--text-3);
  padding-top: 4px;
  border-top: 1px dashed rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .history-item-meta,
.theme-dark .history-item-meta {
  border-top-color: rgba(255, 255, 255, 0.06);
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-inline-start: auto;
}

.history-item-btn {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0.55;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  line-height: 1;
}

.history-item:hover .history-item-btn {
  opacity: 0.85;
}

.history-item-btn:hover {
  opacity: 1 !important;
}

.history-item-pin:hover {
  color: #ca8a04;
  background: rgba(234, 179, 8, 0.12);
}
[data-theme="dark"] .history-item-pin:hover,
.theme-dark .history-item-pin:hover {
  color: #facc15;
}

.history-item-pin.pinned {
  opacity: 1 !important;
  color: #ca8a04;
  background: rgba(234, 179, 8, 0.12);
}
[data-theme="dark"] .history-item-pin.pinned,
.theme-dark .history-item-pin.pinned {
  color: #facc15;
  background: rgba(234, 179, 8, 0.2);
}

.history-item-del:hover {
  opacity: 1 !important;
  color: var(--danger);
  background: var(--danger-bg);
}

.history-item-rename:hover {
  opacity: 1 !important;
  color: var(--brand-primary, #2563eb);
  background: rgba(37, 99, 235, 0.12);
}

.history-item-top .history-item-rename {
  opacity: 0;
  padding: 2px 4px;
  border-radius: 4px;
  margin-inline-start: 2px;
  flex-shrink: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.history-item:hover .history-item-top .history-item-rename {
  opacity: 0.75;
}

.history-item-top .history-item-rename:hover {
  opacity: 1 !important;
}

.history-rename-form {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.history-rename-input {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 4px;
  border: 1px solid var(--brand-primary, #2563eb);
  background: var(--bg-card, #ffffff);
  color: var(--text, #111827);
  outline: none;
  line-height: 1.35;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

[data-theme="dark"] .history-rename-input,
.theme-dark .history-rename-input {
  background: var(--bg-card, #1e293b);
  color: var(--text, #f1f5f9);
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.history-rename-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.history-rename-save {
  color: #16a34a;
  background: rgba(22, 163, 74, 0.12);
}

.history-rename-save:hover {
  color: #15803d;
  background: rgba(22, 163, 74, 0.25);
}

.history-rename-cancel {
  color: var(--text-3, #6b7280);
  background: rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .history-rename-cancel,
.theme-dark .history-rename-cancel {
  background: rgba(255, 255, 255, 0.08);
}

.history-rename-cancel:hover {
  color: var(--danger, #ef4444);
  background: var(--danger-bg, rgba(239, 68, 68, 0.15));
}

.history-section-divider {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 4px 4px;
}
.history-section-divider:not(:first-child) {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}
.history-section-divider .badge-sm {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(234, 179, 8, 0.16);
  color: #ca8a04;
}
[data-theme="dark"] .history-section-divider .badge-sm,
.theme-dark .history-section-divider .badge-sm {
  background: rgba(234, 179, 8, 0.25);
  color: #facc15;
}

/* Backdrop for Mobile / Tablet off-canvas */
.history-backdrop {
  display: none;
}


/* ── Bar Visualization ───────────────────────────────────────────────────── */
.bars { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.bar { display: flex; align-items: center; gap: 12px; }
.bar span:first-child { width: 140px; font-size: 13px; color: var(--text-2); flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bartrack { flex: 1; height: 14px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.barfill { height: 100%; border-radius: 4px; background: var(--brand-primary); }
.barval { font-family: var(--mono); font-size: 12px; color: var(--text-2); width: 64px; text-align: end; flex: none; }

/* ── Interactive Chat Charts (Chart.js) ─────────────────────────────────── */
.chat-chart-card {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.chat-chart-card:hover {
  border-color: rgba(47, 143, 232, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
}
.chat-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.chat-chart-title-area {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.chat-chart-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(47, 143, 232, 0.1);
  color: var(--brand-primary);
  flex-shrink: 0;
}
.chat-chart-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-chart-unit {
  font-size: 11.5px;
  color: var(--text-3);
  font-family: var(--mono);
  font-weight: 500;
}
.chat-chart-controls {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--line-soft);
  padding: 3px;
  border-radius: 8px;
}
.chart-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.chart-type-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.04);
}
.chart-type-btn.active {
  background: var(--surface);
  color: var(--brand-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.chat-chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 220px;
  min-height: 200px;
  max-height: 260px;
}
.chat-chart-canvas-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Clarification Chips (Interactive Turn-Based Disambiguation) ────────── */
.clarification-chips-wrapper {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bg-card, rgba(99, 102, 241, 0.04));
  border: 1px dashed var(--line-active, rgba(99, 102, 241, 0.25));
  border-radius: var(--r-md, 10px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.clarification-chips-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-primary, #6366f1);
  letter-spacing: 0.01em;
}
.clarification-chips-label svg {
  flex-shrink: 0;
}
.clarification-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.clarification-chip {
  background: var(--surface, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  color: var(--text, #1e293b);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  user-select: none;
  text-align: start;
}
.clarification-chip .chip-spark {
  color: var(--brand-primary, #6366f1);
  font-size: 11px;
  transition: transform 0.2s ease;
}
.clarification-chip:hover:not(:disabled) {
  background: var(--bg-hover, rgba(99, 102, 241, 0.08));
  border-color: var(--brand-primary, #6366f1);
  color: var(--brand-primary, #6366f1);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.15);
}
.clarification-chip:hover:not(:disabled) .chip-spark {
  transform: scale(1.25);
}
.clarification-chip:active:not(:disabled) {
  transform: translateY(0);
}
.clarification-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.clarification-chip.chip-selected {
  background: var(--brand-primary, #6366f1);
  border-color: var(--brand-primary, #6366f1);
  color: #ffffff;
  opacity: 1;
}
.clarification-chip.chip-selected .chip-spark {
  color: #ffffff;
}
.clarification-chip-custom {
  border-style: dashed;
  border-color: var(--line-active, rgba(99, 102, 241, 0.45));
  color: var(--brand-primary, #6366f1);
  background: var(--bg-hover, rgba(99, 102, 241, 0.05));
}
.clarification-chip-custom:hover:not(:disabled) {
  border-style: solid;
  background: var(--bg-hover, rgba(99, 102, 241, 0.12));
}
.clarification-custom-container {
  margin-top: 4px;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.clarification-custom-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface, #ffffff);
  border: 1px solid var(--brand-primary, #6366f1);
  border-radius: var(--r-md, 8px);
  padding: 4px 6px 4px 12px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.12);
}
.clarification-custom-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text, #1e293b);
  font-family: inherit;
}
.clarification-custom-input::placeholder {
  color: var(--text-dim, #94a3b8);
}
.clarification-custom-submit {
  background: var(--brand-primary, #6366f1);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.clarification-custom-submit:hover {
  filter: brightness(1.1);
  transform: scale(1.05);
}


