/* Dashboard Analytics — D.1 */

.dash-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
}
.dash-filters label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.dash-filters select,
.dash-filters input[type="date"] {
  width: auto;
  min-width: 130px;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 6px;
}
.dash-filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dash-period-presets {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}
.dash-period-presets button {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.15s;
}
.dash-period-presets button:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.dash-period-presets button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* KPI Cards */
.dash-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
.kpi-card.kpi-conversations::before { background: var(--primary); }
.kpi-card.kpi-duration::before { background: var(--dm-teal); }
.kpi-card.kpi-messages::before { background: var(--dm-yellow); }
.kpi-card.kpi-ended::before { background: var(--dm-green); }

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.kpi-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
}
.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.kpi-conversations .kpi-icon { background: var(--primary-light); }
.kpi-duration .kpi-icon { background: #e0faf8; }
.kpi-messages .kpi-icon { background: #fef9c3; }
.kpi-ended .kpi-icon { background: #dcfce7; }

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 6px;
}
.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.kpi-change.up {
  color: #166534;
  background: #dcfce7;
}
.kpi-change.down {
  color: #991b1b;
  background: #fee2e2;
}
.kpi-change.neutral {
  color: var(--text-light);
  background: var(--bg);
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 2px;
}

/* Chart Grid */
.dash-charts {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}
.dash-chart-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.dash-chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dash-chart-title svg {
  width: 16px;
  height: 16px;
  color: var(--primary);
}

/* Bottom row */
.dash-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

/* Recent table */
.dash-recent-table {
  font-size: 13px;
}
.dash-recent-table td {
  padding: 10px 12px;
}
.dash-recent-table .conv-link {
  color: var(--primary);
  font-family: monospace;
  font-size: 12px;
  text-decoration: none;
}
.dash-recent-table .conv-link:hover {
  text-decoration: underline;
}
.dash-contact-name {
  font-size: 12px;
  color: var(--text-light);
}

/* Loading skeleton */
.dash-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-light);
  font-size: 14px;
}
.dash-loading .loader {
  margin-right: 8px;
}

/* Empty state */
.dash-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-size: 14px;
}

/* D.2 — Dashboard selector */
.dash-board-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.dash-board-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dash-board-selector select {
  width: auto;
  min-width: 200px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
}
.dash-board-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* D.3 — Metric widget cards */
.dash-widgets-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.widget-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  position: relative;
  overflow: hidden;
  min-height: 110px;
}
.widget-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--widget-color, var(--primary));
}
.widget-card.size-small { grid-column: span 1; }
.widget-card.size-medium { grid-column: span 2; }
.widget-card.size-large { grid-column: span 3; }
.widget-card.size-full { grid-column: span 5; }

.widget-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}
.widget-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.widget-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.widget-card:hover .widget-actions { opacity: 1; }
.widget-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-light);
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s;
}
.widget-actions button:hover {
  background: var(--bg);
  color: var(--text);
}

.widget-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 4px;
}
.widget-change {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 3px;
}
.widget-change.up { color: #166534; background: #dcfce7; }
.widget-change.down { color: #991b1b; background: #fee2e2; }
.widget-change.neutral { color: var(--text-light); background: var(--bg); }

.widget-add {
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-light);
  font-size: 13px;
  font-weight: 500;
  min-height: 110px;
  transition: border-color 0.15s, color 0.15s;
}
.widget-add:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.widget-add-icon { font-size: 24px; }

/* Modal */
.dash-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dash-modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 520px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.dash-modal-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dash-modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.dash-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.dash-modal-close:hover { background: var(--bg); }
.dash-modal-body { padding: 20px 24px; }
.dash-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Color picker inline */
.color-picker-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: var(--text); }

/* Key filter rows */
.key-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.key-filter-row input,
.key-filter-row select {
  width: auto;
  flex: 1;
  padding: 6px 8px;
  font-size: 13px;
}
.key-filter-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
}

/* Drag and drop */
.drag-handle {
  cursor: grab;
  color: var(--text-light);
  font-size: 14px;
  user-select: none;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.widget-card:hover .drag-handle { opacity: 1; }
.widget-card.dragging {
  opacity: 0.4;
  border: 2px dashed var(--primary);
}
.widget-card.drag-over {
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 3px rgba(32, 42, 208, 0.15);
}
.widget-card[draggable="true"] { cursor: default; }

/* Chart widget */
.widget-card.size-medium,
.widget-card.size-large,
.widget-card.size-full {
  min-height: 280px;
}

/* Custom dashboard empty */
.dash-custom-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.dash-custom-empty-icon { font-size: 48px; margin-bottom: 12px; }
.dash-custom-empty-text { font-size: 15px; margin-bottom: 16px; }

/* Responsive por ESPAÇO DISPONÍVEL (não por tamanho de tela — o menu lateral
   de 240px desloca o cálculo do viewport, e breakpoint de viewport não
   reage corretamente a zoom do navegador). Container definido em
   .content (portal.css). */
@container (max-width: 1000px) {
  .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-charts { grid-template-columns: minmax(0, 1fr); }
  .dash-bottom { grid-template-columns: minmax(0, 1fr); }
}
@container (max-width: 560px) {
  .dash-kpis { grid-template-columns: minmax(0, 1fr); }
}

/* Responsive por tamanho de tela — só o que ainda não foi convertido
   (dashboard customizável com spans fixos de coluna). */
@media (max-width: 1200px) {
  .dash-widgets-grid { grid-template-columns: repeat(3, 1fr); }
  .widget-card.size-full { grid-column: span 3; }
  .widget-card.size-large { grid-column: span 3; }
}
@media (max-width: 768px) {
  .dash-filters { flex-direction: column; align-items: stretch; }
  .dash-period-presets { margin-left: 0; }
  .dash-widgets-grid { grid-template-columns: repeat(2, 1fr); }
  .widget-card.size-medium,
  .widget-card.size-large,
  .widget-card.size-full { grid-column: span 2; }
  .dash-board-bar { flex-direction: column; align-items: stretch; }
  .dash-board-actions { margin-left: 0; }
}
