/*
 * chat.css — Styles for the main chat dashboard (index.html).
 * Depends on base.css being loaded first.
 */

/* ── Full-screen Layout ── */
html,
body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  display: flex;
  max-width: 100vw;
}

/* ── Sidebar ── */
.sidebar {
  position: relative;
  z-index: 10;
  width: var(--sidebar-width);
  flex-shrink: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: rgba(8, 8, 20, .75);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  padding: 24px 16px;
  gap: 8px;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.logo-text strong {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  color: var(--text);
}

.logo-text span {
  font-size: .68rem;
  color: var(--muted);
}

/* ── Navigation ── */
.nav-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted2);
  padding: 8px 10px 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: all .2s;
  text-decoration: none;
}

.nav-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-btn.active {
  background: rgba(245, 158, 11, .15);
  color: var(--primary);
  border: 1px solid rgba(245, 158, 11, .25);
}

.nav-btn .icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
}

/* Admin-only nav items are hidden by default; shown via JS */
.nav-btn.admin-only {
  display: none;
}

.sidebar-spacer {
  flex: 1;
}

/* ── User card at bottom of sidebar ── */
.user-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--primary-gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.user-meta strong {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text);
}

.user-meta span {
  font-size: .68rem;
  color: var(--muted);
}

.btn-signout {
  margin-top: 10px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: .75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}

.btn-signout:hover {
  background: rgba(248, 113, 113, .1);
  border-color: rgba(248, 113, 113, .35);
  color: var(--error);
}

.sidebar-footer-tools {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2px 0 10px;
  flex-shrink: 0;
}

.btn-theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

.btn-theme-toggle:hover {
  color: var(--primary);
  border-color: var(--border2);
  background: var(--surface-hover);
}

.btn-theme-toggle .theme-icon-moon {
  display: none;
}

.btn-theme-toggle .theme-icon-sun {
  display: block;
}

.light-mode .btn-theme-toggle .theme-icon-moon {
  display: block;
}

.light-mode .btn-theme-toggle .theme-icon-sun {
  display: none;
}

.light-mode .btn-theme-toggle {
  background: rgba(15, 23, 42, 0.04);
  border-color: #e2e8f0;
  color: #64748b;
}

.light-mode .btn-theme-toggle:hover {
  color: var(--primary);
  border-color: hsla(var(--p-h), var(--p-s), var(--p-l), 0.35);
  background: hsla(var(--p-h), var(--p-s), var(--p-l), 0.08);
}

/* ── Main Content Area ── */
.main {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  flex-direction: row;   /* row: history panel + chat wrapper side by side */
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

/* ── History Panel ── */
.history-panel {
  width: 256px;
  flex-shrink: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: rgba(8, 8, 20, .65);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
  transition: width .25s cubic-bezier(.4,0,.2,1), opacity .2s;
  overflow: hidden;
}

.history-panel.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.history-panel-title {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted2);
}

.history-new-btn {
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(245, 158, 11, .1);
  border: 1px solid rgba(245, 158, 11, .25);
  border-radius: 7px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all .2s;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.history-new-btn:hover {
  background: rgba(245, 158, 11, .2);
  border-color: rgba(245, 158, 11, .5);
}

.history-search-wrap {
  padding: 10px 12px 8px;
  flex-shrink: 0;
}

.history-search-input {
  width: 100%;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: 'Inter', sans-serif;
  font-size: .78rem;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
  box-sizing: border-box;
}

.history-search-input:focus {
  border-color: rgba(245, 158, 11, .5);
}

.history-search-input::placeholder {
  color: var(--muted2);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 12px;
}

.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

.history-group-label {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted2);
  padding: 10px 14px 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 8px;
  margin: 1px 6px;
  transition: background .15s;
  position: relative;
  min-width: 0;
}

.history-item:hover {
  background: rgba(255, 255, 255, .05);
}

.history-item.active {
  background: rgba(245, 158, 11, .12);
  border: 1px solid rgba(245, 158, 11, .2);
}

.history-item-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted2);
  flex-shrink: 0;
}

.history-item.active .history-item-dot {
  background: var(--primary);
}

.history-item-info {
  flex: 1;
  min-width: 0;
}

.history-item-title {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.history-item.active .history-item-title {
  color: var(--primary);
}

.history-item-time {
  font-size: .62rem;
  color: var(--muted2);
  margin-top: 2px;
}

.history-item-btn {
  opacity: 0;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
  color: var(--muted);
  appearance: none;
  -webkit-appearance: none;
}

.history-item-btn-icon {
  font-size: 13px;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.history-item:hover .history-item-btn,
.history-item-btn:focus-visible {
  opacity: 1;
}

.history-item-btn-danger:hover {
  color: var(--error);
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
}

.light-mode .history-item-btn {
  background: rgba(15, 23, 42, 0.05);
  border-color: #e2e8f0;
  color: #64748b;
}

.light-mode .history-item-btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--error);
}

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  gap: 6px;
  text-align: center;
  color: var(--muted2);
  font-size: .75rem;
  line-height: 1.5;
}

/* ── History Toggle Button (in topbar) ── */
.history-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}

.history-toggle-btn:hover {
  background: rgba(245, 158, 11, .12);
  border-color: rgba(245, 158, 11, .3);
  color: var(--primary);
}

/* ── Chat Wrapper (flex column: topbar + chat + input) ── */
.chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

/* ── Session replay: historical message footer ── */
.msg-history-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn-rerun-question {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(245, 158, 11, .1);
  border: 1px solid rgba(245, 158, 11, .25);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all .2s;
}

.btn-rerun-question:hover {
  background: rgba(245, 158, 11, .2);
  border-color: rgba(245, 158, 11, .5);
}

.history-replay-badge {
  font-size: .65rem;
  color: var(--muted2);
  font-style: italic;
}



/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(8, 8, 20, .6);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: .95rem;
  font-weight: 600;
}

.topbar-sub {
  font-size: .72rem;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.company-badge {
  font-size: .72rem;
  font-weight: 600;
  background: rgba(245, 158, 11, .15);
  border: 1px solid rgba(245, 158, 11, .3);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .5
  }
}

/* ── Chat Scroll Area ── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
  width: 4px;
}

.chat-area::-webkit-scrollbar-track {
  background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .1);
  border-radius: 4px;
}

/* ── Welcome Screen ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px;
  gap: 16px;
}

.welcome-icon {
  font-size: 48px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0)
  }

  50% {
    transform: translateY(-8px)
  }
}

.welcome h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.welcome p {
  font-size: .88rem;
  color: var(--muted);
  max-width: 380px;
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.suggestion {
  padding: 8px 14px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  font-size: .78rem;
  color: var(--muted);
  cursor: pointer;
  transition: all .2s;
  font-family: 'Inter', sans-serif;
}

.suggestion:hover {
  background: rgba(245, 158, 11, .12);
  border-color: rgba(245, 158, 11, .35);
  color: var(--primary);
}

/* ── Message Rows ── */
.msg-row {
  display: flex;
  gap: 12px;
  animation: msg-in .3s cubic-bezier(.34, 1.56, .64, 1) both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(12px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.msg-row.user-row {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-row.user-row .msg-avatar {
  background: var(--primary-gradient);
  box-shadow: 0 2px 12px var(--primary-glow);
}

.msg-row.ai-row .msg-avatar {
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--border);
}

.msg-body {
  max-width: 72%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row.user-row .msg-body {
  align-items: flex-end;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: .875rem;
  line-height: 1.65;
  word-break: break-word;
}

.msg-row.user-row .msg-bubble {
  background: var(--primary-gradient);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.msg-row.ai-row .msg-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.msg-time {
  font-size: .65rem;
  color: var(--muted2);
}

.msg-row.user-row .msg-time {
  text-align: right;
}

.cache-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .65rem;
  font-weight: 600;
  color: var(--warn);
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .25);
  border-radius: 10px;
  padding: 2px 8px;
  margin-top: 4px;
}

/* ── Typing Indicator ── */
.typing-bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing .9s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: .2s;
}

.typing-dot:nth-child(3) {
  animation-delay: .4s;
}

@keyframes typing {

  0%,
  80%,
  100% {
    transform: scale(1);
    opacity: .4
  }

  40% {
    transform: scale(1.2);
    opacity: 1
  }
}

/* ── Data Results Table Card ── */
.data-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 8px;
}

.data-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.data-card-header:hover {
  color: var(--text);
}

.data-table-wrap {
  overflow-x: auto;
  max-height: 200px;
  overflow-y: auto;
}

.data-table-wrap::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.data-table-wrap::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
}

.data-table-wrap::-webkit-scrollbar-thumb {
  background: rgba(245, 158, 11, 0.45);
  border-radius: 4px;
  border: 1.5px solid rgba(20, 20, 35, 0.95);
}

.data-table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(245, 158, 11, 0.7);
}


table {
  width: 100%;
  border-collapse: collapse;
  font-size: .75rem;
}

th {
  padding: 8px 12px;
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  background: rgba(255, 255, 255, .03);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th.num {
  text-align: right;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
  color: var(--text);
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(255, 255, 255, .02);
}

/* ── Chart Card ── */
.chart-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-top: 8px;
  height: 240px;
  position: relative;
}

/* ── AI Formatted Text ── */
.msg-bubble.ai-text p {
  margin: 0 0 8px;
}

.msg-bubble.ai-text p:last-child {
  margin-bottom: 0;
}

.msg-bubble.ai-text ul,
.msg-bubble.ai-text ol {
  padding-left: 18px;
  margin: 6px 0 8px;
}

.msg-bubble.ai-text li {
  margin: 3px 0;
  line-height: 1.6;
}

.msg-bubble.ai-text strong {
  color: #e2e8f0;
  font-weight: 600;
}

.msg-bubble.ai-text em {
  font-style: italic;
  color: #cbd5e1;
}

.msg-bubble.ai-text h3,
.msg-bubble.ai-text h4,
.msg-bubble.ai-text h5 {
  color: #e2e8f0;
  font-weight: 700;
  font-size: .88rem;
  margin: 14px 0 6px;
  padding: 8px 0 8px 12px;
  border-top: 1px solid rgba(255, 255, 255, .07);
  border-left: 3px solid rgba(245, 158, 11, .65);
  letter-spacing: .01em;
  border-radius: 0 4px 4px 0;
}

.msg-bubble.ai-text h3:first-child,
.msg-bubble.ai-text h4:first-child,
.msg-bubble.ai-text h5:first-child {
  margin-top: 0;
}

.msg-bubble.ai-text br {
  display: block;
  content: '';
  margin: 2px 0;
}

/* ── KPI Card ── */
.kpi-card {
  background: #23180f;
  border: 1px solid rgba(245, 158, 11, .25);
  border-radius: 12px;
  padding: 20px 24px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.kpi-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}

/* ── Chat Input Bar ── */
.input-bar {
  flex-shrink: 0;
  padding: 16px 24px;
  background: rgba(8, 8, 20, .7);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: rgba(255, 255, 255, .05);
  border: 1.5px solid var(--border2);
  border-radius: 14px;
  padding: 10px 12px;
  transition: border-color .2s, box-shadow .2s;
}

.input-wrap:focus-within {
  border-color: rgba(245, 158, 11, .6);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

#question {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: .88rem;
  resize: none;
  max-height: 120px;
  min-height: 22px;
  line-height: 1.5;
}

#question::placeholder {
  color: var(--muted2);
}

#question::-webkit-scrollbar {
  width: 3px;
}

#question::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .1);
  border-radius: 3px;
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-gradient);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all .2s;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-send:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  font-size: .65rem;
  color: var(--muted2);
  margin-top: 6px;
  padding-left: 4px;
}

/* ── Mobile navigation (hamburger + slide-out sidebar) ── */
.mobile-nav-toggle {
  display: none !important;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s, border-color 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-toggle:hover {
  background: rgba(245, 158, 11, .12);
  border-color: rgba(245, 158, 11, .3);
  color: var(--primary);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1040;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

body.mobile-nav-open .sidebar-backdrop {
  display: block;
}

body.mobile-nav-open {
  overflow: hidden;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .mobile-nav-toggle {
    display: inline-flex !important;
  }

  .sidebar {
    display: flex !important;
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-width), 78vw);
    height: 100dvh;
    z-index: 1050;
    transform: translateX(-105%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0) !important;
  }

  .main {
    width: 100%;
    min-width: 0;
  }

  .topbar {
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    gap: 8px;
  }

  .topbar-left {
    gap: 8px;
    min-width: 0;
    flex: 1;
  }

  .topbar-title {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-sub {
    display: none;
  }

  .topbar-right {
    gap: 6px;
    flex-shrink: 0;
  }

  .topbar-right .topbar-btn {
    padding: 4px 8px !important;
    margin-right: 0 !important;
    font-size: 0 !important;
  }

  .topbar-right .topbar-btn .icon {
    font-size: 14px;
  }

  .company-badge {
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 4px 8px;
    font-size: 0.68rem;
  }

  .chat-area {
    padding: 12px;
  }

  .input-bar {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }

  .input-wrap {
    padding: 8px 10px;
  }

  #question {
    font-size: 16px;
  }

  .msg-body {
    max-width: 92%;
  }

  .welcome h2 {
    font-size: 1.2rem;
  }

  .welcome p {
    font-size: 0.82rem;
  }

  .suggestions {
    gap: 8px;
  }

  .suggestion {
    font-size: 0.78rem;
    padding: 8px 12px;
  }

  .dashboard-topbar {
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top, 0px));
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
  }

  .dashboard-topbar .mobile-nav-toggle {
    margin-top: 2px;
    flex-shrink: 0;
  }

  .dashboard-topbar-left h1 {
    font-size: 1rem;
  }

  .dashboard-topbar-left p {
    display: none;
  }

  .dashboard-topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* ── Report Toolbar ── */
.report-toolbar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.report-toolbar .btn-secondary {
  padding: 6px 12px;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: all .2s;
}

.report-toolbar .btn-secondary:hover {
  background: rgba(245, 158, 11, .15);
  border-color: rgba(245, 158, 11, .4);
  color: #fbbf24;
}

.chart-type-selector {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  outline: none;
}

.chart-type-selector option {
  background: var(--bg);
  color: var(--text);
}

/* ── BULLETPROOF PRINT STYLES ── */
@media print {

  /* 1. Clean the base canvas */
  html,
  body {
    background: white !important;
    color: black !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* 2. EXPLICITLY Hide all application UI shells (Sidebar, Topbar, Folders, etc) */
  body.print-mode-active .bg-orb,
  body.print-mode-active .sidebar,
  body.print-mode-active .topbar,
  body.print-mode-active .input-bar,
  body.print-mode-active .folders-sidebar,
  body.print-mode-active .reports-grid,
  body.print-mode-active .report-toolbar,
  body.print-mode-active .btn-back,
  body.print-mode-active .toast-container {
    display: none !important;
  }

  /* 3. Unroll all layout flexboxes into block elements to allow multi-page flow */
  .app-container,
  .main-content,
  .main,
  .reports-layout,
  .reports-main,
  .report-viewer,
  .chat-container,
  .chat-area {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* 4. Hide all chat messages except the active one */
  body.print-mode-active .msg-row {
    display: none !important;
  }

  body.print-mode-active .msg-row.is-printing-msg-row {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* 5. Strip chat bubble styling to look like a document paragraph */
  body.print-mode-active .msg-row.is-printing-msg-row .msg-body {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
  }

  body.print-mode-active .msg-row.is-printing-msg-row .msg-bubble {
    background: transparent !important;
    color: black !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    font-size: 11pt !important;
    line-height: 1.6 !important;
  }

  /* 6. Header Styling (Reports Page) */
  .viewer-header {
    display: block !important;
    background: transparent !important;
    border-bottom: 2px solid black !important;
    padding: 0 0 10px 0 !important;
    margin: 0 0 20px 0 !important;
  }

  .viewer-header h2 {
    color: black !important;
    font-size: 24pt !important;
    font-family: serif !important;
    margin: 0 !important;
  }

  /* 7. Header Styling (Chat Page Injected) */
  .print-only-header {
    display: block !important;
    border-bottom: 2px solid black !important;
    padding-bottom: 10px !important;
    margin-bottom: 20px !important;
    font-family: serif !important;
    font-size: 24pt !important;
    color: black !important;
    font-weight: bold;
  }

  /* 8. Table and Chart Formats */
  .is-printing-now * {
    color: black !important;
    border-color: #cbd5e1 !important;
  }

  .is-printing-now .data-table-wrap {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
  }

  .is-printing-now table {
    width: 100% !important;
  }

  .is-printing-now th {
    background: #f1f5f9 !important;
    border-bottom: 2px solid #94a3b8 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-weight: bold !important;
    padding: 8px !important;
  }

  .is-printing-now td {
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 8px !important;
  }

  .is-printing-now .data-card,
  .is-printing-now .kpi-card {
    background: white !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: none !important;
    margin-bottom: 20px !important;
  }

  .is-printing-now canvas {
    max-width: 100% !important;
    page-break-inside: avoid;
    margin: 20px 0 !important;
  }
}

/* ── LIGHT MODE CHAT OVERRIDES ── */
.light-mode .input-bar {
  background: rgba(255, 255, 255, 0.8);
  border-top: 1px solid #e2e8f0;
}

.light-mode .input-wrap {
  background: white;
  border-color: #cbd5e1;
}

.light-mode #question {
  color: #0f172a;
}

.light-mode .msg-row.ai-row .msg-bubble {
  background: white !important;
  border-color: #e2e8f0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
}

.light-mode .msg-bubble.ai-text strong {
  color: #0f172a;
}

.light-mode .msg-bubble.ai-text em {
  color: #334155;
}

.light-mode .msg-bubble.ai-text h3,
.light-mode .msg-bubble.ai-text h4,
.light-mode .msg-bubble.ai-text h5 {
  color: #0f172a;
  border-top-color: #f1f5f9;
  background: rgba(15, 23, 42, 0.02);
}

.light-mode .data-card,
.light-mode .chart-card,
.light-mode .kpi-card {
  background: white !important;
  border-color: #e2e8f0;
}

.light-mode .kpi-label {
  color: #64748b;
}

.light-mode .kpi-value {
  color: #0f172a;
}

/* .light-mode th and .light-mode td are defined in base.css */

/* ── LIGHT MODE — History Panel ── */
.light-mode .history-panel {
  background: rgba(248, 250, 252, .92) !important;
  border-right-color: #e2e8f0;
}

.light-mode .history-panel-header {
  border-bottom-color: #e2e8f0;
}

.light-mode .history-search-input {
  background: white;
  border-color: #cbd5e1;
  color: #0f172a;
}

.light-mode .history-search-input::placeholder { color: #94a3b8; }

.light-mode .history-item:hover {
  background: rgba(15, 23, 42, .04);
}

.light-mode .history-item.active {
  background: rgba(245, 158, 11, .08);
}

.light-mode .history-item-title { color: #0f172a; }
.light-mode .history-item-time  { color: #94a3b8; }
.light-mode .history-group-label { color: #94a3b8; }
.light-mode .history-panel-title { color: #64748b; }

/* ── Responsive — hide history panel on mobile ── */
@media (max-width: 900px) {
  .history-panel {
    display: none;
  }
  .history-toggle-btn {
    display: none;
  }
}
