/* =============================================
   TableroCencherle — index.css
   Diseño oscuro premium con glassmorphism
   ============================================= */

/* --- VARIABLES --- */
:root {
  --bg-base:        #0b0b14;
  --bg-surface:     #13131f;
  --bg-card:        rgba(255,255,255,0.04);
  --bg-card-hover:  rgba(255,255,255,0.07);
  --border:         rgba(255,255,255,0.07);
  --border-light:   rgba(255,255,255,0.12);

  --text-primary:   #f0f0ff;
  --text-secondary: #8888aa;
  --text-muted:     #555570;

  --color-scalabrini:  #7c6ee0;
  --color-mayoristas:  #10b981;
  --color-ecommerce:   #f59e0b;
  --color-corredores:  #ef4444;
  --color-general:     #60a5fa;

  --accent:         #7c6ee0;
  --accent-glow:    rgba(124,110,224,0.25);

  --sidebar-w:      220px;
  --topbar-h:       64px;
  --radius:         14px;
  --radius-sm:      8px;
  --transition:     0.22s ease;

  font-size: 15px;
}

/* --- RESET --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  overflow: hidden;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
select { font-family: inherit; }

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  flex-shrink: 0;
  transition: transform var(--transition);
  z-index: 100;
  position: relative;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}
.logo-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c6ee0, #4f46e5);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff; letter-spacing: -0.5px;
  box-shadow: 0 0 18px rgba(124,110,224,0.35);
  flex-shrink: 0;
}
.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-brand { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.logo-sub   { font-size: 11px; font-weight: 400; color: var(--text-secondary); }

/* NAV */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  flex: 1;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  text-align: left;
}
.nav-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.nav-btn.active {
  background: linear-gradient(135deg, rgba(124,110,224,0.18), rgba(79,70,229,0.08));
  color: #a89ef8;
  border: 1px solid rgba(124,110,224,0.2);
  box-shadow: 0 0 12px rgba(124,110,224,0.08);
}
.nav-icon {
  font-size: 16px;
  width: 20px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.nav-dot {
  width: 10px !important;
  height: 10px;
  border-radius: 50%;
  font-size: 0 !important;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

/* SIDEBAR FOOTER */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.update-info {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted);
}
.update-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #10b981;
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
.btn-refresh {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-refresh:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  transform: rotate(90deg);
}

/* =============================================
   MAIN CONTENT
   ============================================= */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* --- TOPBAR --- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 50;
}
.burger-btn {
  display: none;
  font-size: 20px;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 6px;
  transition: all var(--transition);
}
.burger-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.filters {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.filter-select:hover, .filter-select:focus {
  border-color: rgba(124,110,224,0.4);
}
.filter-select option { background: #1a1a2e; }

/* Toggle comparar */
.toggle-group { gap: 8px; }
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px; height: 20px;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: rgba(255,255,255,0.1);
  transition: background var(--transition);
  cursor: pointer;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::after { transform: translateX(18px); }

.vista-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: auto;
  white-space: nowrap;
}

/* =============================================
   LOADING & ERROR
   ============================================= */
.loading-overlay {
  position: absolute;
  inset: var(--topbar-h) 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-base);
  z-index: 200;
  transition: opacity 0.3s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(255,255,255,0.05);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--text-muted); }

.error-state {
  position: absolute;
  inset: var(--topbar-h) 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 200;
}
.error-state.hidden { display: none; }
.error-icon { font-size: 48px; }
.error-msg { font-size: 14px; color: var(--text-secondary); }
.btn-retry {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: opacity var(--transition);
}
.btn-retry:hover { opacity: 0.85; }

/* =============================================
   CONTENT AREA
   ============================================= */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.content-area::-webkit-scrollbar { width: 6px; }
.content-area::-webkit-scrollbar-track { background: transparent; }
.content-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }

/* --- KPI SECTION --- */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(10px);
  transition: all var(--transition);
  animation: fadeInUp 0.4s ease backwards;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--kpi-color, var(--accent));
  border-radius: 2px 2px 0 0;
}
.kpi-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1;
}
.kpi-sub {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-delta {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 20px;
}
.kpi-delta.pos { background: rgba(16,185,129,0.15); color: #10b981; }
.kpi-delta.neg { background: rgba(239,68,68,0.15);  color: #ef4444; }

/* --- CHARTS SECTION --- */
.charts-section {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeInUp 0.5s ease backwards;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.chart-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-secondary);
}
.legend-dot {
  width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0;
}
.chart-wrapper {
  position: relative;
  height: 280px;
  min-height: 260px;
}
.chart-donut-wrapper {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.donut-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}
.donut-legend-label {
  display: flex; align-items: center; gap: 8px;
}
.donut-legend-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.donut-legend-value {
  font-weight: 600;
  color: var(--text-primary);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 1024px) {
  .charts-section {
    grid-template-columns: 1fr;
  }
  .chart-donut { order: -1; }
  .chart-donut-wrapper { min-height: 220px; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 240px; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 30px rgba(0,0,0,0.5);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content { width: 100%; }
  .burger-btn { display: flex; }

  .topbar { padding: 0 16px; gap: 12px; }
  .filters { gap: 10px; }
  .filter-label { display: none; }
  .toggle-group .filter-label { display: flex; font-size: 11px; }
  .vista-title { display: none; }

  .content-area { padding: 16px; gap: 16px; }
  .kpi-section { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi-value { font-size: 22px; }
}

@media (max-width: 480px) {
  .kpi-section { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 14px 16px; }
}

/* OVERLAY para cerrar sidebar en mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}
.sidebar-overlay.show { display: block; }
/* --- EXTRA SECTIONS --- */
.extra-section {
  display: block;
  width: 100%;
}
.chart-full {
  width: 100%;
}
.chart-wrapper.large {
  height: 400px;
}

/* --- MODE TOGGLE --- */
.mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.04);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.toggle-btn {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(124,110,224,0.3);
}

/* --- MULTI-SELECT --- */
.multi-select {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.month-tag {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.month-tag:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}
.month-tag.active {
  background: rgba(124,110,224,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* --- TABLES --- */
.table-wrapper {
  overflow-x: auto;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.details-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
}
.details-table th {
  background: rgba(255,255,255,0.03);
  padding: 12px 16px;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.details-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.details-table tr:hover td {
  background: rgba(255,255,255,0.02);
  color: var(--text-primary);
}
.details-table .row-weekend td {
  background: rgba(255,255,255,0.01);
}
.details-table .row-holiday td {
  color: #ff9999;
}
.details-table .val-total {
  font-weight: 700;
  color: var(--text-primary);
}

.btn-export {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-export:hover {
  background: var(--accent);
}

@media (max-width: 768px) {
  .header-actions {
    width: 100%;
    margin-top: 10px;
    justify-content: flex-start;
  }
}
