/* =========================================================================
       VARIABLES CSS - Paleta de colores y tokens de diseño
       Definidos globalmente para uso en todo el sistema.
    ========================================================================= */
    :root {
      /* Azul principal */
      --blue:    #0C447C;   /* Topbar, botones primarios, tabs activos, links */
      --blue-l:  #E6F1FB;   /* Fondos de elementos azules claros, badges info */
      --blue-m:  #185FA5;   /* Hover del color principal */
      --blue-b:  #B5D4F4;   /* Bordes azules, separadores */

      /* Verde - Éxito */
      --green:   #27500A;   /* Sin stock, recalls finalizados */
      --green-l: #EAF3DE;   /* Fondo verde claro */

      /* Rojo - Error / Urgente */
      --red:     #A32D2D;   /* Stock positivo, alertas urgentes */
      --red-l:   #FCEBEB;   /* Fondo rojo claro */

      /* Ámbar - Advertencia */
      --amber:   #633806;   /* Recordatorios pendientes */
      --amber-l: #FAEEDA;   /* Fondo ámbar claro */

      /* Grises */
      --gray:    #5F5E5A;   /* Texto secundario, estados cerrados */
      --gray-l:  #F1EFE8;   /* Fondo gris claro, encabezados de tabla */

      /* Textos */
      --text:    #1a1a1a;   /* Texto principal */
      --text2:   #5F5E5A;   /* Texto secundario / muted */

      /* Superficies */
      --bg:      #F8F7F4;   /* Fondo general de la aplicación */
      --surface: #ffffff;   /* Fondo de panels y cards */

      /* Bordes y radios */
      --border:     rgba(0,0,0,.1);  /* Bordes suaves */
      --radius:     8px;              /* Radio de bordes estándar */
      --radius-lg:  12px;             /* Radio de bordes para cards grandes */

      /* Sombras */
      --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
      --shadow-md: 0 4px 12px rgba(0,0,0,.10);
    }

    /* =========================================================================
       RESET Y BASE
    ========================================================================= */
    *, *::before, *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: 'Google Sans', 'Segoe UI', system-ui, sans-serif;
      font-size: 14px;
      background: var(--bg);
      color: var(--text);
      line-height: 1.5;
      min-height: 100vh;
    }

    a { color: var(--blue); text-decoration: none; }
    a:hover { text-decoration: underline; }

    /* =========================================================================
       LOADER - Pantalla de carga inicial
    ========================================================================= */
    #loader {
      position: fixed;
      inset: 0;
      background: var(--blue);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 9999;
      transition: opacity .4s;
    }
    #loader.hide {
      opacity: 0;
      pointer-events: none;
    }
    .loader-logo {
      font-size: 28px;
      font-weight: 700;
      color: #fff;
      letter-spacing: -0.5px;
    }
    .loader-logo span { color: var(--blue-b); font-weight: 400; }
    .loader-spinner {
      margin-top: 24px;
      width: 32px; height: 32px;
      border: 3px solid rgba(255,255,255,.3);
      border-top-color: #fff;
      border-radius: 50%;
      animation: spin .8s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* =========================================================================
       TOPBAR FIJA
    ========================================================================= */
    #topbar {
      position: fixed;
      top: 0; left: 0; right: 0;
      height: 56px;
      background: var(--blue);
      display: flex;
      align-items: center;
      padding: 0 20px;
      gap: 8px;
      z-index: 100;
      box-shadow: 0 2px 8px rgba(0,0,0,.2);
    }

    /* Logo en la topbar */
    .topbar-logo {
      font-size: 18px;
      font-weight: 700;
      color: #fff;
      margin-right: 16px;
      white-space: nowrap;
      letter-spacing: -0.3px;
    }
    /* "Manager" en gris claro, sin negrita */
    .topbar-logo span {
      font-weight: 400;
      color: var(--blue-b);
    }

    /* Tabs de navegación principal */
    .topbar-tabs {
      display: flex;
      gap: 2px;
      flex: 1;
    }
    .tab-btn {
      padding: 6px 16px;
      border: none;
      background: transparent;
      color: rgba(255,255,255,.75);
      font-size: 14px;
      font-family: inherit;
      cursor: pointer;
      border-radius: var(--radius);
      transition: background .15s, color .15s;
      white-space: nowrap;
    }
    .tab-btn:hover {
      background: rgba(255,255,255,.12);
      color: #fff;
    }
    .tab-btn.active {
      background: rgba(255,255,255,.18);
      color: #fff;
      font-weight: 600;
    }

    /* Usuario y botón Nuevo Recall */
    .topbar-right {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-left: auto;
    }
    .topbar-user {
      font-size: 13px;
      color: var(--blue-b);
    }

    /* Botón primario azul (también reutilizado en toda la app) */
    .btn-primary {
      padding: 7px 16px;
      background: #fff;
      color: var(--blue);
      border: none;
      border-radius: var(--radius);
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      font-family: inherit;
      transition: background .15s, box-shadow .15s;
    }
    .btn-primary:hover {
      background: var(--blue-l);
      box-shadow: var(--shadow-sm);
    }

    /* =========================================================================
       LAYOUT PRINCIPAL (bajo la topbar)
    ========================================================================= */
    #app {
      display: none; /* Oculto hasta que cargue el usuario */
      padding-top: 56px; /* Compensar la topbar fija */
      min-height: 100vh;
    }

    /* Cada sección/tab es un bloque que se muestra/oculta */
    .section {
      display: none;
      padding: 24px 20px;
      max-width: 1200px;
      margin: 0 auto;
    }
    .section.active { display: block; }

    /* =========================================================================
       TOAST - Notificaciones flotantes
    ========================================================================= */
    #toast-container {
      position: fixed;
      bottom: 24px;
      right: 24px;
      z-index: 9998;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }
    .toast {
      padding: 12px 18px;
      border-radius: var(--radius);
      font-size: 13px;
      font-weight: 500;
      color: #fff;
      box-shadow: var(--shadow-md);
      animation: toastIn .25s ease;
      max-width: 320px;
    }
    .toast.ok  { background: var(--green); }
    .toast.err { background: var(--red); }
    .toast.info { background: var(--blue); }
    @keyframes toastIn {
      from { opacity: 0; transform: translateY(12px); }
      to   { opacity: 1; transform: translateY(0); }
    }

    /* =========================================================================
       MODAL - Overlay genérico para dialogs
    ========================================================================= */
    .modal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,.45);
      z-index: 500;
      align-items: center;
      justify-content: center;
    }
    .modal-overlay.open { display: flex; }

    .modal {
      background: var(--surface);
      border-radius: var(--radius-lg);
      padding: 28px;
      width: 600px;
      max-width: 95vw;
      max-height: 90vh;
      overflow-y: auto;
      box-shadow: 0 20px 60px rgba(0,0,0,.25);
    }
    .modal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 20px;
    }
    .modal-title {
      font-size: 18px;
      font-weight: 700;
      color: var(--blue);
    }
    .modal-close {
      background: none;
      border: none;
      font-size: 20px;
      cursor: pointer;
      color: var(--text2);
      line-height: 1;
      padding: 4px;
      border-radius: 4px;
    }
    .modal-close:hover { background: var(--gray-l); }

    /* =========================================================================
       FORMULARIO - Estilos globales para inputs y labels
    ========================================================================= */
    .form-group {
      margin-bottom: 16px;
    }
    .form-label {
      display: block;
      font-size: 12px;
      font-weight: 600;
      color: var(--text2);
      text-transform: uppercase;
      letter-spacing: .5px;
      margin-bottom: 5px;
    }
    .form-control {
      width: 100%;
      padding: 9px 12px;
      border: 1px solid var(--border);
      border-radius: var(--radius);
      font-size: 14px;
      font-family: inherit;
      color: var(--text);
      background: var(--surface);
      transition: border-color .15s, box-shadow .15s;
      outline: none;
    }
    .form-control:focus {
      border-color: var(--blue);
      box-shadow: 0 0 0 3px rgba(12,68,124,.12);
    }
    .form-control[readonly] {
      background: var(--gray-l);
      color: var(--text2);
      cursor: default;
    }
    textarea.form-control { resize: vertical; min-height: 80px; }
    select.form-control { appearance: auto; }

    .form-row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
    }

    /* Sección ANMAT dentro del formulario — visualmente diferenciada */
    .anmat-section {
      background: var(--blue-l);
      border: 1px solid var(--blue-b);
      border-radius: var(--radius);
      padding: 16px;
      margin-bottom: 16px;
    }
    .anmat-section-title {
      font-size: 12px;
      font-weight: 700;
      color: var(--blue);
      text-transform: uppercase;
      letter-spacing: .5px;
      margin-bottom: 12px;
    }

    /* =========================================================================
       CARDS DE MÉTRICAS (Dashboard)
    ========================================================================= */
    .metrics-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 16px;
      margin-bottom: 24px;
    }
    .metric-card {
      background: var(--surface);
      border-radius: var(--radius-lg);
      padding: 20px;
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border);
    }
    .metric-label {
      font-size: 12px;
      font-weight: 600;
      color: var(--text2);
      text-transform: uppercase;
      letter-spacing: .5px;
      margin-bottom: 6px;
    }
    .metric-value {
      font-size: 36px;
      font-weight: 700;
      line-height: 1;
    }
    .metric-card.blue  .metric-value { color: var(--blue); }
    .metric-card.dark  .metric-value { color: var(--text); }
    .metric-card.red   .metric-value { color: var(--red); }
    .metric-card.green .metric-value { color: var(--green); }

    /* Alerta roja de stock positivo */
    .stock-alert {
      display: none; /* Se muestra via JS si hay stock positivo */
      background: var(--red-l);
      border: 1px solid var(--red);
      border-left-width: 4px;
      border-radius: var(--radius);
      padding: 14px 16px;
      margin-bottom: 20px;
      color: var(--red);
      font-weight: 600;
      font-size: 14px;
    }
    .stock-alert.visible { display: block; }

    /* =========================================================================
       LAYOUT DE DOS PANELES (Dashboard inferior)
    ========================================================================= */
    .dashboard-panels {
      display: grid;
      grid-template-columns: 340px 1fr;
      gap: 20px;
    }

    .panel {
      background: var(--surface);
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      box-shadow: var(--shadow-sm);
      overflow: hidden;
    }
    .panel-header {
      padding: 14px 18px;
      border-bottom: 1px solid var(--border);
      font-weight: 700;
      font-size: 13px;
      color: var(--text);
      background: var(--gray-l);
    }
    .panel-body {
      padding: 12px;
    }

    /* =========================================================================
       TABLA DE URGENTES (Panel izquierdo del Dashboard)
    ========================================================================= */
    .urgente-item {
      padding: 10px 12px;
      border-radius: var(--radius);
      border: 1px solid var(--red);
      background: var(--red-l);
      margin-bottom: 8px;
    }
    .urgente-item:last-child { margin-bottom: 0; }
    .urgente-razon {
      font-weight: 600;
      font-size: 13px;
      color: var(--red);
    }
    .urgente-detail {
      font-size: 12px;
      color: var(--text2);
      margin-top: 2px;
    }
    .urgente-btn {
      margin-top: 8px;
      padding: 4px 10px;
      font-size: 12px;
      font-weight: 600;
      background: var(--red);
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-family: inherit;
    }
    .urgente-btn:hover { background: #8b2525; }

    /* =========================================================================
       LISTA DE RECALLS ABIERTOS CON BARRA DE PROGRESO (Panel derecho del Dashboard)
    ========================================================================= */
    .recall-row {
      padding: 14px 16px;
      border-bottom: 1px solid var(--border);
      cursor: pointer;
      transition: background .12s;
    }
    .recall-row:last-child { border-bottom: none; }
    .recall-row:hover { background: var(--blue-l); }

    .recall-row-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 6px;
    }
    .recall-row-id {
      font-size: 12px;
      font-weight: 700;
      color: var(--blue);
    }
    .recall-row-producto {
      font-size: 13px;
      font-weight: 600;
      color: var(--text);
    }
    .recall-row-meta {
      font-size: 12px;
      color: var(--text2);
      margin-bottom: 8px;
    }

    /* Barra de progreso dinámica */
    .progress-bar {
      height: 6px;
      background: var(--gray-l);
      border-radius: 99px;
      overflow: hidden;
    }
    .progress-fill {
      height: 100%;
      border-radius: 99px;
      transition: width .5s ease;
    }
    /* Color de la barra según progreso (se asigna via JS con data-pct) */
    .progress-fill[data-pct="low"]    { background: var(--red); }
    .progress-fill[data-pct="mid"]    { background: var(--amber); }
    .progress-fill[data-pct="high"]   { background: var(--blue); }
    .progress-fill[data-pct="done"]   { background: var(--green); }

    .progress-label {
      display: flex;
      justify-content: space-between;
      font-size: 11px;
      color: var(--text2);
      margin-top: 4px;
    }

    /* =========================================================================
       SECCIÓN: GESTIÓN DE RECALLS
       Grilla de cards 3 columnas + detalle desplegable
    ========================================================================= */
    .recalls-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 16px;
      margin-bottom: 24px;
    }

    .recall-card {
      background: var(--surface);
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      padding: 18px;
      cursor: pointer;
      transition: box-shadow .15s, border-color .15s;
      box-shadow: var(--shadow-sm);
    }
    .recall-card:hover {
      box-shadow: var(--shadow-md);
      border-color: var(--blue-b);
    }
    .recall-card.selected {
      border-color: var(--blue);
      box-shadow: 0 0 0 2px var(--blue-b);
    }
    .recall-card-id {
      font-size: 11px;
      font-weight: 700;
      color: var(--blue);
      text-transform: uppercase;
      letter-spacing: .5px;
      margin-bottom: 4px;
    }
    .recall-card-producto {
      font-size: 15px;
      font-weight: 700;
      color: var(--text);
      margin-bottom: 4px;
    }
    .recall-card-lote {
      font-size: 12px;
      color: var(--text2);
      margin-bottom: 12px;
    }
    .recall-card-footer {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    /* =========================================================================
       DETALLE DE CLIENTES - Tabla completa con filtros y acciones
    ========================================================================= */
    #detalle-section {
      display: none; /* Se muestra cuando se selecciona un recall */
      background: var(--surface);
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      box-shadow: var(--shadow-sm);
      overflow: hidden;
      margin-top: 4px;
    }
    #detalle-section.visible { display: block; }

    .detalle-header {
      padding: 16px 20px;
      background: var(--gray-l);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }
    .detalle-title {
      font-weight: 700;
      font-size: 15px;
      color: var(--text);
      flex: 1;
    }

    /* Barra de filtros */
    .filter-bar {
      display: flex;
      gap: 8px;
      align-items: center;
      padding: 12px 16px;
      border-bottom: 1px solid var(--border);
      flex-wrap: wrap;
    }
    .filter-input {
      padding: 7px 12px;
      border: 1px solid var(--border);
      border-radius: var(--radius);
      font-size: 13px;
      font-family: inherit;
      outline: none;
      width: 220px;
    }
    .filter-input:focus { border-color: var(--blue); }

    .filter-select {
      padding: 7px 10px;
      border: 1px solid var(--border);
      border-radius: var(--radius);
      font-size: 13px;
      font-family: inherit;
      outline: none;
      background: var(--surface);
      cursor: pointer;
    }
    .filter-select:focus { border-color: var(--blue); }

    /* Tabla de clientes */
    .table-wrap {
      overflow-x: auto;
    }
    table.data-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 13px;
    }
    .data-table th {
      padding: 10px 12px;
      background: var(--gray-l);
      text-align: left;
      font-size: 11px;
      font-weight: 700;
      color: var(--text2);
      text-transform: uppercase;
      letter-spacing: .4px;
      border-bottom: 1px solid var(--border);
      white-space: nowrap;
    }
    .data-table td {
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      vertical-align: middle;
      color: var(--text);
    }
    .data-table tr:last-child td { border-bottom: none; }
    .data-table tr:hover td { background: var(--blue-l); }
    .data-table .muted { color: var(--text2); font-style: italic; }

    /* =========================================================================
       BADGES DE ESTADO
       Cada estado tiene un color y clase CSS definidos en el manual.
    ========================================================================= */
    .badge {
      display: inline-flex;
      align-items: center;
      padding: 3px 9px;
      border-radius: 99px;
      font-size: 11px;
      font-weight: 600;
      white-space: nowrap;
    }

    /* Pendiente de notificación */
    .b-pend    { background: var(--amber-l); color: var(--amber); }
    /* Notificado */
    .b-notif   { background: var(--blue-l);  color: var(--blue);  }
    /* Recordatorios 1, 2 y 3 */
    .b-rec     { background: var(--amber-l); color: var(--amber); }
    /* Con stock declarado */
    .b-stock   { background: var(--red-l);   color: var(--red);   }
    /* Sin stock */
    .b-sinstock { background: var(--green-l); color: var(--green); }
    /* Cerrado sin respuesta */
    .b-cerrado { background: var(--gray-l);  color: var(--gray);  }
    /* Producto retirado */
    .b-retirado { background: #FBEAF0;       color: #72243E;      }
    /* Rechazado */
    .b-rech {
      background: var(--gray-l);
      color: var(--gray);
      border: 1px solid var(--border);
    }
    /* Recall abierto */
    .b-abierto { background: var(--blue-l);  color: var(--blue);  }
    /* Recall finalizado */
    .b-fin     { background: var(--green-l); color: var(--green); }

    /* =========================================================================
       BOTONES DE ACCIÓN EN LA TABLA
    ========================================================================= */
    .btn-sm {
      padding: 4px 10px;
      border-radius: 4px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      border: 1px solid transparent;
      font-family: inherit;
      transition: background .12s;
    }
    .btn-blue  { background: var(--blue-l);  color: var(--blue);  border-color: var(--blue-b); }
    .btn-blue:hover  { background: var(--blue-b); }
    .btn-red   { background: var(--red-l);   color: var(--red);   border-color: var(--red); }
    .btn-red:hover   { background: #f8d5d5; }
    .btn-green { background: var(--green-l); color: var(--green); border-color: var(--green); }
    .btn-green:hover { background: #d5edc0; }
    .btn-gray  { background: var(--gray-l);  color: var(--gray);  border-color: var(--border); }
    .btn-gray:hover  { background: #e0ddd4; }

    /* Botón de cerrar recall (section Auditoría) */
    .btn-outline-red {
      padding: 6px 14px;
      border-radius: var(--radius);
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      font-family: inherit;
      background: transparent;
      border: 1px solid var(--red);
      color: var(--red);
      transition: background .12s;
    }
    .btn-outline-red:hover { background: var(--red-l); }

    /* =========================================================================
       DRAG & DROP ZONA DE CSV
    ========================================================================= */
    .csv-dropzone {
      border: 2px dashed var(--blue-b);
      border-radius: var(--radius);
      padding: 24px;
      text-align: center;
      cursor: pointer;
      color: var(--text2);
      font-size: 13px;
      transition: background .15s, border-color .15s;
      background: var(--blue-l);
    }
    .csv-dropzone:hover,
    .csv-dropzone.drag-over {
      border-color: var(--blue);
      background: #d8eaf8;
    }
    .csv-dropzone .drop-icon { font-size: 28px; margin-bottom: 6px; }
    .csv-dropzone .drop-hint { color: var(--blue); font-weight: 600; }
    .csv-filename {
      margin-top: 8px;
      font-size: 12px;
      color: var(--green);
      font-weight: 600;
    }
    #csv-input { display: none; }

    /* =========================================================================
       SECCIÓN AUDITORÍA Y CIERRE - Solapas internas
    ========================================================================= */
    .sub-tabs {
      display: flex;
      gap: 2px;
      margin-bottom: 20px;
      background: var(--gray-l);
      border-radius: var(--radius);
      padding: 4px;
      width: fit-content;
    }
    .sub-tab {
      padding: 6px 16px;
      border: none;
      background: transparent;
      font-size: 13px;
      font-family: inherit;
      cursor: pointer;
      border-radius: 6px;
      color: var(--text2);
      font-weight: 500;
      transition: background .12s, color .12s;
    }
    .sub-tab.active {
      background: var(--surface);
      color: var(--blue);
      font-weight: 700;
      box-shadow: var(--shadow-sm);
    }
    .sub-section { display: none; }
    .sub-section.active { display: block; }

    /* =========================================================================
       MODAL DE CIERRE DE RECALL
    ========================================================================= */
    #modal-cierre .modal { width: 520px; }

    /* =========================================================================
       MODAL DE RETIRO (confirmar NC)
    ========================================================================= */
    #modal-retiro .modal { width: 420px; }

    /* =========================================================================
       BOTÓN ENVIAR MAILS (dentro del detalle)
    ========================================================================= */
    .btn-enviar-mails {
      padding: 8px 18px;
      background: var(--blue);
      color: #fff;
      border: none;
      border-radius: var(--radius);
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      font-family: inherit;
      transition: background .15s;
    }
    .btn-enviar-mails:hover { background: var(--blue-m); }

    /* =========================================================================
       ESTADO VACÍO (cuando no hay datos)
    ========================================================================= */
    .empty-state {
      text-align: center;
      padding: 48px 24px;
      color: var(--text2);
    }
    .empty-state-icon { font-size: 40px; margin-bottom: 12px; }
    .empty-state-text { font-size: 15px; font-weight: 600; }
    .empty-state-sub  { font-size: 13px; margin-top: 4px; }

    /* =========================================================================
       RESPONSIVE (adaptaciones para pantallas medianas)
    ========================================================================= */
    @media (max-width: 900px) {
      .metrics-grid { grid-template-columns: repeat(2, 1fr); }
      .dashboard-panels { grid-template-columns: 1fr; }
      .recalls-grid { grid-template-columns: repeat(2, 1fr); }
    }
    @media (max-width: 600px) {
      .recalls-grid { grid-template-columns: 1fr; }
      .metrics-grid { grid-template-columns: repeat(2, 1fr); }
      .form-row { grid-template-columns: 1fr; }