/* ============================================
   COMEX SFPC - Dashboard Gerencial
   63º Batalhão de Infantaria
   Design System: Militar / Tático
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
  /* Backgrounds */
  --bg-primary: #eef2e6;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f7faf5;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-filter: rgba(238, 242, 230, 0.95);

  /* Military Colors */
  --olive: #3d5016;
  --olive-light: #6b7c3a;
  --olive-dark: #2a3810;
  --navy: #1e3a8a;
  --navy-light: #3b82f6;
  --navy-dark: #1e40af;

  /* Accent */
  --accent-green: #15803d;
  --accent-blue: #2563eb;
  --accent-amber: #c9a227;
  --accent-red: #dc2626;

  /* Text */
  --text-primary: #1a1a1a;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-value: #3d5016;

  /* Borders */
  --border-default: rgba(0, 0, 0, 0.08);
  --border-accent: rgba(201, 162, 39, 0.4);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
  --shadow-glow-green: none;
  --shadow-glow-blue: none;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: #f5f2e8;
  background-image: linear-gradient(rgba(245, 242, 232, 0.88), rgba(245, 242, 232, 0.88)), url('../assets/imagemaerea63biverdeoliva.webp');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle grid pattern overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(74, 124, 89, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 124, 89, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--olive-dark);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--olive);
}

/* ── LOADING OVERLAY DO 63° BI (FUNDO CLARO OTIMIZADO) ── */
.loading-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: #f5f2e8;
  background-image: linear-gradient(rgba(245, 242, 232, 0.88), rgba(245, 242, 232, 0.88)), url('../assets/imagemaerea63biverdeoliva.webp');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 99999; transition: opacity 0.4s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border-default);
  border-top-color: var(--accent-amber);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text { margin-top: 16px; font-size: 14px; color: var(--text-secondary); font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dashboard Container ---------- */
.dashboard-container {
  position: relative;
  z-index: 1;
  max-width: 1920px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-xl);
}

/* ---------- Header EXECUTIVO EM VERDE OLIVA MILITAR COM EFEITO DE VIDRO ---------- */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(20, 28, 12, 0.90) !important;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 2.5px solid #c9a227 !important;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  color: #ffffff !important;
  position: relative;
  overflow: hidden;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-emblem {
  width: auto;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  padding-right: 20px;
}

.header-emblem img {
  height: 72px;
  width: auto;
  object-fit: contain;
}

.header-info h1 {
  font-size: 1.3rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.header-info .header-subtitle {
  font-size: 0.78rem;
  color: #c2d1b2;
  font-weight: 600;
  margin-top: 2px;
}

.dashboard-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--olive), var(--navy), var(--olive-light));
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-shrink: 0;
}

.header-meta {
  text-align: right;
}

.header-meta .meta-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.header-meta .meta-value {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.btn-load-csv {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 8px 16px;
  background: rgba(74, 124, 89, 0.2);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  color: var(--olive-light);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: inherit;
}

.btn-load-csv:hover {
  background: rgba(74, 124, 89, 0.35);
  border-color: var(--olive-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow-green);
}

.hidden-input {
  display: none;
}

/* ---------- Filters Section ---------- */
.filters-section {
  display: flex;
  align-items: flex-end;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 160px;
}

.filter-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.filter-control {
  padding: 7px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  transition: all var(--transition-fast);
  outline: none;
  cursor: pointer;
}

.filter-control:hover,
.filter-control:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 2px rgba(74, 124, 89, 0.15);
}

.filter-control option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-clear-filters {
  padding: 7px 16px;
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-red);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  align-self: flex-end;
}

.btn-clear-filters:hover {
  background: rgba(248, 81, 73, 0.25);
  border-color: var(--accent-red);
}

/* ---------- Section Title ---------- */
.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border-default);
}

.section-title .title-icon {
  font-size: 1rem;
}

.section-title .title-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border-default), transparent);
}

/* ---------- KPI Section ---------- */
.kpi-section {
  margin-bottom: var(--space-lg);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-md);
}

.kpi-card {
  position: relative;
  padding: var(--space-lg);
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  overflow: hidden;
  animation: fadeInUp 0.6s ease forwards;
  opacity: 0;
}

.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }
.kpi-card:nth-child(5) { animation-delay: 0.25s; }

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}

.kpi-card.kpi-value-card::before { background: linear-gradient(90deg, var(--accent-green), var(--olive-light)); }
.kpi-card.kpi-process-card::before { background: linear-gradient(90deg, var(--accent-blue), var(--navy-light)); }
.kpi-card.kpi-li-card::before { background: linear-gradient(90deg, #a78bfa, #7c3aed); }
.kpi-card.kpi-lpco-card::before { background: linear-gradient(90deg, #f472b6, #db2777); }
.kpi-card.kpi-sla-card::before { background: linear-gradient(90deg, var(--accent-amber), #e67e22); }

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-accent);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

.kpi-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
}

.kpi-value-card .kpi-icon { background: rgba(126, 217, 87, 0.12); }
.kpi-process-card .kpi-icon { background: rgba(88, 166, 255, 0.12); }
.kpi-li-card .kpi-icon { background: rgba(167, 139, 250, 0.12); }
.kpi-lpco-card .kpi-icon { background: rgba(244, 114, 182, 0.12); }
.kpi-sla-card .kpi-icon { background: rgba(240, 168, 48, 0.12); }

.kpi-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
  margin-top: var(--space-xs);
  font-variant-numeric: tabular-nums;
}

.kpi-value-card .kpi-value { color: var(--accent-green); }
.kpi-process-card .kpi-value { color: var(--accent-blue); }
.kpi-li-card .kpi-value { color: #a78bfa; }
.kpi-lpco-card .kpi-value { color: #f472b6; }
.kpi-sla-card .kpi-value { color: var(--accent-amber); }

.kpi-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.sla-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 600;
  margin-top: 4px;
}

.sla-badge.sla-good {
  background: rgba(126, 217, 87, 0.15);
  color: var(--accent-green);
}

.sla-badge.sla-warning {
  background: rgba(240, 168, 48, 0.15);
  color: var(--accent-amber);
}

.sla-badge.sla-critical {
  background: rgba(248, 81, 73, 0.15);
  color: var(--accent-red);
}

/* ---------- Charts Grid ---------- */
.charts-section {
  margin-bottom: var(--space-lg);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

.chart-panel {
  position: relative;
  padding: var(--space-lg);
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  animation: fadeInUp 0.6s ease forwards;
  opacity: 0;
}

.chart-panel:nth-child(1) { animation-delay: 0.3s; }
.chart-panel:nth-child(2) { animation-delay: 0.35s; }
.chart-panel:nth-child(3) { animation-delay: 0.4s; }
.chart-panel:nth-child(4) { animation-delay: 0.45s; }

.chart-panel:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md);
}

.chart-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: var(--space-md);
}

.chart-title .chart-icon {
  font-size: 1rem;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 280px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-wrapper-sm {
  height: 240px;
}

.chart-wrapper-doughnut {
  height: 260px;
  max-width: 380px;
  margin: 0 auto;
}

/* ---------- Intelligence Section ---------- */
.intel-section {
  margin-bottom: var(--space-lg);
}

.intel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

/* ---------- Companies Table ---------- */
.company-table-panel {
  position: relative;
  padding: var(--space-lg);
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.6s ease forwards;
  opacity: 0;
  animation-delay: 0.5s;
  overflow: hidden;
}

.company-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.company-table thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-default);
}

.company-table thead th:last-child {
  text-align: right;
}

.company-table tbody tr {
  transition: background var(--transition-fast);
}

.company-table tbody tr:hover {
  background: rgba(74, 124, 89, 0.08);
}

.company-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.3);
  vertical-align: middle;
}

.company-table tbody td:last-child {
  text-align: right;
  font-weight: 600;
  color: var(--accent-green);
  font-variant-numeric: tabular-nums;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}

.rank-1 { background: rgba(240, 168, 48, 0.2); color: var(--accent-amber); }
.rank-2 { background: rgba(139, 148, 158, 0.2); color: #c9d1d9; }
.rank-3 { background: rgba(205, 127, 50, 0.2); color: #cd7f32; }
.rank-default { background: rgba(110, 118, 129, 0.15); color: var(--text-muted); }

.company-name {
  font-weight: 500;
  color: var(--text-primary);
}

.company-processes {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(48, 54, 61, 0.5);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--olive), var(--accent-green));
  transition: width 1s ease;
}

/* ---------- Footer ---------- */
.dashboard-footer {
  text-align: center;
  padding: var(--space-lg);
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  border-top: 1px solid var(--border-default);
  margin-top: var(--space-md);
}

.dashboard-footer span {
  color: var(--olive-light);
  font-weight: 600;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes countUp {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.animate-pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ---------- No Data State ---------- */
.no-data-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: 0.85rem;
  gap: var(--space-sm);
}

.no-data-message .no-data-icon {
  font-size: 2rem;
  opacity: 0.5;
}

/* ---------- Responsive ---------- */

/* Large TV / Monitor */
@media (min-width: 1920px) {
  .dashboard-container {
    padding: var(--space-xl) var(--space-2xl);
  }

  .kpi-value {
    font-size: 2rem;
  }

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

/* Laptop / Tablet landscape */
@media (max-width: 1400px) {
  .kpi-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .kpi-value {
    font-size: 1.5rem;
  }
}

@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

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

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

@media (max-width: 900px) {
  .dashboard-header {
    flex-direction: column;
    text-align: center;
    gap: var(--space-md);
  }

  .header-left {
    flex-direction: column;
  }

  .header-right {
    flex-direction: column;
  }

  .header-meta {
    text-align: center;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .filters-section {
    flex-direction: column;
  }

  .filter-group {
    min-width: 100%;
  }
}

@media (max-width: 600px) {
  .dashboard-container {
    padding: var(--space-sm);
  }

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

  .header-info h1 {
    font-size: 1rem;
  }
}

/* ---------- Print / Presentation ---------- */
@media print {
  body {
    background: white;
    color: #1a1a1a;
  }

  .filters-section,
  .btn-load-csv,
  .btn-clear-filters,
  .kpi-details-panel {
    display: none !important;
  }

  .kpi-card,
  .chart-panel,
  .company-table-panel {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ---------- KPI Details Panel ---------- */
.kpi-details-panel {
  margin-top: 0;
  padding: 0 var(--space-lg);
  background: var(--bg-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  box-shadow: none;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-10px);
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease,
              transform 0.3s ease,
              padding 0.4s ease,
              margin 0.4s ease,
              border-color 0.3s ease;
}

.kpi-details-panel.show {
  margin-top: var(--space-md);
  padding: var(--space-lg);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-lg);
  max-height: 1000px;
  opacity: 1;
  transform: translateY(0);
}

.details-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-default);
  padding-bottom: var(--space-xs);
}

.details-panel-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-blue);
  letter-spacing: 0.8px;
}

.btn-close-details {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: color var(--transition-fast);
}

.btn-close-details:hover {
  color: var(--accent-red);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.details-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  text-align: left;
}

.details-table th {
  padding: 8px 12px;
  background: var(--bg-primary);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border-default);
}

.details-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
  color: var(--text-secondary);
}

.details-table tr:hover {
  background: rgba(74, 124, 89, 0.05);
}

.details-table tr:hover td {
  color: var(--text-primary);
}

.details-table td:last-child {
  font-weight: 600;
  color: var(--accent-green);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.details-table th:last-child {
  text-align: right;
}

/* Pointer cursor on cards */
.kpi-card {
  cursor: pointer;
}

.kpi-card:hover {
  outline: 1px solid var(--olive-light);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

