/* ============================================================
   NODE-PAGOS-ADMIN · Fox Service
   Estilos minimalistas, oscuros con acento dorado (paleta Fox)
   ============================================================ */

:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1f2530;
  --border: #2a313c;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --primary: #c9a86a;          /* dorado Fox */
  --primary-hover: #d8b978;
  --danger: #f85149;
  --success: #3fb950;
  --info: #58a6ff;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --radius: 10px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

.muted { color: var(--text-muted); }
code { font-family: var(--mono); font-size: 0.9em; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at 20% 0%, rgba(201, 168, 106, 0.08), transparent 60%),
              radial-gradient(circle at 90% 90%, rgba(88, 166, 255, 0.05), transparent 50%),
              var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}
.login-brand h1 { margin-top: 0.8rem; }
.login-brand p { margin-top: 0.3rem; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), #a88a52);
  color: #0e1116;
  font-weight: 800;
  font-size: 1.25rem;
  border-radius: 12px;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 16px rgba(201, 168, 106, 0.3);
}

.login-hint {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(201, 168, 106, 0.15);
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

/* Form de configuración con un form por campo (stack vertical) */
.config-form {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
}
.config-form:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.config-form .form-group { flex: 1; margin-bottom: 0; }
.config-form .btn { flex-shrink: 0; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
  font-family: var(--font);
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #0e1116;
}
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-elev-2); text-decoration: none; }

.btn-block { width: 100%; }

.inline { display: inline; }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.topbar-left { display: flex; align-items: center; gap: 0.9rem; }
.topbar-left .brand-mark { width: 40px; height: 40px; font-size: 0.95rem; }
.topbar-title { font-size: 1.05rem; }
.topbar-sub { font-size: 0.8rem; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 0.8rem; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
}
.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.6);
}

/* ============================================================
   CONTAINER + CARDS
   ============================================================ */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* ============================================================
   FILTERS
   ============================================================ */
.filters-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1rem;
  align-items: end;
}
@media (max-width: 640px) {
  .filters-form { grid-template-columns: 1fr; }
}

/* ============================================================
   SUMMARY STATS
   ============================================================ */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
@media (max-width: 900px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr; }
}

.stat { text-align: center; padding: 1.5rem 1rem; }
.stat-value { font-size: 1.2rem; }
.diff-warn { color: #c0392b; font-weight: 600; }
.stat-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}
.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  font-family: var(--mono);
}
.stat-highlight { border-color: var(--primary); }
.stat-highlight .stat-value { color: var(--primary); }

/* ============================================================
   NIVELES-CARD — Distribución por nivel
   ============================================================ */
.niveles-card {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
}
.niveles-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.niveles-card-header h2 { margin: 0; font-size: 1rem; }
.niveles-card-header .muted { font-size: 0.8rem; }
.niveles-header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.niveles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}
.nivel-tile { padding: 0.75rem 0.9rem; }
.nivel-tile .badge { font-size: 0.75rem; }
.nivel-tile .stat-value {
  font-size: 1.45rem;
  margin-top: 0.2rem;
}
.nivel-precio { font-size: 0.75rem; margin-top: 0.15rem; }
.nivel-sin { border-style: dashed; opacity: 0.85; }

/* ============================================================
   ANUAL-CARD — Resumen anual en tabla (clickable)
   ============================================================ */
.anual-card { margin-top: 1.25rem; padding: 1rem 1.25rem; }
.anual-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}
.anual-table thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #888);
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.anual-th-num { text-align: right !important; }
.anual-table tbody tr {
  transition: background 0.12s;
}
.anual-table tbody tr:hover:not(.anual-row-empty) {
  background: rgba(201, 168, 106, 0.08);
}
.anual-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.anual-td-num { text-align: right; font-variant-numeric: tabular-nums; }
.anual-td-mes {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--primary, #c9a86a);
}
.anual-mes-corto { display: inline-block; min-width: 2.5em; }
.anual-mes-largo { font-size: 0.8rem; font-weight: 400; }
.anual-active-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--primary, #c9a86a);
  border-radius: 50%;
  margin-left: auto;
  box-shadow: 0 0 0 2px rgba(201, 168, 106, 0.25);
}
.anual-row-active { background: rgba(201, 168, 106, 0.1); }
.anual-row-active td { font-weight: 600; }
.anual-row-empty { opacity: 0.4; cursor: default; }
.anual-row-empty td { color: var(--muted, #888); }

.anual-table tfoot th {
  text-align: left;
  font-weight: 600;
  padding: 0.7rem 0.6rem;
  border-top: 1px solid rgba(201, 168, 106, 0.4);
  color: var(--primary, #c9a86a);
  background: rgba(201, 168, 106, 0.06);
  font-variant-numeric: tabular-nums;
}
.anual-total-row .anual-td-num { text-align: right; }

@media (max-width: 640px) {
  .anual-table { font-size: 0.82rem; }
  .anual-mes-largo { display: none; }
}

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { padding: 0; overflow: hidden; }
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}
.table-header-tools {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.table-search {
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  min-width: 240px;
}
.table-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(201, 168, 106, 0.15);
}

/* Botones de export */
.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn-export:hover {
  background: var(--bg-elev);
  text-decoration: none;
  border-color: var(--primary);
}
.btn-export:active { transform: translateY(1px); }
.btn-export svg { flex-shrink: 0; }
.btn-export-pdf  { color: #ff8a82; border-color: rgba(248, 81, 73, 0.4); }
.btn-export-pdf:hover  { background: rgba(248, 81, 73, 0.1); }
.btn-export-xlsx { color: #6fcf97; border-color: rgba(63, 185, 80, 0.4); }
.btn-export-xlsx:hover { background: rgba(63, 185, 80, 0.1); }

/* ============================================================
   TOPBAR NAV
   ============================================================ */
.topbar-nav { display: flex; gap: 0.4rem; margin-right: 0.4rem; }
.topbar-nav a { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.topbar-nav a.active { background: var(--bg-elev-2); border-color: var(--primary); color: var(--primary); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  background: rgba(201, 168, 106, 0.15);
  color: var(--primary);
  border: 1px solid rgba(201, 168, 106, 0.4);
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--mono);
}
.badge-empresa { background: rgba(88, 166, 255, 0.12); color: #58a6ff; border-color: rgba(88, 166, 255, 0.4); }
.badge-warn {
  background: rgba(255, 138, 0, 0.15);
  color: #ffa657;
  border-color: rgba(255, 138, 0, 0.4);
  cursor: help;
}

/* Filas huérfanas: tinte naranja de fondo */
tr.is-orphan td { background: rgba(255, 138, 0, 0.06); }
tr.is-orphan:hover td { background: rgba(255, 138, 0, 0.12); }

/* Checkbox column */
.check-col { width: 32px; text-align: center; padding-left: 0.75rem; padding-right: 0; }
.check-col input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

.stat-warn { border-color: rgba(255, 138, 0, 0.5); }
.stat-warn .stat-value { color: #ffa657; }

.actions-col { white-space: nowrap; text-align: right; width: 1%; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ============================================================
   ALERTAS
   ============================================================ */
.alert-success {
  background: rgba(63, 185, 80, 0.1);
  border-color: rgba(63, 185, 80, 0.4);
  color: #6fcf97;
}
.alert-warning {
  background: rgba(255, 138, 0, 0.1);
  border-color: rgba(255, 138, 0, 0.4);
  color: #ffa657;
}

/* ============================================================
   FILTERS 4-col
   ============================================================ */
.filters-form-4 {
  grid-template-columns: 1fr 1fr 1.4fr auto;
  align-items: end;
}
.filters-form-4 .form-group { margin-bottom: 0; }
.filters-form-4 .form-actions { align-self: end; }
.filters-form-4 .btn {
  height: 2.7rem;            /* igualar al input (.95rem * 1.5 + 0.65rem * 2 + 2px border) */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-left: 1.1rem;
  padding-right: 1.1rem;
}
@media (max-width: 900px) {
  .filters-form-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 540px) {
  .filters-form-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   FILTERS 6-col (SubconPagos: Mes | Año | Desde | Hasta | Empresa | Acciones)
   ============================================================ */
.filters-form-6 {
  grid-template-columns: 0.7fr 0.7fr 1fr 1fr 1.2fr auto;
  align-items: end;
  row-gap: 0.6rem;
}
.filters-form-6 .form-group { margin-bottom: 0; }
.filters-form-6 .form-actions { align-self: end; }
.filters-form-6 .btn {
  height: 2.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 1100px) {
  .filters-form-6 { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 640px) {
  .filters-form-6 { grid-template-columns: 1fr 1fr; }
  .filters-form-6 .form-actions { grid-column: 1 / -1; }
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.open { display: flex; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.modal-dialog {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: calc(100% - 2rem);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-title { margin: 0 0 1.2rem 0; font-size: 1.1rem; }
.modal-title span { color: var(--primary); font-family: var(--mono); }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1.2rem; }

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
thead th {
  background: var(--bg-elev-2);
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: rgba(201, 168, 106, 0.05); }
tfoot th {
  padding: 0.9rem 1rem;
  background: var(--bg-elev-2);
  border-top: 2px solid var(--primary);
  font-weight: 700;
  color: var(--primary);
}
.num { text-align: right; font-family: var(--mono); }

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 0.9rem;
}
.alert-error {
  background: rgba(248, 81, 73, 0.1);
  border-color: rgba(248, 81, 73, 0.4);
  color: #ff8a82;
}

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

/* ============================================================
   ERROR PAGE
   ============================================================ */
.error-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.error-card {
  text-align: center;
  max-width: 480px;
  padding: 3rem 2rem;
}
.error-code {
  font-size: 5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 1rem;
  font-family: var(--mono);
}
.error-card h1 { margin-bottom: 0.5rem; }
.error-card .btn { margin-top: 1.5rem; }
