/* ==========================================================================
   LaborStats Dashboard - Hoja de Estilos Vanilla CSS
   Tema Claro (Light Theme) & Diseño Responsivo Puro (Sin dependencias externas)
   ========================================================================== */

:root {
  /* Paleta cromática tema claro */
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-focus: #4f46e5;

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --brand-primary: #4f46e5;
  --brand-primary-hover: #4338ca;
  --brand-light: #eef2ff;
  --brand-border: #c7d2fe;

  --emerald: #059669;
  --emerald-light: #ecfdf5;
  --emerald-border: #a7f3d0;
  --emerald-text: #047857;

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

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.07);

  --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset básico */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar estilizada */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-subtle); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Utilidades */
.hidden {
  display: none !important;
}

/* ==========================================================================
   HEADER / ENCABEZADO
   ========================================================================== */
.app-header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 0.35rem 1.25rem;
  box-shadow: var(--shadow-xs);
}

.header-banner {
  display: block;
  width: 100%;
  max-width: 1920px;
  height: auto;
  max-height: 92px;
  object-fit: contain;
  margin: 0 auto;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1920px;
  margin: 0 auto;
  gap: 1rem;
}

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

.brand-icon {
  background: var(--brand-light);
  color: var(--brand-primary);
  border: 1px solid var(--brand-border);
  padding: 0.4rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-xs);
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--brand-light);
  color: var(--brand-primary);
  border: 1px solid var(--brand-border);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.status-badge {
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--emerald-light);
  color: var(--emerald-text);
  border: 1px solid var(--emerald-border);
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ==========================================================================
   MAIN LAYOUT & CARDS
   ========================================================================== */
.main-wrapper {
  flex: 1;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 1920px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
  overflow-x: hidden;
}

.card-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

/* ==========================================================================
   CONTROLS BAR / BARRA DE CONTROLES UNIFICADA
   ========================================================================== */
.controls-container {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  min-width: 0;
}

.controls-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  width: 100%;
  min-width: 0;
}

.controls-left-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 auto;
  flex-wrap: wrap;
  min-width: 0;
}

/* Conmutador de modo */
.mode-toggle-group {
  display: flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.2rem;
  gap: 0.2rem;
  flex-shrink: 0;
}

.btn-mode {
  border: none;
  background: transparent;
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition-fast);
}

.btn-mode:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

.btn-mode.active {
  background: var(--brand-primary);
  color: #ffffff;
  box-shadow: var(--shadow-xs);
}

/* Selectores estilizados */
.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.select-category-wrapper {
  width: 250px;
}

.select-indicator-wrapper {
  flex: 1;
  min-width: 260px;
}

.custom-select {
  width: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  padding: 0.45rem 2rem 0.45rem 0.75rem;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
  transition: var(--transition-fast);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.custom-select:hover {
  background: #ffffff;
  border-color: var(--border-strong);
}

.custom-select:focus {
  background: #ffffff;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.select-icon {
  position: absolute;
  right: 0.65rem;
  color: var(--text-muted);
  pointer-events: none;
}

.notice-box {
  background: var(--brand-light);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--brand-primary);
  font-weight: 500;
  flex: 1;
}

/* Botonera de acciones (Reubicada) */
.actions-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-action {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-xs);
  transition: var(--transition-fast);
}

.btn-action:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.btn-action.active {
  background: var(--brand-primary);
  color: #ffffff;
  border-color: var(--brand-primary);
}

.btn-action.btn-primary {
  background: var(--brand-primary);
  color: #ffffff;
  border-color: var(--brand-primary);
  font-weight: 600;
}

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

.btn-action.btn-excel {
  background: #107c41;
  color: #ffffff;
  border-color: #107c41;
  font-weight: 600;
}

.btn-action.btn-excel:hover {
  background: #0b5a2f;
  border-color: #0b5a2f;
}

/* Fila secundaria: Rango temporal & tipo de gráfica */
.controls-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.year-range-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.year-input-box {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.year-input {
  width: 3.5rem;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  color: var(--brand-primary);
  outline: none;
}

.year-input:focus {
  border-color: var(--brand-primary);
}

/* Selector tipo de gráfico */
.chart-type-selector {
  display: flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.2rem;
  gap: 0.25rem;
}

.btn-chart-type {
  border: none;
  background: transparent;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: var(--transition-fast);
}

.btn-chart-type:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

.btn-chart-type.active {
  background: var(--brand-primary);
  color: #ffffff;
  box-shadow: var(--shadow-xs);
}

/* ==========================================================================
   VISUALIZATION LAYOUT: CHART + SIDEBAR CHIPS
   ========================================================================== */
.viz-layout {
  display: flex;
  gap: 1rem;
  align-items: stretch;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
}

.chart-section {
  flex: 1 1 0%;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

.chart-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.chart-title-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  max-width: 100%;
  min-width: 0;
}

.chart-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand-primary);
  animation: pulse-dot 2s infinite ease-in-out;
  flex-shrink: 0;
}

.chart-main-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  max-width: 480px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.badge-tag {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  flex-shrink: 0;
}

.badge-category {
  background: var(--brand-light);
  color: var(--brand-primary);
  border-color: var(--brand-border);
}

.badge-unit {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.zoom-hint-text {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.canvas-container {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 420px;
  min-width: 0;
}

/* ==========================================================================
   SERIES SWITCHER PANEL (AL LADO EN DESKTOP, ABAJO EN MÓVIL)
   ========================================================================== */
.series-panel {
  width: 320px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-shrink: 0;
  min-width: 0;
}

.series-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.6rem;
}

.series-panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.series-panel-title h3 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-main);
}

.series-panel-title p {
  font-size: 0.65rem;
  color: var(--text-secondary);
}

.series-ratio-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--brand-light);
  color: var(--brand-primary);
  border: 1px solid var(--brand-border);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
}

.series-actions-row {
  display: flex;
  gap: 0.5rem;
}

.btn-quick-toggle {
  flex: 1;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: var(--transition-fast);
}

.btn-quick-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.btn-quick-toggle.btn-quick-on {
  background: var(--brand-light);
  color: var(--brand-primary);
  border-color: var(--brand-border);
}

.btn-quick-toggle.btn-quick-on:hover {
  background: #e0e7ff;
}

/* Lista deslizable de chips */
.series-chips-list {
  flex: 1;
  max-height: 460px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
}

.series-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.series-group-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.series-group-header .series-group-chip {
  flex: 1;
  min-width: 0;
}

.series-group-chip .chip-content {
  flex: 1;
  overflow: hidden;
}

.series-group-chip .chip-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.series-group-visibility {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.series-group-visibility:hover {
  background: var(--bg-hover);
  color: var(--brand-primary);
}

.series-group-visibility svg {
  width: 14px;
  height: 14px;
}

.series-group-chip {
  font-weight: 700;
}

.series-indicator-chip {
  margin-left: 0.75rem;
  width: calc(100% - 0.75rem);
  padding: 0.4rem 0.65rem;
  font-size: 0.7rem;
}

.series-chip {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-fast);
}

.chip-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.chip-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.chip-detail {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 400;
}

.chip-active {
  background: var(--brand-light);
  border-color: var(--brand-border);
  color: var(--brand-primary);
}

.chip-inactive {
  background: var(--bg-subtle);
  border-color: var(--border-color);
  color: var(--text-muted);
  opacity: 0.65;
}

.chip-inactive .chip-name {
  color: var(--text-muted);
}

.chip-inactive:hover {
  opacity: 0.9;
  background: #e2e8f0;
}

/* ==========================================================================
   HISTORICAL DATA TABLE / TABLA HISTÓRICA
   ========================================================================== */
.table-container {
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

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

.data-table thead {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.03em;
}

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

.table-row-hover:hover {
  background: var(--bg-subtle);
}

.cell-year {
  font-weight: 600;
  color: var(--text-main);
}

.cell-value {
  font-weight: 700;
  color: var(--brand-primary);
}

/* ==========================================================================
   FOOTER / PIE DE PÁGINA
   ========================================================================== */
.app-footer {
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 0.65rem 1.25rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.footer-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1920px;
  margin: 0 auto;
  flex-wrap: wrap;
}

/* ==========================================================================
   RESPONSIVE MEDIA QUERIES (SIN TAILWIND)
   ========================================================================== */

/* Tablet (640px a 1023px) */
@media (max-width: 1023px) {
  .viz-layout {
    flex-direction: column;
  }

  .series-panel {
    width: 100%;
  }

  .series-chips-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    max-height: 320px;
    gap: 0.5rem;
  }
}

/* Móvil (<640px) */
@media (max-width: 639px) {
  .main-wrapper {
    padding: 0.75rem;
    gap: 0.75rem;
  }

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

  .controls-left-group {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-toggle-group {
    width: 100%;
  }

  .btn-mode {
    flex: 1;
    justify-content: center;
  }

  .select-category-wrapper,
  .select-indicator-wrapper {
    width: 100%;
    min-width: 100%;
  }

  .actions-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .btn-action {
    justify-content: center;
    padding: 0.55rem 0.5rem;
  }

  .controls-sub-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .year-range-picker {
    justify-content: center;
  }

  .chart-type-selector {
    justify-content: center;
  }

  .btn-chart-type {
    flex: 1;
    justify-content: center;
  }

  .chart-section {
    min-height: 360px;
  }

  .canvas-container {
    min-height: 280px;
  }

  .zoom-hint-text {
    display: none;
  }

  .series-chips-list {
    grid-template-columns: 1fr;
    max-height: 300px;
  }

  .brand-subtitle {
    display: none;
  }

  .footer-container {
    flex-direction: column;
    text-align: center;
    gap: 0.5rem;
  }
}
