:root {
  --sg-deep: #083344;
  --sg-navy: #155e75;
  --sg-cyan: #0891b2;
  --sg-aqua: #22d3ee;
  --sg-sky: #38bdf8;
  --sg-pool: #ecfeff;
  --sg-mist: #f0f9ff;
  --sg-sand: #f8fafc;
  --sg-foam: #ffffff;
  --sg-ink: #164e63;
  --sg-muted: #64748b;
  --sg-line: #d6eef4;
  --sg-ok: #059669;
  --sg-warn: #d97706;
  --sg-bad: #dc2626;
  --sg-info: #0284c7;
  --sidebar-w: 268px;
  --topbar-h: 64px;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(8, 51, 68, 0.08);
  --sg-app-height: 100dvh;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  color: var(--sg-ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(34, 211, 238, .18), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(14, 165, 233, .12), transparent 45%),
    var(--sg-sand);
}

img { max-width: 100%; height: auto; }
a { color: var(--sg-cyan); text-decoration: none; }
a:hover { color: var(--sg-navy); }

.app-shell { min-height: 100dvh; display: flex; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #082f40 0%, #0e4a5c 52%, #0f766e 140%);
  color: #e0f2fe;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  height: auto;
  max-height: none;
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 140px;
  background: radial-gradient(circle at 20% 120%, rgba(34,211,238,.28), transparent 50%);
  pointer-events: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-close,
.sidebar-toggle { display: none; }
.sidebar-close {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-close:hover { background: rgba(255,255,255,.22); }
.nav-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 51, 68, .45);
  z-index: 35;
  border: 0;
  padding: 0;
  touch-action: none;
  overscroll-behavior: none;
}
.brand img {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
.brand-copy { line-height: 1.15; }
.brand-copy strong { display: block; font-size: 15px; letter-spacing: .04em; }
.brand-copy small { color: #a5f3fc; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

.nav-scroll {
  flex: 1 1 0%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: scroll; /* fuerza área scrolleable para ver todos los ítems */
  overscroll-behavior: contain;
  padding: 12px 6px 0 10px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(165, 243, 252, .55) rgba(255, 255, 255, .06);
}
/* Espacio extra al final para que Backups/Auditoría no queden pegados al borde */
.nav-scroll::after {
  content: "";
  display: block;
  height: calc(48px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.nav-scroll::-webkit-scrollbar {
  width: 8px;
}
.nav-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, .06);
  border-radius: 999px;
  margin: 10px 2px;
}
.nav-scroll::-webkit-scrollbar-thumb {
  background: rgba(165, 243, 252, .45);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  min-height: 40px;
}
.nav-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(165, 243, 252, .7);
  background-clip: padding-box;
  border: 2px solid transparent;
}
.nav-scroll::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
.nav-scroll::-webkit-scrollbar-corner {
  background: transparent;
}
.nav-label {
  margin: 14px 12px 6px;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #67e8f9;
  opacity: .8;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: #dbeafe;
  font-weight: 600;
  font-size: 14px;
}
.nav-link i { width: 20px; text-align: center; opacity: .9; }
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: rgba(255,255,255,.78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--sg-line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.page-title { margin: 0; font-size: 20px; font-weight: 800; color: var(--sg-deep); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.branch-select, .user-chip {
  border: 1px solid var(--sg-line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--sg-ink);
}
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.user-chip span { color: var(--sg-muted); font-weight: 500; }

.content { padding: 22px; max-width: 1500px; }

.card-sg {
  background: var(--sg-foam);
  border: 1px solid var(--sg-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-sg .card-body { padding: 18px 20px; }
.card-sg h3, .card-sg h2 { margin: 0 0 6px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: #fff;
  border: 1px solid var(--sg-line);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(34,211,238,.18), rgba(8,145,178,.08));
}
.kpi .label { color: var(--sg-muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.kpi .value { font-size: 28px; font-weight: 800; color: var(--sg-deep); margin-top: 4px; }
.kpi .hint { color: var(--sg-navy); font-size: 12px; margin-top: 4px; }

.btn-sg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 9px 14px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: linear-gradient(135deg, #0891b2, #0284c7);
  color: #fff;
}
.btn-sg:hover { filter: brightness(1.05); color: #fff; }
.btn-sg-ghost {
  background: #fff;
  color: var(--sg-navy);
  border: 1px solid var(--sg-line);
}
.btn-sg-danger { background: linear-gradient(135deg, #e11d48, #be123c); }
.btn-sg-ok { background: linear-gradient(135deg, #059669, #0f766e); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 10px; }

.table-wrap { overflow: auto; }
table.dataTable { width: 100% !important; }
table.dataTable thead th {
  background: var(--sg-pool);
  color: var(--sg-deep);
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--sg-line) !important;
}
table.dataTable tbody td { vertical-align: middle; color: #155e75; }

.badge-sg {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .02em;
}
.badge-sg-success { background: #d1fae5; color: #047857; }
.badge-sg-warning { background: #fef3c7; color: #b45309; }
.badge-sg-danger { background: #fee2e2; color: #b91c1c; }
.badge-sg-info { background: #e0f2fe; color: #0369a1; }
.badge-sg-secondary { background: #e2e8f0; color: #475569; }
.badge-sg-dark { background: #334155; color: #f8fafc; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
label.sg { display: block; font-size: 12px; font-weight: 800; color: var(--sg-navy); margin-bottom: 6px; }
.form-control, .form-select, textarea.form-control {
  border: 1px solid var(--sg-line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--sg-deep);
  background: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: #22d3ee;
  box-shadow: 0 0 0 3px rgba(34,211,238,.18);
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }

.login-page {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  background: #082f40;
}
.login-hero {
  position: relative;
  overflow: hidden;
  min-height: 100dvh;
}
.login-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
  background:
    linear-gradient(180deg, rgba(236,254,255,.96), #ffffff 40%);
}
.login-card { width: 100%; max-width: 420px; }
.login-card h1 { margin: 0 0 6px; font-size: 30px; color: var(--sg-deep); }
.login-card p.lead { color: var(--sg-muted); margin: 0 0 22px; }
.demo-box {
  background: var(--sg-pool);
  border: 1px dashed #67e8f9;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--sg-navy);
  margin-top: 16px;
}

.alert { border-radius: 12px; }

.sg-swal {
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif !important;
  border-radius: 18px !important;
  color: var(--sg-deep) !important;
}
.sg-swal .swal2-title { color: var(--sg-deep); font-weight: 800; }
.sg-swal .swal2-html-container { color: var(--sg-navy); }
div:where(.swal2-container) button:where(.swal2-styled).sg-swal-ok,
div:where(.swal2-container) button:where(.swal2-styled).swal2-confirm {
  background: linear-gradient(135deg, #0891b2, #0284c7) !important;
  border-radius: 12px !important;
  font-weight: 700 !important;
}
div:where(.swal2-container) button:where(.swal2-styled).swal2-cancel {
  border-radius: 12px !important;
  font-weight: 700 !important;
}

.footer-mini {
  color: var(--sg-muted);
  font-size: 12px;
  padding: 8px 22px 22px;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 991.98px) {
  .sidebar {
    transform: translate3d(-105%, 0, 0);
    transition: transform .22s ease;
    width: min(82vw, 300px);
    top: 0;
    left: 0;
    bottom: 0;
    height: auto;
    max-height: none;
    z-index: 50;
    box-shadow: 16px 0 40px rgba(8, 51, 68, .28);
  }
  .sidebar.open { transform: translate3d(0, 0, 0); }
  .sidebar-toggle,
  .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
  .nav-scroll {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .nav-backdrop {
    display: block;
    z-index: 45;
  }
  .nav-backdrop[hidden] { display: none !important; }
  /* Bloquea por completo el scroll del fondo blanco */
  html.nav-open,
  body.nav-open {
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: none;
  }
  body.nav-open {
    position: fixed;
    width: 100%;
    left: 0;
    right: 0;
  }
  body.nav-open .main,
  body.nav-open .app-shell {
    pointer-events: none;
    touch-action: none;
  }
  body.nav-open .sidebar,
  body.nav-open .sidebar * {
    pointer-events: auto;
  }
  body.nav-open .nav-scroll {
    touch-action: pan-y;
  }
  .main { margin-left: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-hero { min-height: 220px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .topbar { padding-left: 14px; padding-right: 14px; }
}
