/* ===== Base ===== */
:root {
  --primary: #2563eb;
  --secondary: #0c0187;
  --font: #060a2e;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f2f4f8;
  color: var(--font);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: linear-gradient(120deg, var(--secondary), var(--primary));
  color: #fff;
}
.header-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.header-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-img {
  height: 40px;
  width: auto;
  object-fit: contain;
}
.logo-text { font-size: 20px; font-weight: 800; letter-spacing: 2px; }
.header-title h1 { font-size: 18px; font-weight: 600; }
.header-title p { font-size: 12px; opacity: 0.75; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.version-badge {
  font-size: 12px; font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.3);
  white-space: nowrap;
}

/* ===== Layout ===== */
.container {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 1px 3px rgba(15,23,42,0.06);
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--secondary);
}

/* ===== Form ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: #374151; }

input[type="text"], input[type="email"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: #1f2937;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.period-row { display: flex; gap: 10px; }
.period-row select { flex: 1; }

/* ===== Navegación ===== */
.header-link {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.header-link:hover { background: rgba(255,255,255,0.28); }
.back-link {
  display: inline-block;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 14px;
}
.back-link:hover { text-decoration: underline; }
.container-wide { max-width: 1100px; }

/* ===== Toolbar / filtros ===== */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="text"] { min-width: 220px; }
.toolbar select { min-width: 160px; }

/* ===== Badges ===== */
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-new  { background: #ede9fe; color: #5b21b6; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ===== Tablas de archivos / catálogo ===== */
.file-table td { vertical-align: middle; }
.f-det { color: #64748b; font-size: 12px; }
.card-hint { font-size: 12px; color: #64748b; margin-top: 10px; line-height: 1.5; }
.card-hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; }
td.cbx { width: 36px; text-align: center; }
td input[type="checkbox"] { transform: scale(1.15); cursor: pointer; }
td input[type="text"], td select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
  color: #1f2937;
}
td.mono { font-family: Consolas, monospace; white-space: nowrap; }
.count-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  background: #eef2ff;
  color: var(--secondary);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.import-preview {
  margin-top: 12px;
  border: 1px dashed #c7d2fe;
  border-radius: 10px;
  background: #f5f7ff;
  padding: 14px 16px;
  font-size: 12px;
  color: #3730a3;
  line-height: 1.6;
}
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-top: 6px; }
.stat { border: 1px solid #e2e8f0; border-radius: 10px; padding: 12px 14px; background: #f8fafc; }
.stat b { font-size: 22px; color: var(--secondary); display: block; }
.stat span { font-size: 12px; color: #64748b; }
.repro-note {
  margin-top: 14px;
  padding: 10px 14px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  font-size: 12px;
  color: #075985;
  line-height: 1.5;
}

/* ===== Botones ===== */
.btn {
  padding: 9px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f1f5f9; border-color: #94a3b8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-dirty { box-shadow: 0 0 0 2px #f59e0b; }
.btn-secondary {
  background: var(--secondary);
  border-color: var(--secondary);
  color: #fff;
}
.btn-secondary:hover:not(:disabled) { background: #0a0169; }
.btn-large { padding: 11px 22px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-reprocesar {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  background: #fff7ed;
  color: #b45309;
  cursor: pointer;
  white-space: nowrap;
}
.btn-reprocesar:hover { background: #ffedd5; }
.btn-danger {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  background: #fef2f2;
  color: #b91c1c;
  cursor: pointer;
  white-space: nowrap;
}
.btn-danger:hover { background: #fee2e2; }

.actions-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }

/* ===== Lista de archivos ===== */
.file-list { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  font-size: 13px;
}
.file-item .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 11px; font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  flex-shrink: 0;
}
.badge-ok    { background: #dcfce7; color: #166534; }
.badge-error { background: #fee2e2; color: #991b1b; }
.badge-warn  { background: #fef3c7; color: #92400e; }
.file-empty { color: #94a3b8; font-size: 13px; padding: 8px 2px; }

/* ===== Tabla resultados ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #e2e8f0; }
th { background: #f1f5f9; font-weight: 700; color: #475569; }
td .btn { padding: 5px 10px; font-size: 12px; }
#resultTable { table-layout: fixed; }
#resultTable th:nth-child(1), #resultTable td:nth-child(1) { width: 22%; }
#resultTable th:nth-child(2), #resultTable td:nth-child(2) { width: 10%; }
#resultTable th:nth-child(3), #resultTable td:nth-child(3) { width: 53%; word-wrap: break-word; }
#resultTable th:nth-child(4), #resultTable td:nth-child(4) { width: 15%; }

/* ===== Overlay ===== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.overlay-box {
  background: #fff;
  border-radius: 12px;
  padding: 28px 34px;
  width: 360px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.spinner {
  width: 40px; height: 40px;
  margin: 0 auto 14px;
  border: 4px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#overlayTexto { font-weight: 600; font-size: 14px; }
.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  margin-top: 14px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: #2563eb;
  border-radius: 999px;
  transition: width 0.3s;
}
.overlay-detalle { margin-top: 10px; font-size: 12px; color: #64748b; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Error detail table ===== */
.error-detail-row td {
  padding: 0 10px 10px 10px;
  background: #fef2f2;
  border-bottom: 2px solid #fecaca;
}
.error-detail-row:hover td {
  background: #fef2f2;
}
.error-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 6px;
  background: #fff;
  border: 1px solid #fecaca;
  border-radius: 6px;
  overflow: hidden;
  table-layout: fixed;
}
.error-detail-table th {
  background: #fee2e2;
  color: #991b1b;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px;
  text-align: left;
}
.error-detail-table td {
  border-bottom: 1px solid #fecaca;
  padding: 6px 8px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.error-detail-table th:nth-child(1), .error-detail-table td:nth-child(1) { width: 10%; }
.error-detail-table th:nth-child(2), .error-detail-table td:nth-child(2) { width: 7%; text-align: right; }
.error-detail-table th:nth-child(3), .error-detail-table td:nth-child(3) { width: 7%; text-align: center; }
.error-detail-table th:nth-child(4), .error-detail-table td:nth-child(4) { width: 16%; }
.error-detail-table th:nth-child(5), .error-detail-table td:nth-child(5) { width: 20%; font-family: Consolas, monospace; font-size: 11px; }
.error-detail-table th:nth-child(6), .error-detail-table td:nth-child(6) { width: 40%; }
.error-toggle-btn {
  border-color: #fca5a5 !important;
  color: #991b1b !important;
  background: #fff !important;
  font-size: 11px !important;
  margin-left: 6px;
  padding: 2px 8px !important;
  cursor: pointer;
}
.error-toggle-btn:hover {
  background: #fee2e2 !important;
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .header { flex-wrap: wrap; padding: 12px 16px; }
}
