/* ============================
   BELLA CAPRI DASHBOARD - CSS
   ============================ */

:root {
  --primary: #D32F2F;
  --primary-dark: #B71C1C;
  --primary-light: #FFCDD2;
  --success: #4CAF50;
  --success-bg: #E8F5E9;
  --warning: #FF9800;
  --warning-bg: #FFF3E0;
  --danger: #F44336;
  --danger-bg: #FFEBEE;
  --info: #2196F3;
  --info-bg: #E3F2FD;
  --bg: #F5F5F5;
  --card: #FFFFFF;
  --text: #212121;
  --text-secondary: #616161;
  --border: #E0E0E0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;

  /* Classificação */
  --cor-excelente: #4CAF50;
  --cor-boa: #2196F3;
  --cor-regular: #FF9800;
  --cor-ruim: #F44336;
  --cor-pessima: #616161;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* HEADER */
.header {
  background: var(--card);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.logo-sub {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary);
  color: white;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.select-periodo {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: white;
  cursor: pointer;
  color: var(--text);
}

.btn-refresh {
  background: var(--primary);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s;
}

.btn-refresh:hover {
  transform: rotate(180deg);
}

.btn-refresh.loading {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* MAIN */
.main {
  padding: 24px 0 48px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}

/* KPI CARDS */
.kpis-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpis-3 {
  grid-template-columns: repeat(3, 1fr);
}

.kpis-1 {
  grid-template-columns: 1fr;
  max-width: 320px;
}

.kpis-2 {
  grid-template-columns: repeat(2, 1fr);
  max-width: 640px;
}

.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow 0.2s;
}

.kpi-card:hover {
  box-shadow: var(--shadow-hover);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.kpi-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.kpi-variacao {
  font-size: 12px;
  font-weight: 600;
}

.kpi-variacao.positivo { color: var(--success); }
.kpi-variacao.negativo { color: var(--danger); }
.kpi-variacao.neutro { color: var(--text-secondary); }

/* KPI colored cards */
.kpi-excelente { border-left: 4px solid var(--cor-excelente); }
.kpi-boa { border-left: 4px solid var(--cor-boa); }
.kpi-regular { border-left: 4px solid var(--cor-regular); }
.kpi-ruim { border-left: 4px solid var(--cor-ruim); }
.kpi-danger { border-left: 4px solid var(--danger); }

/* CHART CARDS */
.charts-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chart-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: -10px;
  margin-bottom: 14px;
  line-height: 1.4;
  opacity: 0.8;
}

.chart-wrapper {
  position: relative;
  min-height: 280px;
}

.chart-wrapper canvas {
  max-height: 320px;
}

/* FUNIL */
.funil-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 0;
}

.funil-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  transition: padding 0.4s ease;
}

.funil-label {
  width: 120px;
  font-size: 11px;
  font-weight: 500;
  text-align: right;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.funil-track {
  flex: 1;
  height: 28px;
  background: transparent;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.funil-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  min-width: 40px;
}

.funil-fill span {
  color: white;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* HEATMAP */
.heatmap-wrapper {
  overflow-x: auto;
  min-height: auto;
}

.heatmap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.heatmap-table th {
  padding: 6px 8px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
}

.heatmap-table td {
  padding: 6px 8px;
  text-align: center;
  border-radius: 4px;
  font-weight: 500;
  min-width: 40px;
}

.heatmap-cell {
  color: white;
  font-size: 11px;
}

/* ALERTAS */
.alertas-container {
  margin-bottom: 20px;
}

.alerta {
  padding: 14px 20px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alerta-critico {
  background: var(--danger-bg);
  color: var(--danger);
  border-left: 4px solid var(--danger);
}

.alerta-atencao {
  background: var(--warning-bg);
  color: #E65100;
  border-left: 4px solid var(--warning);
}

.alerta-icon {
  font-size: 18px;
}

/* FILTERS */
.section-filters {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-filters h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.filters-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.filter-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}

.btn-filter-action {
  background: none;
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-filter-action:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.multi-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  min-width: 160px;
  min-height: 80px;
  background: white;
}

/* Checkbox filter */
.checkbox-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  min-width: 200px;
  max-width: 360px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 12px;
  user-select: none;
}

.checkbox-item:hover {
  background: var(--primary-light);
}

.checkbox-item input[type="checkbox"] {
  accent-color: var(--primary);
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.checkbox-item:has(input:checked) {
  background: var(--primary);
  color: white;
}

.checkbox-item:has(input:checked) .checkbox-label {
  color: white;
}

.checkbox-label {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.btn-filtrar {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-filtrar:hover {
  background: var(--primary-dark);
}

/* TABLES */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: #FAFAFA;
}

/* Badge de classificação */
.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
  text-transform: uppercase;
}

.badge-EXCELENTE { background: #E8F5E9; color: #2E7D32; }
.badge-BOA { background: #E3F2FD; color: #1565C0; }
.badge-REGULAR { background: #FFF3E0; color: #E65100; }
.badge-RUIM { background: #FFEBEE; color: #C62828; }
.badge-PESSIMA { background: #ECEFF1; color: #37474F; }

.badge-ALTA { background: #E8F5E9; color: #2E7D32; }
.badge-MEDIA { background: #FFF3E0; color: #E65100; }
.badge-BAIXA { background: #FFEBEE; color: #C62828; }
.badge-NULA { background: #ECEFF1; color: #37474F; }

/* LIST (for performance page) */
.list-wrapper {
  max-height: 350px;
  overflow-y: auto;
  min-height: 100px;
}

.list-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.list-item-thread {
  font-size: 11px;
  color: var(--info);
  font-weight: 500;
  cursor: pointer;
}

.list-item-thread:hover {
  text-decoration: underline;
}

.list-item-date {
  font-size: 11px;
  color: var(--text-secondary);
}

.list-item-text {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.list-empty {
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
  padding-right: 30px;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-field-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.modal-field-value {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.modal-historico {
  background: #FAFAFA;
  border-radius: 8px;
  padding: 16px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'Segoe UI', sans-serif;
  border: 1px solid var(--border);
}

/* LOADING */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  z-index: 10;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
  .kpis-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }

  .nav {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 4px;
  }

  .nav-btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .header-actions {
    width: 100%;
    justify-content: center;
  }

  .container {
    padding: 0 12px;
  }

  .kpis-grid {
    grid-template-columns: 1fr;
  }

  .kpis-3 {
    grid-template-columns: 1fr;
  }

  .kpi-value {
    font-size: 22px;
  }

  .page-title {
    font-size: 20px;
  }

  .filters-row {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }

  .funil-label {
    width: 100px;
    font-size: 11px;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ============================
   DARK MODE BUTTON
   ============================ */
.btn-darkmode {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-darkmode:hover {
  background: var(--primary-light);
}

/* ============================
   DARK MODE
   ============================ */
[data-theme="dark"] {
  --bg: #121212;
  --card: #1E1E1E;
  --text: #E0E0E0;
  --text-secondary: #9E9E9E;
  --border: #333333;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.4);
  --primary-light: #4A1A1A;
}

[data-theme="dark"] .header {
  background: #1E1E1E;
  border-bottom: 1px solid #333;
}

[data-theme="dark"] .nav-btn:hover {
  background: #2A2A2A;
}

[data-theme="dark"] .select-periodo {
  background: #2A2A2A;
  color: var(--text);
  border-color: #444;
}

[data-theme="dark"] .btn-darkmode {
  background: #2A2A2A;
  border-color: #444;
}

[data-theme="dark"] .data-table th {
  background: #2A2A2A;
}

[data-theme="dark"] .data-table tbody tr:hover {
  background: #2A2A2A;
}

[data-theme="dark"] .data-table td {
  border-bottom-color: #333;
}

[data-theme="dark"] .checkbox-filter {
  background: #2A2A2A;
  border-color: #444;
}

[data-theme="dark"] .checkbox-item {
  background: #333;
}

[data-theme="dark"] .checkbox-item:hover {
  background: #4A1A1A;
}

[data-theme="dark"] .checkbox-label {
  color: var(--text);
}

[data-theme="dark"] .multi-select {
  background: #2A2A2A;
  color: var(--text);
  border-color: #444;
}

[data-theme="dark"] .modal-content {
  background: #1E1E1E;
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0,0,0,0.7);
}

[data-theme="dark"] .modal-historico {
  background: #2A2A2A;
  border-color: #444;
}

[data-theme="dark"] .heatmap-table td {
  color: #eee;
}

[data-theme="dark"] .heatmap-table td:not(.heatmap-cell) {
  background: #2A2A2A;
  color: #555;
}

[data-theme="dark"] .funil-track {
  background: #2A2A2A;
}

[data-theme="dark"] .alerta-critico {
  background: #3D1515;
  border-left-color: #F44336;
}

[data-theme="dark"] .alerta-atencao {
  background: #3D2E15;
  border-left-color: #FF9800;
}

[data-theme="dark"] .list-item {
  border-bottom-color: #333;
}

[data-theme="dark"] .btn-filter-action {
  border-color: #444;
  color: #9E9E9E;
}

[data-theme="dark"] .btn-filter-action:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

[data-theme="dark"] .badge-EXCELENTE { background: #1B3A1B; color: #66BB6A; }
[data-theme="dark"] .badge-BOA { background: #152E42; color: #64B5F6; }
[data-theme="dark"] .badge-REGULAR { background: #3D2E15; color: #FFB74D; }
[data-theme="dark"] .badge-RUIM { background: #3D1515; color: #EF5350; }
[data-theme="dark"] .badge-PESSIMA { background: #2A2A2A; color: #BDBDBD; }
[data-theme="dark"] .badge-ALTA { background: #1B3A1B; color: #66BB6A; }
[data-theme="dark"] .badge-MEDIA { background: #3D2E15; color: #FFB74D; }
[data-theme="dark"] .badge-BAIXA { background: #3D1515; color: #EF5350; }
[data-theme="dark"] .badge-NULA { background: #2A2A2A; color: #BDBDBD; }

/* Chart.js dark mode grid lines */
[data-theme="dark"] .chart-wrapper canvas {
  filter: none;
}

/* ============================
   LOGIN OVERLAY
   ============================ */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #B71C1C 0%, #D32F2F 50%, #E53935 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  color: #D32F2F;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: #616161;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 13px;
  font-weight: 600;
  color: #424242;
}

.login-field input {
  padding: 12px 16px;
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  outline: none;
}

.login-field input:focus {
  border-color: #D32F2F;
  box-shadow: 0 0 0 3px rgba(211,47,47,0.1);
}

.login-error {
  background: #FFEBEE;
  color: #C62828;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.login-btn {
  background: #D32F2F;
  color: white;
  border: none;
  padding: 14px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}

.login-btn:hover {
  background: #B71C1C;
}

.login-btn:disabled {
  background: #999;
  cursor: not-allowed;
}

[data-theme="dark"] .login-card {
  background: #1E1E1E;
}

[data-theme="dark"] .login-title {
  color: #EF5350;
}

[data-theme="dark"] .login-subtitle {
  color: #9E9E9E;
}

[data-theme="dark"] .login-field label {
  color: #BDBDBD;
}

[data-theme="dark"] .login-field input {
  background: #2A2A2A;
  border-color: #444;
  color: #E0E0E0;
}

[data-theme="dark"] .login-field input:focus {
  border-color: #EF5350;
  box-shadow: 0 0 0 3px rgba(239,83,80,0.2);
}

[data-theme="dark"] .login-error {
  background: #3D1515;
  color: #EF5350;
}
