/* ============================================================
   EMOVTT SR-EP - Sistema de Arriendos
   Sistema de diseño: "Data-Dense Dashboard" institucional
   Paleta navy de alto contraste + acento azul institucional
   ============================================================ */

:root {
  /* -- Tokens de color -------------------------------------- */
  --ink-950: #020617;
  --ink-900: #0F172A;   /* primario: sidebar, topbar, títulos   */
  --ink-800: #1E293B;
  --ink-700: #334155;
  --ink-500: #64748B;
  --ink-400: #94A3B8;
  --accent-700: #075985;
  --accent-600: #0369A1; /* acento / CTA                        */
  --accent-100: #E0F2FE;
  --accent-50:  #F0F9FF;
  --surface:    #FFFFFF;
  --bg-app:     #F1F5F9;
  --border:     #E2E8F0;
  --success:    #15803D;
  --success-bg: #DCFCE7;
  --warning:    #B45309;
  --warning-bg: #FEF3C7;
  --danger:     #DC2626;
  --danger-bg:  #FEE2E2;
  --info:       #0E7490;
  --info-bg:    #CFFAFE;

  /* -- Tokens de forma y elevación --------------------------- */
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);

  /* -- Compatibilidad con variables previas ------------------ */
  --color-primary: var(--accent-600);
  --sidebar-bg: var(--ink-900);
  --sidebar-width: 230px;

  /* -- Bootstrap: re-mapeo de la marca ------------------------ */
  --bs-primary: #0369A1;
  --bs-primary-rgb: 3, 105, 161;
  --bs-body-color: #1E293B;
  --bs-body-bg: #F1F5F9;
  --bs-border-color: #E2E8F0;
  --bs-link-color: #0369A1;
  --bs-link-hover-color: #075985;
}

/* ============================================================
   BASE
   ============================================================ */
body {
  font-family: 'Fira Sans', 'Segoe UI', system-ui, sans-serif;
  font-size: 0.92rem;
  color: var(--bs-body-color);
  background: var(--bg-app);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--ink-900);
  font-weight: 600;
  letter-spacing: -0.01em;
}

a { color: var(--accent-600); }
a:hover { color: var(--accent-700); }

/* Cifras, contratos, RUC y códigos con dígitos tabulares */
.text-mono,
.stat-value,
td.text-end,
.font-monospace {
  font-family: 'Fira Code', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
}

/* Foco visible para navegación por teclado */
:focus-visible {
  outline: 2px solid var(--accent-600);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Scrollbar sutil */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 8px; border: 2px solid var(--bg-app); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-400); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   TOPBAR (navbar superior)
   ============================================================ */
.topbar {
  background: linear-gradient(90deg, var(--ink-950) 0%, var(--ink-900) 55%, #14263F 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 58px;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.topbar .navbar-brand {
  letter-spacing: 0.01em;
  font-weight: 700;
  color: #fff;
}

.topbar .brand-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--accent-600);
  color: #fff;
  font-size: 1.05rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25);
}

.topbar .brand-sub {
  display: block;
  font-size: 0.66rem;
  font-weight: 400;
  color: var(--ink-400);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}

.topbar .user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.75rem 0.3rem 0.4rem;
  border-radius: 2rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #E2E8F0;
  font-size: 0.85rem;
}

.topbar .user-chip .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-600);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
}

.topbar .user-chip .badge {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.14);
  color: #E2E8F0;
}

.topbar .btn-logout {
  color: var(--ink-400);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
}
.topbar .btn-logout:hover {
  color: #fff;
  background: rgba(220, 38, 38, 0.25);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  min-height: calc(100vh - 58px);
  background: var(--sidebar-bg) !important;
  position: sticky;
  top: 58px;
  max-height: calc(100vh - 58px);
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar::-webkit-scrollbar-thumb { border-color: var(--ink-900); background: var(--ink-700); }

.sidebar-heading {
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-500) !important;
  font-weight: 700;
  padding: 1.1rem 1.25rem 0.35rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #CBD5E1;
  padding: 0.5rem 0.85rem;
  margin: 1px 0.6rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  font-size: 0.88rem;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

.sidebar-link i {
  font-size: 1rem;
  width: 1.15rem;
  text-align: center;
  color: var(--ink-500);
  transition: color 0.15s;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.sidebar-link:hover i { color: #7DD3FC; }

.sidebar-link.is-active {
  background: linear-gradient(90deg, rgba(3, 105, 161, 0.35), rgba(3, 105, 161, 0.12));
  border-left-color: #38BDF8;
  color: #fff;
  font-weight: 500;
}
.sidebar-link.is-active i { color: #7DD3FC; }

.sidebar-link .badge { font-size: 0.66rem; }

.sidebar-link.is-sub {
  font-size: 0.82rem;
  padding-left: 2.35rem;
  color: var(--ink-400);
}
.sidebar-link.is-sub:hover { color: #fff; }

.sidebar-rol {
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 1rem 0.85rem 0;
  padding-top: 0.85rem;
}

/* ============================================================
   CONTENIDO PRINCIPAL
   ============================================================ */
.main-content {
  min-height: calc(100vh - 58px);
}

/* Encabezado de página estándar */
.page-header h4, .page-header h5 { margin-bottom: 0.1rem; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--ink-900);
}

.card-header.bg-white { border-radius: var(--radius-md) var(--radius-md) 0 0; }

/* Tarjetas de indicadores (KPI) */
.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease-out, box-shadow 0.18s ease-out;
  overflow: hidden;
  position: relative;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
  font-size: 1.35rem;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-50);
}
.stat-card .stat-icon.text-primary  { background: var(--accent-50); }
.stat-card .stat-icon.text-success  { background: var(--success-bg); color: var(--success) !important; }
.stat-card .stat-icon.text-danger   { background: var(--danger-bg);  color: var(--danger) !important; }
.stat-card .stat-icon.text-warning  { background: var(--warning-bg); color: var(--warning) !important; }

.stat-card .stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

/* ============================================================
   TABLAS
   ============================================================ */
.table {
  --bs-table-hover-bg: var(--accent-50);
  margin-bottom: 0;
}

.table thead th,
.table-light th {
  background: #F8FAFC !important;
  color: var(--ink-500) !important;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border) !important;
  white-space: nowrap;
}

.table td { vertical-align: middle; }

.table-hover tbody tr { transition: background-color 0.12s; }
.table-hover tbody tr:hover { background-color: var(--accent-50); }

/* ============================================================
   BADGES DE ESTADO
   ============================================================ */
.badge {
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 2rem;
  padding: 0.34em 0.72em;
}

.badge-vigente    { background-color: var(--success-bg); color: var(--success); }
.badge-renovado   { background-color: var(--accent-100); color: var(--accent-700); }
.badge-vencido    { background-color: var(--warning-bg); color: var(--warning); }
.badge-caducado   { background-color: var(--danger-bg);  color: var(--danger); }
.badge-pendiente  { background-color: #E2E8F0;           color: var(--ink-700); }
.badge-parcial    { background-color: var(--info-bg);    color: var(--info); }
.badge-pagado     { background-color: var(--success-bg); color: var(--success); }
.badge-mora       { background-color: var(--danger-bg);  color: var(--danger); }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent-600);
  border-color: var(--accent-600);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--accent-700);
  border-color: var(--accent-700);
}

.btn-outline-primary { color: var(--accent-600); border-color: var(--accent-600); }
.btn-outline-primary:hover { background: var(--accent-600); border-color: var(--accent-600); }

.btn-success { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: #166534; border-color: #166534; }

/* ============================================================
   FORMULARIOS
   ============================================================ */
.form-label {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--ink-700);
}

.form-control, .form-select {
  border-color: #CBD5E1;
  border-radius: var(--radius-sm);
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent-600);
  box-shadow: 0 0 0 0.2rem rgba(3, 105, 161, 0.15);
}

.required::after { content: ' *'; color: var(--danger); }

/* ============================================================
   ALERTAS
   ============================================================ */
.alert { border-radius: var(--radius-md); border-width: 1px; }

/* ============================================================
   COMPROBANTES
   ============================================================ */
.comprobante-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.comprobante-header {
  border-bottom: 2px solid var(--ink-900);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
}

/* ============================================================
   SELECCIÓN DE PERÍODOS A PAGAR (pago múltiple / adelantado)
   ============================================================ */
.cargo-select {
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
  border: 1.5px solid var(--border);
}
.cargo-select:hover {
  border-color: var(--accent-600);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.cargo-select.is-checked {
  border-color: var(--success);
  background: var(--success-bg);
  box-shadow: 0 2px 10px rgba(21, 128, 61, 0.15);
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrapper {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(3, 105, 161, 0.45), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, rgba(14, 116, 144, 0.35), transparent 55%),
    linear-gradient(150deg, var(--ink-950) 0%, var(--ink-900) 60%, #12365A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.login-card {
  width: 100%;
  max-width: 430px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-brand-icon {
  width: 64px;
  height: 64px;
  font-size: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, var(--accent-600), var(--accent-700));
  color: #fff;
  box-shadow: 0 8px 20px rgba(3, 105, 161, 0.35);
}

/* ============================================================
   DATATABLES (controles: buscador, "Mostrar N registros", paginación)
   ============================================================ */
/* Los controles quedaban pegados a los bordes cuando la tabla vive
   dentro de un card-body p-0; se les da aire propio. */
.dataTables_wrapper > .row:first-child {
  padding: 0.65rem 0.75rem 0.25rem;
  margin: 0;
}
.dataTables_wrapper > .row:last-child {
  padding: 0.35rem 0.75rem 0.65rem;
  margin: 0;
  align-items: center;
}

/* Selector de cantidad de registros: ancho automático y bien alineado */
.dataTables_wrapper .dataTables_length label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0;
  font-size: 0.85rem;
  color: var(--ink-500);
  white-space: nowrap;
}
.dataTables_wrapper .dataTables_length select {
  width: auto !important;
  min-width: 4.5rem;
  display: inline-block;
  border: 1px solid #CBD5E1;
  border-radius: var(--radius-sm);
  padding: 0.3rem 1.9rem 0.3rem 0.55rem;
  background-color: #fff;
}

/* Buscador */
.dataTables_wrapper .dataTables_filter label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0;
  font-size: 0.85rem;
  color: var(--ink-500);
}
.dataTables_wrapper .dataTables_filter input {
  width: auto;
  border: 1px solid #CBD5E1;
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.55rem;
  margin-left: 0 !important;
}

/* La tabla dentro del wrapper se desplaza horizontalmente en móvil
   sin arrastrar los controles */
.dataTables_wrapper > .row > [class*="col-"] { min-width: 0; }
.dataTables_wrapper > .row > .col-sm-12:not([class*="col-md"]) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--accent-600) !important;
  border-color: var(--accent-600) !important;
  color: #fff !important;
  border-radius: var(--radius-sm);
}
.dataTables_wrapper .dataTables_info { color: var(--ink-500); font-size: 0.82rem; }

/* ============================================================
   ESTADO VACÍO (listados sin registros)
   ============================================================ */
.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-50);
  color: var(--accent-600);
  font-size: 1.7rem;
}
.empty-state h6 { color: var(--ink-700); }

/* ============================================================
   MODAL DE CONFIRMACIÓN (reemplaza confirm() del navegador)
   ============================================================ */
.app-confirm {
  border: none;
  border-radius: var(--radius-lg, 16px);
  box-shadow: 0 18px 50px rgba(10, 20, 45, 0.25);
}
.app-confirm-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.8rem;
}
.app-confirm-icon.is-primary { background: var(--accent-50, #e8f0fe); color: var(--accent-600, #1a56db); }
.app-confirm-icon.is-danger  { background: #fdecea; color: #c0392b; }

/* ============================================================
   TOASTS DE NOTIFICACIÓN (mensajes flash)
   ============================================================ */
.app-toast {
  border: none;
  border-radius: 12px;
  box-shadow: 0 10px 34px rgba(10, 20, 45, 0.18);
  background: #fff;
  overflow: hidden;
  min-width: 320px;
}
.app-toast::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
}
.app-toast { position: relative; }
.app-toast.toast-success::before { background: #1e8e4e; }
.app-toast.toast-danger::before  { background: #c0392b; }
.app-toast.toast-warning::before { background: #d99000; }
.app-toast.toast-info::before    { background: var(--accent-600, #1a56db); }

/* ============================================================
   UTILIDADES
   ============================================================ */
.cursor-pointer { cursor: pointer; }
.border-start-4 { border-left-width: 4px !important; }

/* Footer */
.app-footer {
  background: var(--ink-900);
  color: var(--ink-500);
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.78rem;
}
.app-footer a { color: var(--ink-400); text-decoration: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 767.98px) {
  .sidebar {
    position: static;
    min-height: auto;
    max-height: none;
  }
  .main-content { padding: 1rem !important; }

  /* Toda tabla se puede desplazar horizontalmente en pantallas chicas */
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .card .table { font-size: 0.85rem; }

  /* Controles DataTables apilados y centrados en móvil */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    text-align: left !important;
    margin-bottom: 0.4rem;
  }
  .dataTables_wrapper .dataTables_paginate { justify-content: center; display: flex; }
}

/* ============================================================
   ACCESIBILIDAD: movimiento reducido
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .sidebar, .navbar, .topbar, .app-footer, .no-print { display: none !important; }
  .main-content { padding: 0 !important; }
  body { background: #fff; }
  .card, .stat-card, .comprobante-preview {
    background: #fff !important;
    box-shadow: none !important;
  }
}
