/* ReportGenAI — Enterprise Dashboard */

.dashboard-shell {
  background: #f4f6f9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 520px;
  color: #1e293b;
  --dash-primary: #6366f1;
}

.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}

.dashboard-toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dashboard-title-input {
  font-size: 1.125rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: #0f172a;
  min-width: 200px;
  padding: 0.25rem 0;
}

.dashboard-title-input:focus { outline: none; border-bottom: 2px solid var(--primary); }

.dashboard-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn-dash {
  padding: 0.625rem 1rem;
  min-height: 40px;
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-dash:hover { border-color: var(--dash-primary, var(--primary)); color: var(--dash-primary, var(--primary)); }
.btn-dash-primary { background: var(--dash-primary, var(--primary)); color: #fff; border-color: var(--dash-primary, var(--primary)); }
.btn-dash-primary:hover { filter: brightness(0.92); color: #fff; }

.slicers-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}

.slicer { display: flex; flex-direction: column; gap: 0.25rem; min-width: 140px; }

.slicer label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.slicer select {
  padding: 0.4375rem 0.625rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.8125rem;
  background: #fff;
  color: #334155;
}

.slicer-remove {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1rem;
}

.slicer-remove:hover { color: #ef4444; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1rem;
  padding: 1.25rem;
}

.widget {
  background: #fff;
  border: 1px solid #e8ecf1;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  position: relative;
  transition: box-shadow 0.2s;
}

.widget:hover { box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); }

.widget.col-4 { grid-column: span 4; }
.widget.col-6 { grid-column: span 6; }
.widget.col-8 { grid-column: span 8; }
.widget.col-12 { grid-column: span 12; }

@media (max-width: 1024px) {
  .widget.col-4, .widget.col-6, .widget.col-8 { grid-column: span 12; }
}

.widget-meta { font-size: 0.6875rem; color: #94a3b8; }
.widget-title { font-size: 0.875rem; font-weight: 600; color: #334155; margin: 0; }

.widget-menu-btn {
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0;
  border-radius: 8px;
  font-size: 1.125rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.widget-menu-btn:hover { background: #f1f5f9; color: #475569; }

.widget-body { padding: 0.5rem 1rem 1rem; }

.widget-chart-wrap { position: relative; height: 200px; }
.widget-chart-wrap.tall { height: 260px; }
.widget-chart-wrap.short { height: 140px; }

.kpi-value {
  font-size: 2rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.kpi-value.accent-blue { color: #2563eb; }
.kpi-value.accent-green { color: #059669; }
.kpi-value.accent-purple { color: #7c3aed; }

.kpi-sparkline { height: 48px; margin-top: 0.75rem; }

.multi-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.multi-kpi-item { text-align: center; }
.multi-kpi-item .kpi-value { font-size: 1.375rem; }
.multi-kpi-label {
  font-size: 0.6875rem;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 0.25rem;
}

.widget-insight {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f1f5f9;
}

.widget-dropdown {
  position: absolute;
  top: 2.5rem;
  right: 0.75rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  z-index: 20;
  min-width: 180px;
  display: none;
}

.widget-dropdown.open { display: block; }

.widget-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.625rem 1rem;
  border: none;
  background: none;
  font-size: 0.8125rem;
  color: #334155;
  cursor: pointer;
  font-family: inherit;
}

.widget-dropdown button:hover { background: #f8fafc; }
.widget-dropdown button.danger { color: #ef4444; }

.theme-panel {
  padding: 1rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: none;
}

.theme-panel.open { display: block; }

.theme-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }

.theme-field label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.color-swatches { display: flex; gap: 0.375rem; flex-wrap: wrap; }

.color-swatch {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
}

.output-empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-dim);
}

.generating-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  gap: 1rem;
  color: var(--text-muted);
}

.generating-overlay .loading-spinner { width: 40px; height: 40px; border-width: 3px; }

.report-output.has-dashboard {
  display: block;
  padding: 0;
  background: transparent;
  border: none;
  min-height: auto;
  white-space: normal;
}

.panel-output { padding: 0 !important; overflow: hidden; }

.layout-generate-full { display: block !important; }

.layout-generate-full .generate-config { margin-bottom: 1.5rem; }

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 1200px) { .config-grid { grid-template-columns: 1fr; } }

.widget-edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Drag & drop grid ── */
.widget-drag-handle {
  cursor: grab;
  color: #94a3b8;
  font-size: 1.125rem;
  padding: 0.25rem;
  user-select: none;
  flex-shrink: 0;
}

.widget-drag-handle:active { cursor: grabbing; }

.widget-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 1rem 1rem 0.5rem;
}

.widget-header-main { flex: 1; min-width: 0; }

.widget-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.widget-inline-color {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  cursor: pointer;
}

.widget-inline-color input[type="color"] {
  width: 36px;
  height: 36px;
  border: none;
  padding: 0;
  margin: -4px;
  cursor: pointer;
}

.widget.dragging { opacity: 0.45; transform: scale(0.98); }
.widget.drag-over { outline: 2px dashed var(--dash-primary, #6366f1); outline-offset: 2px; }

/* ── Dark theme (default) ── */
.dashboard-shell.theme-dark {
  background: #0f1219;
  color: #e2e8f0;
}

.dashboard-shell.theme-dark .dashboard-toolbar,
.dashboard-shell.theme-dark .slicers-bar,
.dashboard-shell.theme-dark .theme-panel {
  background: #141820;
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.dashboard-shell.theme-dark .dashboard-title-input { color: #f1f5f9; }

.dashboard-shell.theme-dark .btn-dash {
  background: #1a1f2e;
  border-color: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}

.dashboard-shell.theme-dark .slicer select {
  background: #1a1f2e;
  border-color: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.dashboard-shell.theme-dark .widget {
  background: #141820;
  border-color: rgba(255, 255, 255, 0.08);
}

.dashboard-shell.theme-dark .widget-title { color: #f1f5f9; }
.dashboard-shell.theme-dark .widget-insight { color: #94a3b8; border-top-color: rgba(255,255,255,0.06); }
.dashboard-shell.theme-dark .widget-dropdown { background: #1a1f2e; border-color: rgba(255,255,255,0.1); }
.dashboard-shell.theme-dark .widget-dropdown button { color: #e2e8f0; }
.dashboard-shell.theme-dark .widget-dropdown button:hover { background: rgba(255,255,255,0.05); }
.dashboard-shell.theme-dark .widget-menu-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }
.dashboard-shell.theme-dark .widget-inline-color { border-color: rgba(255,255,255,0.15); }
.dashboard-shell.theme-dark .theme-field select,
.dashboard-shell.theme-dark .theme-field input[type="color"] {
  background: #1a1f2e;
  border: 1px solid rgba(255,255,255,0.1);
  color: #e2e8f0;
  border-radius: 6px;
  padding: 0.375rem;
}

.dashboard-shell.theme-dark .gauge-value-text { color: #f1f5f9; }
.gauge-value-text { text-align: center; font-size: 1.5rem; font-weight: 800; color: #334155; }

/* PDF export — fixed desktop grid, hide interactive chrome */
.rg-pdf-export-wrap {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99998;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
  width: 1400px;
}

.pdf-export-mode {
  width: 1400px !important;
  max-width: 1400px !important;
  background: #0f1219;
}

.pdf-export-mode.theme-light { background: #f8fafc; }

.pdf-export-mode .dashboard-toolbar .dashboard-actions,
.pdf-export-mode .widget-drag-handle,
.pdf-export-mode .widget-header-actions,
.pdf-export-mode .widget-menu-btn,
.pdf-export-mode .widget-dropdown,
.pdf-export-mode .widget-inline-color,
.pdf-export-mode .slicer-remove,
.pdf-export-mode .theme-panel,
.pdf-export-mode .btn-dash { display: none !important; }

.pdf-export-mode .dashboard-toolbar {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.pdf-export-mode .pdf-export-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #f1f5f9;
}

.pdf-export-mode.theme-light .pdf-export-title { color: #0f172a; }

.pdf-export-mode .dashboard-grid {
  display: grid !important;
  grid-template-columns: repeat(12, 1fr) !important;
  gap: 1rem;
  padding: 1.25rem;
  width: 100%;
}

.pdf-export-mode .widget.col-4 { grid-column: span 4 !important; }
.pdf-export-mode .widget.col-6 { grid-column: span 6 !important; }
.pdf-export-mode .widget.col-8 { grid-column: span 8 !important; }
.pdf-export-mode .widget.col-12 { grid-column: span 12 !important; }

.pdf-export-mode .widget {
  break-inside: avoid;
  page-break-inside: avoid;
}

.pdf-export-mode .widget-header {
  padding: 0.75rem 1rem 0;
}

.pdf-export-mode .widget-drag-handle { display: none !important; }

.pdf-export-mode .widget-meta { font-size: 0.625rem; }

.pdf-export-chart-img { max-width: 100%; height: auto; }

/* ——— AI Insights panel ——— */
.ai-insights-wrap {
  padding: 0 1.25rem 0.75rem;
}

.ai-insights-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  overflow: hidden;
}

.dashboard-shell.theme-dark .ai-insights-panel {
  background: #141820;
  border-color: rgba(255, 255, 255, 0.08);
}

.ai-insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}

.dashboard-shell.theme-dark .ai-insights-header {
  background: linear-gradient(180deg, #1a2030 0%, #141820 100%);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.ai-insights-title h3 {
  margin: 0.25rem 0 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.dashboard-shell.theme-dark .ai-insights-title h3 { color: #f1f5f9; }

.ai-insights-badge {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #0071e3;
  background: rgba(0, 113, 227, 0.1);
  padding: 0.2rem 0.5rem;
  border-radius: 980px;
}

.ai-insights-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  color: #64748b;
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.2s;
}

.dashboard-shell.theme-dark .ai-insights-toggle {
  background: #1c2434;
  border-color: rgba(255, 255, 255, 0.1);
  color: #94a3b8;
}

.ai-insights-panel.is-collapsed .ai-insights-toggle { transform: rotate(-90deg); }
.ai-insights-panel.is-collapsed .ai-insights-body { display: none; }
.ai-insights-panel.is-collapsed .ai-insights-header { border-bottom: none; }

.ai-insights-body {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 0;
}

.ai-insights-summary,
.ai-insights-findings,
.ai-insights-actions {
  padding: 1rem 1.125rem;
}

.ai-insights-findings,
.ai-insights-actions {
  border-left: 1px solid #e2e8f0;
}

.dashboard-shell.theme-dark .ai-insights-findings,
.dashboard-shell.theme-dark .ai-insights-actions {
  border-left-color: rgba(255, 255, 255, 0.08);
}

.ai-insights-body h4 {
  margin: 0 0 0.625rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.ai-insights-summary p {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: #334155;
}

.dashboard-shell.theme-dark .ai-insights-summary p { color: #cbd5e1; }

.ai-insights-findings ul,
.ai-insights-actions ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.ai-insight-finding {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  font-size: 0.75rem;
  line-height: 1.45;
  padding: 0.5rem 0.625rem;
  border-radius: 8px;
  background: #f8fafc;
  border-left: 3px solid #94a3b8;
}

.ai-insight-finding strong { color: #0f172a; font-size: 0.75rem; }
.ai-insight-finding span { color: #64748b; }
.ai-insight-finding--alert { border-left-color: #ef4444; background: rgba(239, 68, 68, 0.06); }
.ai-insight-finding--positive { border-left-color: #22c55e; background: rgba(34, 197, 94, 0.06); }
.ai-insight-finding--info { border-left-color: #0071e3; background: rgba(0, 113, 227, 0.06); }

.dashboard-shell.theme-dark .ai-insight-finding { background: rgba(255, 255, 255, 0.04); }
.dashboard-shell.theme-dark .ai-insight-finding strong { color: #f1f5f9; }
.dashboard-shell.theme-dark .ai-insight-finding span { color: #94a3b8; }

.ai-insight-improve {
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  font-size: 0.75rem;
  line-height: 1.45;
}

.ai-insight-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #0071e3;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.ai-insight-improve strong { display: block; color: #0f172a; margin-bottom: 0.125rem; }
.ai-insight-improve p { margin: 0; color: #64748b; }
.dashboard-shell.theme-dark .ai-insight-improve strong { color: #f1f5f9; }
.dashboard-shell.theme-dark .ai-insight-improve p { color: #94a3b8; }

.ai-insights-footnote {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0.625rem 1.125rem 0.875rem;
  font-size: 0.6875rem;
  color: #94a3b8;
  border-top: 1px solid #e2e8f0;
}

.dashboard-shell.theme-dark .ai-insights-footnote {
  border-top-color: rgba(255, 255, 255, 0.08);
}

.pdf-export-mode .ai-insights-toggle { display: none !important; }
.pdf-export-mode .ai-insights-panel.is-collapsed .ai-insights-body { display: grid !important; }

@media (max-width: 1100px) {
  .ai-insights-body { grid-template-columns: 1fr; }
  .ai-insights-findings,
  .ai-insights-actions {
    border-left: none;
    border-top: 1px solid #e2e8f0;
  }
  .dashboard-shell.theme-dark .ai-insights-findings,
  .dashboard-shell.theme-dark .ai-insights-actions {
    border-top-color: rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 768px) {
  .ai-insights-wrap { padding: 0 0.75rem 0.75rem; }
}


