/* ==========================================================================
   Extratos PWA - Design System & Modern Dark Theme
   ========================================================================== */

:root {
  --bg-app: #0B0F19;
  --bg-surface: #161F30;
  --bg-surface-elevated: #1E293B;
  --bg-surface-hover: #26334D;
  --border-color: #1E293B;
  --border-subtle: #334155;

  --accent-emerald: #10B981;
  --accent-emerald-dark: #059669;
  --accent-emerald-glow: rgba(16, 185, 129, 0.18);

  --accent-indigo: #6366F1;
  --accent-indigo-glow: rgba(99, 102, 241, 0.18);
  --accent-cyan: #06B6D4;

  --accent-amber: #F59E0B;
  --accent-amber-glow: rgba(245, 158, 11, 0.18);
  --accent-rose: #EF4444;
  --accent-rose-glow: rgba(239, 68, 68, 0.18);

  --text-primary: #F8FAFC;
  --text-muted: #94A3B8;
  --text-subtle: #64748B;
  --text-disabled: #475569;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-subtle);
}

/* Layout App Shell */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1rem 3rem 1rem;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background-color: rgba(11, 15, 25, 0.85);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  margin-bottom: 1.5rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-emerald) 0%, var(--accent-indigo) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  box-shadow: 0 0 16px var(--accent-emerald-glow);
}

.brand-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-title .brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Form Controls */
select.custom-select, input.custom-input {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
}

select.custom-select:focus, input.custom-input:focus {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 2px var(--accent-emerald-glow);
}

/* Status Indicator Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

.status-dot.offline {
  background-color: var(--accent-amber);
  box-shadow: 0 0 8px var(--accent-amber);
}

/* Month Selector Pills */
.month-selector-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.75rem 0 0.25rem 0;
}

.month-pill {
  flex-shrink: 0;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.month-pill:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.month-pill.active {
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
  font-weight: 700;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.nav-tab-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.nav-tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.02);
}

.nav-tab-btn.active {
  color: var(--accent-emerald);
  border-bottom-color: var(--accent-emerald);
}

/* Content Views */
.view-content {
  display: none;
  animation: fadeIn 0.25s ease-in-out forwards;
}

.view-content.active {
  display: block;
}

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

/* Card Surfaces */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-subtle);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: linear-gradient(145deg, var(--bg-surface) 0%, rgba(22, 31, 48, 0.6) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, var(--kpi-glow, var(--accent-emerald-glow)) 0%, transparent 70%);
  pointer-events: none;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-subtle);
  margin-top: 0.25rem;
}

/* Alerts Box */
.alert-box {
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.alert-box.concentration {
  background-color: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #FDE68A;
}

.alert-box.spike {
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #FECACA;
}

.alert-box.info {
  background-color: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #C7D2FE;
}

/* Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

/* Donut & Bar Charts SVG */
.chart-container {
  width: 100%;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.chart-svg {
  width: 100%;
  height: 100%;
}

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
  max-height: 140px;
  overflow-y: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.5rem;
}

/* Tables & Data Grid */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

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

.data-table th {
  background-color: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background-color: var(--bg-surface-hover);
}

.data-table tfoot td {
  background-color: var(--bg-surface-elevated);
  font-weight: 700;
  border-top: 2px solid var(--border-subtle);
}

.text-right {
  text-align: right;
}
.text-center {
  text-align: center;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-emerald {
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
}
.badge-indigo {
  background: var(--accent-indigo-glow);
  color: var(--accent-indigo);
}
.badge-amber {
  background: var(--accent-amber-glow);
  color: var(--accent-amber);
}
.badge-rose {
  background: var(--accent-rose-glow);
  color: var(--accent-rose);
}
.badge-muted {
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
}

/* Progress Bar */
.progress-track {
  width: 100%;
  height: 8px;
  background-color: var(--bg-surface-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 0.4rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-emerald) 0%, var(--accent-indigo) 100%);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* Filters & Search Toolbar */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.search-input-wrapper {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-input-wrapper input {
  width: 100%;
  padding-left: 2.25rem;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.filter-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chip {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.chip:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.chip.active {
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
  font-weight: 600;
}

/* Category Matrix Heatmap Grid */
.matrix-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.matrix-table th, .matrix-table td {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.matrix-table th {
  background: var(--bg-surface-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
}

.matrix-table td.cat-sticky {
  position: sticky;
  left: 0;
  background: var(--bg-surface);
  font-weight: 600;
  z-index: 5;
}

.heatmap-cell {
  text-align: right;
  transition: var(--transition);
}

.heatmap-cell:hover {
  outline: 2px solid var(--accent-emerald);
  z-index: 2;
}

/* Responsive queries */
@media (max-width: 768px) {
  .app-container {
    padding: 0 0.5rem 2rem 0.5rem;
  }
  .header-top {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-controls {
    width: 100%;
    justify-content: space-between;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
}
