/* ==========================================================================
   1. VARIABLES GLOBALES Y RESET (Base: styles2.css)
   Manual de marca 2026: principal #061E44, secundario #0357A0, detalles
   #FF9D00, tipografía Rethink Sans (RethinkSans-Regular/Bold.ttf deben
   estar en la misma carpeta que este archivo).
   ========================================================================== */
@font-face {
  font-family: 'Rethink Sans';
  src: url('RethinkSans-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Rethink Sans';
  src: url('RethinkSans-Bold.ttf') format('truetype');
  font-weight: 600 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --primary: #061E44;   /* Marca: color principal */
  --accent: #0357A0;    /* Marca: color secundario */
  --detalle: #FF9D00;   /* Marca: detalles (subrayados, acentos) */
  --primary-rgb: 6, 30, 68;
  --accent-rgb: 3, 87, 160;
  --detalle-rgb: 255, 157, 0;
  --text: #1a2640;
  --muted: #6b7a90;
  --line: #d3deec;
  --bg: #f2f6fb;
  --panel: #ffffff;
  --shadow: 0 10px 30px rgba(6, 30, 68, .14);
  --radius: 6px;
  --font: 'Rethink Sans', "Segoe UI", Roboto, Arial, sans-serif;
  
  /* Variables de estado */
  --success-bg: #d1e7dd;
  --success-text: #0f5132;
  --error-bg: #f8d7da;
  --error-text: #842029;
  --warn-bg: #fff3cd;
  --warn-text: #664d03;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); }
button, input, select, textarea { font-family: var(--font); }

/* Fondo Global */
.bg { position: fixed; inset: 0; background: linear-gradient(180deg, #f6f8fc, #eaf0f8); z-index: -1; }

/* Control de Vistas (SPA) */
.view { display: none; padding: 40px 16px; }
.view.active { display: block; }

/* ==========================================================================
   2. COMPONENTES GENERALES (Tarjetas, Botones, Inputs)
   ========================================================================== */

/* Tarjetas */
.card {
  width: min(1100px, 96vw);
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid #e7ebf2;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card { width: min(650px, 94vw); padding: 28px 28px 18px; }
.form-card { overflow: hidden; }
.selector-card { overflow: hidden; }

/* Branding */
.brand-row, .tqa-brand {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid #eef2f8;
}
.brand-logo-mini { width: 44px; height: 44px; object-fit: contain; }
.brand-mini-text { font-weight: 700; letter-spacing: .6px; color: var(--primary); }
.brand-mini-sub { font-size: 13px; color: var(--muted); }

/* Login Branding Specifics */
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.brand-logo { width: 140px; height: auto; display: block; transform: scale(2.3); }
.brand-sub { color: var(--muted); }

/* Formularios */
.form { margin-top: 18px; }
.field { margin: 14px 0; }

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  background: #f7f9fc;
  border-radius: 4px;
  outline: none;
  font-size: 14px;
}
textarea { min-height: 120px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: rgba(var(--accent-rgb), .55);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .12);
  background: #fff;
}

label { display: block; margin: 14px 0 6px; font-size: 13px; }
.req { color: #e24a4a; font-weight: 700; }

/* Botones */
.btn {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn.full { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 13px; }

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(.97); }

.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: rgba(var(--accent-rgb), .08); }

.btn.success { background: var(--primary); color: #fff; }
.btn.success:hover { filter: brightness(1.05); }

.icon { margin-right: 8px; }
.arrow { margin-left: 8px; font-weight: 800; }

/* Links */
.links-row { display: flex; justify-content: space-between; margin-top: 18px; }
.links-row a { color: var(--accent); text-decoration: none; font-size: 14px; }
.links-row a:hover { text-decoration: underline; }

/* Headers y Barras */
.topbar { padding: 10px 14px; border-bottom: 1px solid #eef2f8; }
.titlebar { background: var(--primary); color: #fff; padding: 14px 16px; border-bottom: 3px solid var(--detalle); }
.titlebar h2 { margin: 0; font-weight: 700; font-size: 18px; }
.note { padding: 14px 16px; color: var(--muted); font-size: 13px; }
.pad { padding: 0 16px 16px; }

/* Grids Generales */
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.col { padding: 0 6px; }

/* Actions footer */
.actions {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 16px 22px; border-top: 1px solid #eef2f8; margin-top: 14px;
}
.actions .right { display: flex; gap: 10px; align-items: center; }

/* ==========================================================================
   3. TABLAS GENERALES Y DATA
   ========================================================================== */
.table-wrap { overflow: auto; padding: 0 16px 16px; }

.fin-table {
  width: 100%; min-width: 760px;
  border-collapse: collapse;
  border: 1px solid #eef2f8;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.fin-table th, .fin-table td {
  border-bottom: 1px solid #eef2f8;
  padding: 10px;
  vertical-align: middle;
}
.fin-table th { background: #f2f6fb; font-size: 13px; color: var(--primary); text-align: left; }
.fin-table tr:hover { background: rgba(var(--accent-rgb), .04); }

/* Badges Genéricos */
.badge {
  display: inline-block; padding: 4px 10px;
  border-radius: 999px; font-size: 12px;
  border: 1px solid #e7ebf2; background: #f7f9fc;
  color: #2a3550; white-space: nowrap;
}
.badge.ok { border-color: rgba(27, 94, 32, .18); background: #e8f5e9; color: #1b5e20; }
.badge.warn { border-color: rgba(var(--detalle-rgb), .35); background: #fff4e0; color: #a35f00; }
.badge.bad { background: #ffebee; color: #c62828; border-color: #ffcdd2; }

/* Pills y Tags */
.pill {
  font-size: 12px; padding: 6px 10px; border-radius: 999px;
  border: 1px solid rgba(var(--detalle-rgb), .35);
  background: rgba(var(--detalle-rgb), .10); color: var(--primary);
  white-space: nowrap;
}
.tag {
  font-size: 12px; padding: 6px 10px; border-radius: 999px;
  border: 1px solid rgba(var(--primary-rgb), .2);
  background: rgba(var(--primary-rgb), .06); color: var(--primary);
}

/* ==========================================================================
   4. MÓDULOS ESPECÍFICOS: DASHBOARD CLIENTE
   ========================================================================== */
.dash-head { padding-top: 8px; }
.dash-head h1 { margin: 10px 0 6px; font-size: 20px; font-weight: 700; color: var(--primary); }
.dash-name { color: var(--accent); }
.dash-head p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.dash-meta { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin-top: 12px; }
.meta-box {
  border: 1px solid #eef2f8; border-radius: 12px; padding: 10px 12px; background: #fff; min-width: 160px;
}
.meta-box .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.meta-box .value { font-weight: 700; color: var(--primary); }

.years, .dash-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 12px 16px; }

.kpi-box { border: 1px solid #eef2f8; border-radius: 12px; padding: 12px; background: #fff; }
.kpi-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.kpi-title { font-weight: 700; color: var(--primary); font-size: 13px; }
.kpi-val { font-size: 22px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.kpi-val.neg { color: #d53b3b; }
.kpi-sub, .kpi-foot, .kpi-unit { font-size: 12px; color: var(--muted); }

.docs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 12px 16px 18px; }
.doc-box { border: 1px solid #eef2f8; border-radius: 12px; padding: 12px; background: #fff; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.doc-title { font-weight: 700; color: var(--primary); }
.doc-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.quick { display: grid; gap: 10px; margin-top: 10px; }
.quick-item {
  border: 1px solid #eef2f8; border-radius: 12px; padding: 12px;
  background: #fff; display: flex; justify-content: space-between;
  align-items: flex-start; gap: 10px;
}
.quick-item .label { font-size: 12px; font-weight: 700; color: var(--muted); }
.quick-item .value { font-weight: 800; color: var(--primary); }

.dashboard-footer { display: flex; justify-content: flex-end; padding-top: 12px; }

/* ==========================================================================
   5. MÓDULOS ESPECÍFICOS: NUEVO CLIENTE (Tabs & Selector)
   ========================================================================== */
.header-slim { padding: 14px 18px; border-bottom: 1px solid #eef2f8; }
.selector-body { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; padding: 48px 22px 30px; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.choice-emoji { font-size: 44px; }
.selector-footer { display: flex; justify-content: center; padding: 16px 0 26px; }

.tabs { display: flex; gap: 6px; padding: 10px 12px 0; background: #e8eef8; border-bottom: 1px solid var(--line); }
.tab {
  padding: 10px 14px; border: none; background: rgba(255, 255, 255, .45);
  color: var(--primary); cursor: pointer; border-top-left-radius: 6px; border-top-right-radius: 6px;
}
.tab.active { background: var(--accent); color: #fff; }
.tabpanel { display: none; padding: 6px 16px 18px; }
.tabpanel.active { display: block; }
.charcount { display: flex; justify-content: flex-end; color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ==========================================================================
   6. MÓDULOS ESPECÍFICOS: GESTIÓN DE CLIENTES (Toolbar)
   ========================================================================== */
.clients-toolbar { display: flex; gap: 16px; align-items: flex-end; padding: 14px 16px; border-bottom: 1px solid #eef2f8; }
.clients-toolbar .field { margin: 0; flex: 1 1 auto; }
.clients-toolbar .field input { height: 40px; width: 50%; }
.clients-actions { display: flex; gap: 10px; align-items: center; }
.clients-actions .btn { height: 40px; display: flex; align-items: center; justify-content: center; }
.clients-meta, .clients-empty { padding: 10px 16px; font-size: 13px; color: var(--muted); }

/* ==========================================================================
   7. MÓDULO CRÍTICO: CARGA DE FACTURAS (Factoring)
   ========================================================================== */
/* Estilos específicos para la barra de acción en Carga Facturas */
.action-bar {
  background: #f8f9fc;
  border: 1px solid #eef2f8;
  border-radius: 8px;
  padding: 15px 20px;
  display: flex; gap: 15px; align-items: flex-end;
  margin-bottom: 20px;
}

/* Grupos de inputs específicos de carga */
.input-group { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.input-group label { margin: 0; color: var(--muted); font-weight: 600; font-size: 12px; }
.input-group input { 
  font-family: 'Courier New', monospace; 
  font-size: 14px; 
  height: 42px; 
  border-color: #d1d9e6; 
  background: #fff; /* Asegura fondo blanco */
}

/* Importador TXT */
.txt-importer { 
  display: flex; align-items: center; gap: 8px; 
  padding-left: 15px; border-left: 1px solid #dcdfe6; height: 42px; 
}

/* Tabla Específica de Facturas (Layout Fijo) */
#tablaFacturas { 
  table-layout: fixed; 
  width: 100%; 
  min-width: 800px; 
}

/* Columnas definidas por ancho (Carga Facturas) */
.col-idx { width: 40px; text-align: center; }
.col-key { width: 320px; } 
.col-info { width: auto; } 
.col-monto { width: 120px; text-align: right; }
.col-estado { width: 120px; text-align: center; }
.col-accion { width: 60px; text-align: center; }

/* Estilos de celda tabla facturas */
#tablaFacturas th, #tablaFacturas td {
  white-space: nowrap;
  vertical-align: middle;
  padding: 8px 10px;
  font-size: 13px;
  overflow: hidden; 
  text-overflow: ellipsis;
  text-align: center; /* Alineación centrada solicitada */
}

/* Clave de acceso con fuente monoespaciada */
.key-cell { 
  font-family: 'Courier New', monospace; 
  font-size: 11px; 
  white-space: normal !important; 
  word-break: break-all; 
  line-height: 1.1; 
  color: #555; 
  text-align: left !important; /* Excepción: la clave se lee mejor a la izquierda */
}

/* Zona de Carga de Archivos (Grid) */
.support-grid { 
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; margin-top: 10px; 
}

.compact-upload { 
  border: 1px dashed #ced4da; 
  background: #fff; 
  padding: 15px; 
  border-radius: 6px; 
  display: flex; flex-direction: column; align-items: center; 
  text-align: center; gap: 8px; 
  cursor: pointer; transition: all 0.2s; 
}
.compact-upload:hover { 
  border-color: var(--accent); background: #fcfdfe; transform: translateY(-2px); 
}
.compact-upload.required { 
  border: 1px dashed var(--accent); 
  background: rgba(var(--accent-rgb), 0.03); 
}

/* Badges específicos de estado SRI */
.status-badge { padding: 3px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.status-valid { background: var(--success-bg); color: var(--success-text); }
.status-err { background: var(--error-bg); color: var(--error-text); }
.status-wait { background: var(--warn-bg); color: var(--warn-text); }

/* ==========================================================================
   8. RESPONSIVE FINAL
   ========================================================================== */
@media (max-width: 980px) {
  .docs-grid { grid-template-columns: 1fr; }
  .grid.two { grid-template-columns: 1fr; }
  .selector-body { grid-template-columns: 1fr; }
  .support-grid { grid-template-columns: 1fr; } /* Carga facturas responsive */
}

@media (max-width: 720px) {
  .clients-toolbar { flex-wrap: wrap; align-items: stretch; }
  .clients-actions { width: 100%; }
  .years, .dash-kpis { grid-template-columns: 1fr; }
  .action-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .txt-importer { border-left: none; padding-left: 0; border-top: 1px solid #dcdfe6; padding-top: 10px; margin-top: 5px; }
}

/* Contenedor de la fila */
.radio-row {
  display: flex;
  align-items: center;
  gap: 20px; /* Separación entre "Sí" y "No" */
  margin-top: 8px;
}

/* Estilo para cada opción (Bolita + Texto) */
.radio-option {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  font-weight: normal; /* Evitar negritas heredadas */
  margin: 0 !important; /* Resetear márgenes globales */
}

/* Resetear el input para que no sea gigante */
.radio-option input[type="radio"] {
  width: 18px !important;  /* Tamaño fijo */
  height: 18px !important; 
  margin: 0 8px 0 0 !important; /* Separación con el texto */
  padding: 0 !important;
  border: 1px solid var(--line) !important;
  box-shadow: none !important;
  cursor: pointer;
  accent-color: var(--accent); /* Color azul corporativo */
}

.drop-zone {
        border: 2px dashed var(--accent);
        border-radius: 8px;
        padding: 40px 20px;
        text-align: center;
        background-color: #f8fbff;
        cursor: pointer;
        transition: all 0.3s ease;
        margin-bottom: 25px;
      }
      .drop-zone:hover, .drop-zone.dragover {
        background-color: rgba(var(--accent-rgb), .08);
        border-color: var(--primary);
      }
      /* Estilos para el Drag & Drop */
      .dropzone {
          border: 2px dashed var(--accent);
          border-radius: 10px;
          padding: 40px 20px;
          text-align: center;
          background-color: #f4f8fd;
          color: var(--primary);
          cursor: pointer;
          transition: all 0.3s ease;
          margin-bottom: 20px;
      }
      .dropzone:hover, .dropzone.dragover {
          background-color: rgba(var(--accent-rgb), .08);
          border-color: var(--primary);
      }
      .dropzone i {
          font-size: 3rem;
          color: var(--accent);
          margin-bottom: 15px;
      }
      .file-list {
          display: flex;
          flex-direction: column;
          gap: 10px;
      }
      .file-item {
          display: flex;
          align-items: center;
          justify-content: space-between;
          background: #fff;
          border: 1px solid #ddd;
          padding: 10px 15px;
          border-radius: 8px;
          box-shadow: 0 2px 4px rgba(0,0,0,0.02);
      }
      .file-item-name {
          font-weight: 500;
          font-size: 14px;
          color: #333;
          display: flex;
          align-items: center;
          gap: 10px;
          flex: 1;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
      }
      .file-item-select {
          padding: 8px;
          border-radius: 5px;
          border: 1px solid #ccc;
          outline: none;
          font-family: inherit;
          flex: 1;
          max-width: 300px;
      }
      .file-item-remove {
          background: #ff4d4f;
          color: white;
          border: none;
          padding: 6px 10px;
          border-radius: 5px;
          cursor: pointer;
          margin-left: 10px;
          font-size: 12px;
      }

/* ==========================================================================
   9. MANUAL DE MARCA — títulos
   ========================================================================== */
h1, h2, h3, h4, .brand-title, .brand-mini-text { font-family: var(--font); }
.brand-title { color: var(--primary); font-weight: 700; }