/* ============================================================
   Dashboard Impekble — Mobile-first
   ============================================================ */

:root {
  --verde-oscuro:  #312e81;
  --verde-medio:   #4f46e5;
  --verde-claro:   #eef2ff;
  --verde-borde:   #c7d2fe;
  --amarillo:      #f59e0b;
  --amarillo-bg:   #fef3c7;
  --rojo:          #dc2626;
  --rojo-bg:       #fee2e2;
  --verde-ok:      #16a34a;
  --verde-ok-bg:   #dcfce7;
  --gris-texto:    #374151;
  --gris-suave:    #6b7280;
  --gris-borde:    #e5e7eb;
  --fondo:         #f5f3ff;
  --blanco:        #fff;
}

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--fondo);
  color: var(--gris-texto);
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================================ HEADER */
.header {
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.header__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.875rem 1.25rem 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.header__back     { color: rgba(255,255,255,0.7); text-decoration: none; font-size: 1.1rem; line-height: 1; margin-right: -0.25rem; }
.header__back:hover { color: white; }
.header__logo     { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.5px; }
.header__subtitle { font-size: 0.8rem; opacity: 0.7; flex: 1; }
.header__update   { font-size: 0.7rem; opacity: 0.5; white-space: nowrap; }

/* ============================================================ NAV TABS */
.nav {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 0;
}
.nav::-webkit-scrollbar { display: none; }

.nav-tab {
  color: rgba(255,255,255,0.55);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 0.875rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}
.nav-tab:hover  { color: rgba(255,255,255,0.85); }
.nav-tab.activo { color: white; border-bottom-color: white; }

/* ============================================================ MAIN */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

/* ============================================================ SECCIONES */
.section {
  background: var(--blanco);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 0 0 1px var(--gris-borde);
}
.section__title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 0.625rem;
  margin-bottom: 0.75rem;
  border-bottom: 2px solid var(--verde-claro);
}
.section__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--verde-oscuro);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}
/* Secciones sin title-row usan h2 directamente */
section > h2.section__title {
  padding-bottom: 0.625rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--verde-claro);
}
.section__title::before {
  content: '';
  display: inline-block;
  width: 3px; height: 1rem;
  background: var(--verde-oscuro);
  border-radius: 2px;
  flex-shrink: 0;
}

/* ============================================================ AVISO STOCK BAJO */
.aviso-stock {
  padding: 0.625rem 0.875rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.875rem;
}
.aviso-stock--alerta { background: var(--rojo-bg);     color: #7f1d1d; border: 1px solid #fca5a5; }
.aviso-stock--ok     { background: var(--verde-ok-bg); color: #14532d; border: 1px solid #86efac; }

/* ============================================================ RESUMEN CHIPS */
.resumen-chips {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
  flex-wrap: wrap;
}
.chip {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.chip--verde    { background: var(--verde-ok-bg); color: #14532d; }
.chip--amarillo { background: var(--amarillo-bg); color: #78350f; }
.chip--rojo     { background: var(--rojo-bg);     color: #7f1d1d; }

/* ============================================================ FILTROS */
.filtros {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.875rem;
}
.pill {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--verde-borde);
  background: var(--blanco);
  color: var(--verde-oscuro);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.pill:hover     { background: var(--verde-claro); }
.pill--active   { background: var(--verde-oscuro); color: white; border-color: var(--verde-oscuro); }

/* ============================================================ TABLAS */
.tabla-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th {
  background: var(--verde-claro);
  color: var(--verde-oscuro);
  font-weight: 700;
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--verde-borde);
  white-space: nowrap;
}
.tabla td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--gris-borde); vertical-align: middle; }
.tabla tbody tr:last-child td { border-bottom: none; }
.tabla tbody tr:hover { background: #f5f3ff; }

.num      { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.cat      { color: var(--gris-suave); font-size: 12px; }
.id-col   { color: var(--gris-suave); font-size: 11px; font-family: monospace; }
.fecha-col{ white-space: nowrap; font-size: 12px; }

.fila--rojo td:first-child     { border-left: 3px solid var(--rojo); }
.fila--amarillo td:first-child { border-left: 3px solid var(--amarillo); }
.fila--verde td:first-child    { border-left: 3px solid var(--verde-medio); }

/* ============================================================ BADGES */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge--verde    { background: var(--verde-ok-bg); color: #14532d; }
.badge--amarillo { background: var(--amarillo-bg); color: #78350f; }
.badge--rojo     { background: var(--rojo-bg);     color: #7f1d1d; }

/* ============================================================ TAGS */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.tag--normal  { background: var(--verde-claro); color: var(--verde-oscuro); }
.tag--inicial { background: #ede9fe; color: #4c1d95; }

/* ============================================================ CARDS OPERADORES */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.875rem;
}
.card {
  border: 1px solid var(--gris-borde);
  border-radius: 8px;
  overflow: hidden;
}
.card__header {
  background: var(--verde-claro);
  padding: 0.625rem 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--verde-borde);
}
.card__id     { font-size: 10px; font-weight: 700; color: var(--verde-oscuro); background: var(--verde-borde); padding: 1px 6px; border-radius: 10px; font-family: monospace; }
.card__nombre { font-weight: 600; color: var(--verde-oscuro); font-size: 0.875rem; }
.card__empty  { padding: 0.75rem 0.875rem; color: var(--gris-suave); font-size: 12px; font-style: italic; }
.card__body   { padding: 0.75rem 0.875rem; display: flex; flex-direction: column; gap: 0.45rem; }

/* ============================================================ BARRAS */
.bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 40px;
  align-items: center;
  gap: 0.5rem;
  font-size: 12px;
}
.bar-label { color: var(--gris-texto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--verde-claro); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill  { background: var(--verde-medio); height: 100%; border-radius: 4px; transition: width 0.4s ease; min-width: 4px; }
.bar-val   { text-align: right; font-weight: 700; color: var(--verde-oscuro); font-variant-numeric: tabular-nums; }
.bar-aseos { font-weight: 400; font-size: 0.78em; color: var(--gris-suave); margin-left: 4px; }

/* ============================================================ DROPDOWN PC (debajo del input) */
.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--blanco);
  border: 1.5px solid var(--verde-borde);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.search-dropdown.abierto { display: block; }
.search-dropdown__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s;
}
.search-dropdown__item:hover { background: var(--verde-claro); }
.search-dropdown__item.activo { background: var(--verde-claro); font-weight: 700; color: var(--verde-oscuro); }
.search-dropdown__item-id { font-size: 10px; color: var(--gris-suave); font-family: monospace; background: var(--verde-borde); padding: 1px 5px; border-radius: 8px; }
@media (max-width: 640px) {
  .search-dropdown { display: none !important; }
}

/* ============================================================ SEARCHABLE SELECT */
.search-select {
  position: relative;
  width: 100%;
  max-width: 320px;
  margin-bottom: 0.875rem;
  z-index: 50;
}
.search-select__input {
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 2.25rem;
  border: 1.5px solid var(--verde-borde);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--gris-texto);
  background: var(--blanco);
  outline: none;
  transition: border-color 0.15s;
}
.search-select__input:focus { border-color: var(--verde-medio); }
.search-select__input::placeholder { color: var(--gris-suave); }
.search-select__icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: var(--gris-suave);
  pointer-events: none;
}
.search-select__clear {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--gris-suave);
  cursor: pointer;
  display: none;
  padding: 0 0.2rem;
  font-family: inherit;
}
.search-select__clear:hover { color: var(--rojo); }
/* ============================================================ OVERLAY SELECTOR (móvil) */
.overlay-selector {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6vh;
}
.overlay-selector.abierto { display: flex; }
.overlay-selector__panel {
  background: var(--blanco);
  border-radius: 12px;
  width: 94%;
  max-width: 400px;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  overflow: hidden;
}
.overlay-selector__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--gris-borde);
  background: var(--verde-claro);
}
.overlay-selector__search {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--verde-borde);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.overlay-selector__search:focus { border-color: var(--verde-medio); }
.overlay-selector__close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--gris-suave);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}
.overlay-selector__list { overflow-y: auto; flex: 1; }
.overlay-selector__item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s;
  font-size: 15px;
}
.overlay-selector__item:hover,
.overlay-selector__item:active { background: var(--verde-claro); }
.overlay-selector__item.activo { background: var(--verde-claro); font-weight: 700; color: var(--verde-oscuro); }
.overlay-selector__item-id {
  font-size: 11px; font-weight: 700; color: var(--verde-oscuro);
  background: var(--verde-borde); padding: 2px 6px; border-radius: 10px; font-family: monospace;
}
.overlay-selector__item-name { color: var(--gris-texto); }
.overlay-selector__empty { padding: 1rem; text-align: center; color: var(--gris-suave); font-style: italic; }

/* ============================================================ ESTADOS */
.loading { color: var(--gris-suave); font-style: italic; padding: 1.5rem 0; text-align: center; font-size: 13px; }
.empty   { color: var(--gris-suave); font-size: 13px; padding: 1rem 0; text-align: center; font-style: italic; }

/* ============================================================ FILA DETALLE (oculta por defecto, solo visible en móvil al tocar) */
tr.fila-detalle { display: none; }
tr.fila-detalle.abierto { display: none; }

/* ============================================================ FOOTER */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 11px;
  color: var(--gris-suave);
  border-top: 1px solid var(--gris-borde);
  margin-top: 1rem;
}

/* ============================================================ RESPONSIVE */
@media (max-width: 640px) {
  .header__inner { padding: 0.75rem 1rem 0.4rem; }
  .nav           { padding: 0 1rem; }
  .main          { padding: 0.75rem 0.5rem 3rem; }
  .section       { padding: 0.75rem; border-radius: 8px; }
  .cards-grid    { grid-template-columns: 1fr; }
  .bar-row       { grid-template-columns: 90px 1fr 36px; }

  /* Ocultar columnas secundarias en móvil */
  .hide-mobile { display: none !important; }

  /* Tabla más compacta */
  .tabla th { padding: 0.4rem 0.5rem; font-size: 10px; }
  .tabla td { padding: 0.4rem 0.5rem; font-size: 12px; }

  /* Producto más ancho, sin truncar */
  .col-producto { min-width: 100px; }

  /* Stock y estado centrados */
  .col-stock { text-align: center; }

  /* Filtros scroll horizontal */
  .filtros { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.25rem; }
  .filtros::-webkit-scrollbar { display: none; }

  /* Fila expandible en móvil */
  .tabla tbody tr:not(.fila-detalle) { cursor: pointer; }
  tr.fila-detalle { display: none; }
  tr.fila-detalle.abierto { display: table-row; }
  .fila-detalle td {
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border-bottom: 2px solid var(--verde-borde);
    font-size: 12px;
  }
  .detalle-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem 1rem;
  }
  .detalle-item { display: flex; flex-direction: column; }
  .detalle-label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--gris-suave); letter-spacing: 0.03em; }
  .detalle-valor { font-size: 13px; font-weight: 600; color: var(--gris-texto); }
}
