:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-alt: #f7f9fc;
  --border: #d8e0ec;
  --text: #132238;
  --muted: #6a778b;
  --primary: #4f46e5;
  --primary-soft: #ecebff;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
}
body { min-height: 100vh; }
button, textarea, input { font: inherit; }

.synergy-shell { padding: 22px; }

.dashboard-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 20px;
  align-items: start;
}

.dashboard-shell.chat-collapsed {
  grid-template-columns: minmax(0, 1fr) 0;
}

.analytics-stage { min-width: 0; }

.card-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding: 22px 24px;
  border-radius: 28px;
  background: linear-gradient(135deg, #0f172a, #243b53 55%, #3b82f6);
  color: #fff;
}

.eyebrow,
.viz-label,
.chat-kicker {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 11px;
  opacity: .75;
}

.hero-bar h1,
.chat-panel h2 {
  margin: 0;
  font-size: 28px;
}

.hero-subtitle {
  margin: 8px 0 0;
  max-width: 780px;
  color: rgba(255,255,255,.82);
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  font-weight: 600;
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(79,70,229,.28);
}

.ghost-btn {
  background: rgba(255,255,255,.12);
  color: #fff;
  padding: 12px 16px;
  border: 1px solid rgba(255,255,255,.18);
}

.ask-strip .ghost-btn {
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.icon-btn {
  width: 40px;
  height: 40px;
  background: var(--surface-alt);
  color: var(--text);
}

.ask-strip {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 180px;
  gap: 16px;
  align-items: stretch;
  padding: 18px;
  margin-bottom: 18px;
}

.ask-strip__icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-soft), #dbeafe);
  color: var(--primary);
  font-size: 20px;
}

.ask-strip__body label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

#queryBox {
  width: 100%;
  min-height: 104px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-alt);
  padding: 16px 18px;
  resize: vertical;
  color: var(--text);
  outline: none;
}

#queryBox:focus,
#tableSearch:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79,70,229,.1);
}

.ask-strip__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card {
  padding: 18px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-card h3 {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.metric-card .metric-value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 10px;
}

.metric-card .metric-sub {
  color: var(--muted);
  font-size: 13px;
}

.placeholder-card {
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  border-style: dashed;
  background: rgba(255,255,255,.5);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.viz-card {
  padding: 18px;
  min-width: 0;
}

.viz-card--wide,
.viz-card--full {
  grid-column: span 2;
}

.viz-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 10px;
}

.viz-card__head h3 {
  margin: 0;
  font-size: 18px;
}

.viz-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.chart-slot {
  width: 100%;
  height: 300px;
}

.empty-state {
  height: 100%;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 18px;
  background: var(--surface-alt);
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#tableSearch {
  min-width: 260px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 14px;
  background: var(--surface-alt);
  outline: none;
}

.table-shell {
  overflow: auto;
  max-height: 480px;
  border: 1px solid var(--border);
  border-radius: 18px;
}

#data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 900px;
}

#data-table thead th {
  position: sticky;
  top: 0;
  background: #0f172a;
  color: #fff;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 14px 12px;
  text-align: left;
  z-index: 1;
}

#data-table tbody td {
  padding: 13px 12px;
  border-bottom: 1px solid #edf2f7;
  color: #243243;
  font-size: 14px;
}

#data-table tbody tr:nth-child(even) { background: #fafcff; }
#data-table tbody tr:hover { background: #f2f6ff; }

.chat-panel {
  position: sticky;
  top: 20px;
  padding: 18px;
  min-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.chat-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.chat-thread {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message-bubble {
  max-width: 90%;
  padding: 14px 15px;
  border-radius: 18px;
  white-space: pre-wrap;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #5b4ff7, #6d7cff);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.message.assistant .message-bubble {
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.chat-summary {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-alt);
  padding: 14px;
}

.chat-summary__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.summary-content {
  white-space: pre-wrap;
  font-size: 13px;
  color: #334155;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.idle { background: #eef2ff; color: #4338ca; }
.status-pill.loading { background: #fff7ed; color: #c2410c; }
.status-pill.ready { background: #ecfdf3; color: #166534; }
.status-pill.error { background: #fef2f2; color: #991b1b; }

.reopen-chat-btn {
  position: fixed;
  right: 20px;
  top: 100px;
  z-index: 20;
  display: none;
  background: #0f172a;
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  gap: 8px;
  align-items: center;
}

.dashboard-shell.chat-collapsed + .reopen-chat-btn,
.dashboard-shell.chat-collapsed ~ .reopen-chat-btn {
  display: inline-flex;
}

.dashboard-shell.chat-collapsed .chat-panel {
  display: none;
}

.mobile-only { display: none; }

@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-shell { grid-template-columns: minmax(0, 1fr) 360px; }
}

@media (max-width: 1024px) {
  .dashboard-shell,
  .dashboard-shell.chat-collapsed {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    min-height: auto;
    position: static;
  }

  .chart-grid { grid-template-columns: 1fr; }
  .viz-card--wide,
  .viz-card--full { grid-column: span 1; }

  .ask-strip { grid-template-columns: 1fr; }
  .ask-strip__icon { display: none; }
  .ask-strip__actions { flex-direction: row; }
  .reopen-chat-btn { bottom: 20px; top: auto; }
  .mobile-only { display: inline-flex; }
}

@media (max-width: 640px) {
  .synergy-shell { padding: 14px; }
  .hero-bar { padding: 18px; flex-direction: column; }
  .kpi-grid { grid-template-columns: 1fr; }
  #tableSearch { min-width: 100%; }
  .table-tools { width: 100%; flex-direction: column; align-items: stretch; }
}