:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #059669;
  --color-danger: #dc2626;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

button, input { font-family: inherit; font-size: inherit; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--color-surface);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}

.login-title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
}

.login-subtitle {
  margin: 0 0 24px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  outline: none;
  transition: border-color .15s;
}

.form-input:focus { border-color: var(--color-primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ---------- Dashboard layout placeholder ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 24px 16px;
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 24px;
  padding: 0 8px;
}

.sidebar-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 16px 8px 8px;
}

.sidebar-link {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--color-text);
  text-decoration: none;
  font-size: 13px;
}

.sidebar-link:hover { background: var(--color-bg); }
.sidebar-link.active { background: #eff6ff; color: var(--color-primary); font-weight: 500; }

.main {
  padding: 24px 32px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.topbar-title { font-size: 22px; font-weight: 600; margin: 0; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  padding: 0;
  font-size: inherit;
}

.btn-link:hover { text-decoration: underline; }

.empty-state {
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
  color: var(--color-text-muted);
}

/* ---------- Alerts extra ---------- */
.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

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

/* ---------- Cards de licencias ---------- */
.lic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.lic-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.lic-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.lic-status {
  font-size: 12px;
  font-weight: 500;
}

.lic-meta {
  font-size: 13px;
  color: var(--color-text);
}
.lic-meta div { margin-bottom: 2px; }

.lic-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
  font-size: 13px;
}

/* ---------- Filtros / Tabs ---------- */
.filtros {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.filtro-grupo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filtro-label {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 500;
}

.tab {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  transition: all .15s;
}
.tab:hover { background: var(--color-bg); }
.tab.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  margin-bottom: 4px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--color-text-muted);
}

.kpi-cmp-block {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-cmp {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: baseline;
  font-size: 11px;
  color: var(--color-text-muted);
}

.kpi-cmp .pct-up { color: var(--color-success); font-weight: 600; }
.kpi-cmp .pct-down { color: var(--color-danger); font-weight: 600; }
.kpi-cmp .pct-neutral { color: var(--color-text-muted); }
.kpi-cmp-val { font-variant-numeric: tabular-nums; text-align: right; }

.loader {
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--color-text-muted);
}

/* ---------- Tabla de desglose ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}

.data-table th, .data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.data-table thead {
  background: var(--color-bg);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-bg); }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

/* ---------- Cards de bloque (gráficos / tablas) ---------- */
.card-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.subtitle {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Layout 2 columnas (gráfico + tabla) */
.ventas-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

@media (max-width: 1100px) {
  .ventas-layout { grid-template-columns: 1fr; }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--color-bg);
  color: var(--color-text);
}

.badge-ok {
  background: #d1fae5;
  color: #065f46;
}

.badge-warn {
  background: #fef3c7;
  color: #92400e;
}

/* ---------- Estado de Resultados ---------- */
.pl-table tbody td { padding: 12px 14px; font-size: 14px; }
.pl-table .row-total td {
  background: var(--color-bg);
  font-weight: 600;
  border-top: 2px solid var(--color-border);
}
.pl-table .row-positive td { color: var(--color-success); }
.pl-table .row-negative td { color: var(--color-danger); }

/* ---------- Mapeos ---------- */
.mapeo-form .form-row {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 12px;
}
.mapeo-form .form-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 500;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}
.form-actions .btn { width: auto; padding: 10px 20px; }

.btn-danger { color: var(--color-danger); }

/* ---------- Indicador global de carga ---------- */
.loading-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px; z-index: 9999;
  background: linear-gradient(90deg, transparent 0%, #3B82F6 50%, transparent 100%);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: loading-bar-slide 1.2s linear infinite;
}
@keyframes loading-bar-slide {
  0%   { background-position: -40% 0; }
  100% { background-position: 140% 0; }
}
.loading-label {
  position: fixed; top: 12px; right: 16px;
  z-index: 9998;
  font-size: 12px; font-weight: 600;
  color: #1f2937;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 12px 4px 28px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.loading-label::before {
  content: ''; position: absolute; left: 8px; top: 50%;
  width: 12px; height: 12px; margin-top: -6px;
  border: 2px solid #3B82F6;
  border-top-color: transparent;
  border-radius: 50%;
  animation: loading-spin 0.7s linear infinite;
}
@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Tablas con scroll horizontal ---------- */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
}

/* ---------- Tabla PyG Mensual (matriz cuentas × meses) ---------- */
.pyg-mensual { font-size: 12px; min-width: 1100px; }
.pyg-mensual th, .pyg-mensual td { padding: 4px 8px; white-space: nowrap; }
.pyg-mensual thead th {
  position: sticky; top: 0; background: var(--color-surface);
  border-bottom: 2px solid var(--color-border); z-index: 1;
}
.pyg-mensual .cell-codigo { font-family: ui-monospace, monospace; color: var(--color-text-muted); }
.pyg-mensual .cell-nombre { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.pyg-mensual .cell-total { font-weight: 600; background: rgba(0,0,0,0.025); }
.pyg-mensual .fila-cuenta:hover { background: rgba(59,130,246,0.05); }
.pyg-mensual .fila-grupo td {
  background: var(--color-bg, #f3f4f6);
  font-weight: 700; text-transform: uppercase; font-size: 11px;
  letter-spacing: 0.04em; padding-top: 8px;
}
.pyg-mensual .fila-total td {
  border-top: 1px solid var(--color-border);
  background: rgba(0,0,0,0.03); font-weight: 600;
}
.pyg-mensual .row-positive td { color: var(--color-success); }
.pyg-mensual .fila-ingresos .num { color: var(--color-text); }

/* ---------- Helpers ---------- */
.muted { color: var(--color-text-muted); margin: 0; }
.muted.small { font-size: 12px; }

.kpi-value-sm {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
}

.pct-up { color: var(--color-success); }
.pct-down { color: var(--color-danger); }

/* Alert warn (faltaba) */
.alert-warn {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
