:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-2: #0f172a;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --sidebar-width: 290px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 220px, var(--bg) 100%);
  color: var(--text);
}

a { text-decoration: none; }

.app-layout {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: #e5e7eb;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  box-shadow: 18px 0 38px rgba(15, 23, 42, 0.18);
}

.sidebar-logo {
  padding: 16px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.04);
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  font-size: 22px;
  margin-bottom: 12px;
}

.sidebar-logo h1 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  color: #fff;
}

.sidebar-logo span,
.sidebar-caption,
.sidebar-footer {
  color: rgba(226, 232, 240, .78);
}

.sidebar-caption {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  padding: 0 10px;
}

.sidebar-menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  color: #dbe4f0;
  font-weight: 500;
  transition: .2s ease;
}

.sidebar-link:hover,
.sidebar-link.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, .24), rgba(59, 130, 246, .14));
  color: #fff;
  transform: translateX(2px);
}

.sidebar-link i {
  width: 18px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 12px 6px;
  font-size: .9rem;
  border-top: 1px solid rgba(255,255,255,.08);
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
}

.main-inner {
  width: min(100%, 1720px);
  margin: 0 auto;
  padding: 28px;
}

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

.main-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.main-header h2 {
  margin: 2px 0 0;
  font-size: clamp(1.55rem, 2.6vw, 2rem);
  font-weight: 700;
}

.page-eyebrow {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 700;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(226,232,240,.9);
  border-radius: 18px;
  padding: 10px 14px;
  box-shadow: 0 16px 40px rgba(15,23,42,.06);
}

.user-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  color: #fff;
  font-weight: 700;
}

.user-meta strong,
.user-meta small {
  display: block;
}

.user-meta small { color: var(--muted); }

.main-content { min-width: 0; }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .46);
  opacity: 0;
  visibility: hidden;
  transition: .2s ease;
  z-index: 1030;
}

.btn-toggle-sidebar { display: none; }

.page-hero {
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 100%);
  color: #fff;
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.metric-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255,255,255,.10);
  color: inherit;
  font-size: .92rem;
  font-weight: 600;
}

.page-hero h3,
.auth-title {
  font-size: clamp(2rem, 3vw, 2.8rem);
  font-weight: 800;
  line-height: 1.08;
  margin-bottom: 12px;
}

.page-hero p,
.auth-copy { color: rgba(255,255,255,.82); }

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.stat-card,
.card {
  background: var(--surface);
  border: 1px solid rgba(226,232,240,.95);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card {
  margin-bottom: 0;
}

.card-header {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  color: #1e293b;
  padding: 16px 20px;
}

.card-body,
.card-footer,
.modal-body,
.modal-footer,
.modal-header {
  padding: 18px 20px;
}

.stat-card {
  padding: 20px;
}

.stat-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 12px;
}

.stat-value {
  font-size: clamp(1.9rem, 4vw, 2.4rem);
  font-weight: 800;
  line-height: 1;
}

.stat-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: .94rem;
}

.kpi-primary { border-top: 5px solid #2563eb; }
.kpi-success { border-top: 5px solid #16a34a; }
.kpi-warning { border-top: 5px solid #f59e0b; }
.kpi-danger { border-top: 5px solid #dc2626; }

.section-title h4 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.section-title span { color: var(--muted); }

.info-list {
  display: grid;
  gap: 14px;
}

.info-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
}

.info-item strong,
.info-item span { display: block; }
.info-item span { color: rgba(255,255,255,.8); font-size: .95rem; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px !important;
}

.empty-state i {
  display: block;
  font-size: 1.6rem;
  margin-bottom: 10px;
  color: #94a3b8;
}

.table-responsive {
  border-radius: 0 0 24px 24px;
}

.table {
  --bs-table-bg: transparent;
  margin-bottom: 0;
}

.table > :not(caption) > * > * {
  padding: .9rem .95rem;
  border-bottom-color: #eef2f7;
  vertical-align: middle;
}

.table thead th {
  background: #f8fafc;
  color: #334155;
  font-size: .88rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.table tbody tr:hover {
  background: rgba(37, 99, 235, .04);
}

.form-label {
  font-weight: 700;
  color: #334155;
  margin-bottom: .45rem;
}

.form-control,
.form-select,
.input-group-text,
textarea.form-control {
  border-radius: 14px !important;
  border: 1px solid #d7e0ea !important;
  min-height: 46px;
  box-shadow: none !important;
}

textarea.form-control { min-height: 110px; }

.form-control:focus,
.form-select:focus {
  border-color: rgba(37,99,235,.45) !important;
  box-shadow: 0 0 0 .22rem rgba(37,99,235,.12) !important;
}

.input-group-text {
  background: #f8fafc;
  color: #64748b;
}

.btn {
  border-radius: 14px;
  font-weight: 600;
}

.btn-sm {
  border-radius: 12px;
}

.btn-primary,
.btn-auth {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
  color: #fff;
}

.btn-auth {
  width: 100%;
  min-height: 50px;
  border-radius: 16px;
  font-weight: 700;
}

.btn-outline-primary {
  border-color: rgba(37,99,235,.28);
  color: #1d4ed8;
}

.btn-outline-primary:hover,
.btn-primary:hover,
.btn-auth:hover {
  filter: brightness(.98);
}

.alert {
  border: 0;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(15,23,42,.05);
}

.badge {
  border-radius: 999px;
  padding: .5em .8em;
}

.pagination {
  gap: 6px;
}

.page-link {
  border-radius: 12px !important;
  border: 1px solid #dbe4ee;
  color: #334155;
  min-width: 42px;
  text-align: center;
}

.page-item.active .page-link {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: transparent;
}

.modal-content {
  border: 0;
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .24);
}

.modal-header,
.modal-footer {
  border-color: #edf2f7;
}

.auth-body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(59,130,246,.18), transparent 35%),
    radial-gradient(circle at bottom right, rgba(15,23,42,.14), transparent 28%),
    linear-gradient(135deg, #eff6ff 0%, #f8fafc 45%, #eef2ff 100%);
}

.auth-shell {
  min-height: 100vh;
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 24px;
  align-items: stretch;
}

.auth-brand,
.auth-card {
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.auth-brand {
  background: linear-gradient(150deg, #0f172a, #1d4ed8 65%, #2563eb 100%);
  color: #fff;
  padding: 38px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-logo {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.12);
  font-size: 28px;
  margin-bottom: 20px;
}

.auth-points {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.auth-point {
  display: flex;
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255,255,255,.08);
}

.auth-point i {
  margin-top: 3px;
  font-size: 1.1rem;
}

.auth-point strong,
.auth-point span {
  display: block;
}

.auth-point span { color: rgba(255,255,255,.82); }

.auth-card {
  background: rgba(255,255,255,.84);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.6);
  padding: 30px;
  width: min(100%, 520px);
  margin: auto;
}

.auth-headline {
  font-weight: 800;
  margin-bottom: 8px;
}

.auth-subtitle,
.auth-note,
.auth-footer,
.auth-links {
  color: var(--muted);
}

.auth-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.auth-note {
  padding: 12px 14px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.row {
  --bs-gutter-y: 1rem;
}

@media (max-width: 1399.98px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1199.98px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
  }

  .btn-toggle-sidebar { display: inline-flex; }
  .main { margin-left: 0; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { opacity: 1; visibility: visible; }
  .auth-shell { grid-template-columns: 1fr; }
}

@media (max-width: 991.98px) {
  .main-inner { padding: 20px; }
  .main-header { flex-direction: column; align-items: stretch; }
  .user-chip { justify-content: space-between; }
  .page-hero { padding: 22px; }
}

@media (max-width: 767.98px) {
  .stats-grid { grid-template-columns: 1fr; }
  .main-inner { padding: 16px; }
  .card-header,
  .card-body,
  .modal-body,
  .modal-header,
  .modal-footer { padding: 16px; }
  .auth-brand,
  .auth-card { padding: 24px; }
  .auth-links { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 575.98px) {
  .user-chip { flex-direction: column; align-items: stretch; }
  .page-actions { flex-direction: column; }
  .page-actions .btn { width: 100%; }
}


/* ===============================
   RESPONSIVE MEJORADO PARA MÓVIL
================================ */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

.main,
.main-inner,
.main-content {
  min-width: 0;
}

.table-responsive {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.table-responsive table {
  margin-bottom: 0;
}

@media (max-width: 767.98px) {
  .main-header-left,
  .main-header,
  .user-chip {
    width: 100%;
  }

  .card-header.d-flex,
  .card-header-flex,
  .toolbar-form,
  form.row.g-2.align-items-center {
    flex-direction: column;
    align-items: stretch !important;
  }

  .toolbar-form .col-auto,
  form.row.g-2.align-items-center .col-auto,
  .toolbar-form .btn,
  form.row.g-2.align-items-center .btn,
  .acciones-top,
  .acciones-top > *,
  .card-header .btn,
  .card-header .btn-group,
  .card-header .dropdown,
  .card-header a.btn,
  .card-header button.btn {
    width: 100%;
  }

  .toolbar-form .col-auto,
  form.row.g-2.align-items-center .col-auto {
    flex: 1 1 100%;
  }

  .btn,
  .btn-sm {
    min-height: 44px;
  }

  .pagination {
    justify-content: center;
  }

  .modal {
    padding: 0 !important;
  }

  .modal-dialog {
    max-width: 100vw !important;
    width: 100vw !important;
    min-height: 100dvh;
    margin: 0 !important;
  }

  .modal-dialog.modal-dialog-centered {
    display: flex;
    align-items: stretch;
    min-height: 100dvh;
  }

  .modal-content {
    min-height: 100dvh;
    border-radius: 0 !important;
  }

  .modal-header,
  .modal-footer {
    position: sticky;
    background: #fff;
    z-index: 5;
  }

  .modal-header {
    top: 0;
  }

  .modal-footer {
    bottom: 0;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .modal-body {
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer .btn,
  .modal-footer a.btn,
  .modal-footer button.btn {
    width: 100%;
  }
}
