:root {
  --sg-primary: #0d6efd;
  --sg-primary-dark: #084298;
  --sg-primary-soft: #eaf2ff;
  --sg-accent: #14b8a6;
  --sg-bg: #f4f7fb;
  --sg-surface: #ffffff;
  --sg-surface-2: #f8fafc;
  --sg-text: #172033;
  --sg-muted: #64748b;
  --sg-border: #e5eaf1;
  --sg-danger: #dc3545;
  --sg-warning: #f59e0b;
  --sg-success: #198754;
  --sg-radius: 16px;
  --sg-shadow-sm: 0 4px 18px rgba(15, 23, 42, .06);
  --sg-shadow: 0 14px 34px rgba(15, 23, 42, .10);
}

html { scroll-behavior: smooth; }
body {
  color: var(--sg-text);

  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body:not(.sg-login-page) { background: var(--sg-bg) !important; }

/* Precarga global */
.sg-preloader {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  background: rgba(248, 250, 252, .96);
  backdrop-filter: blur(6px);
  transition: opacity .24s ease, visibility .24s ease;
}
.sg-preloader.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.sg-preloader__box { text-align: center; min-width: 180px; }
.sg-preloader__mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--sg-primary), var(--sg-primary-dark));
  box-shadow: 0 12px 30px rgba(13, 110, 253, .25);
}
.sg-preloader__mark img { width: 36px; height: 36px; object-fit: contain; }
.sg-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 12px;
  border: 3px solid #dbe7fb;
  border-top-color: var(--sg-primary);
  border-radius: 50%;
  animation: sg-spin .72s linear infinite;
}
.sg-preloader__text { color: var(--sg-muted); font-size: .9rem; font-weight: 600; letter-spacing: .01em; }
@keyframes sg-spin { to { transform: rotate(360deg); } }

/* Shell */
.app-header {
  min-height: 64px;
  border-bottom: 1px solid var(--sg-border);
  background: rgba(255,255,255,.94) !important;
  backdrop-filter: blur(12px);
  box-shadow: 0 1px 8px rgba(15,23,42,.03);
}
.app-header .nav-link { color: #334155; border-radius: 10px; }
.app-header .nav-link:hover { background: var(--sg-primary-soft); color: var(--sg-primary); }

.app-sidebar {
  background: linear-gradient(180deg, #111827 0%, #172033 100%) !important;
  border-right: 0;
}
.sidebar-brand {
  min-height: 88px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,.08) !important;
}
.sidebar-brand .brand-link {
  width: 100%;
  min-height: 88px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.sidebar-brand .brand-image {
  display: block;
  float: none !important;
  width: 205px !important;
  max-width: 92% !important;
  max-height: 66px !important;
  height: auto !important;
  object-fit: contain;
  margin: 0 auto !important;
  opacity: 1 !important;
  filter: drop-shadow(0 5px 12px rgba(0,0,0,.28));
}
.sidebar-menu { padding: 8px 10px 22px; }
.sidebar-menu .nav-header {
  color: #94a3b8;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
  padding: 18px 12px 7px;
}
.sidebar-menu .nav-link {
  color: #cbd5e1;
  border-radius: 11px;
  margin: 2px 0;
  padding: .72rem .78rem;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.sidebar-menu .nav-link:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(2px); }
.sidebar-menu .nav-link.active {
  color: #fff;
  background: linear-gradient(135deg, var(--sg-primary), #2563eb);
  box-shadow: 0 8px 20px rgba(13,110,253,.24);
}
.sidebar-menu .nav-icon { width: 1.35rem; font-size: 1.05rem; opacity: .96; }

.app-main { background: var(--sg-bg); min-height: calc(100vh - 114px); }
.app-content-header { padding: 24px 0 12px; }
.app-content-header h1, .app-content-header h2, .app-content-header h3 { color: var(--sg-text); letter-spacing: -.02em; }
.app-content { padding-bottom: 28px; }
.app-content > .container-fluid, .app-content-header > .container-fluid { padding-left: 24px; padding-right: 24px; }
.app-footer { border-top: 1px solid var(--sg-border); background: #fff; color: var(--sg-muted); font-size: .88rem; }

/* Superficies */
.card {
  border: 1px solid var(--sg-border) !important;
  border-radius: var(--sg-radius) !important;
  box-shadow: var(--sg-shadow-sm) !important;
  overflow: hidden;
  background: var(--sg-surface);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid var(--sg-border);
  padding: 1rem 1.15rem;
}
.card-body { padding: 1.15rem; }
.modal-content { border: 0; border-radius: 18px; box-shadow: 0 26px 60px rgba(15,23,42,.22); overflow: hidden; }
.modal-header, .modal-footer { border-color: var(--sg-border); }

/* Formularios */
.form-label { color: #334155; font-weight: 600; font-size: .9rem; }
.form-control, .form-select, .input-group-text {
  min-height: 44px;
  border-color: #dce3ec;
  border-radius: 11px;
  background-color: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: #86b7fe;
  box-shadow: 0 0 0 .22rem rgba(13,110,253,.10);
}
.input-group > .form-control:not(:last-child), .input-group > .form-select:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.form-text { color: var(--sg-muted); }

/* Botones */
.btn { border-radius: 10px; font-weight: 600; padding: .55rem .9rem; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { box-shadow: 0 6px 16px rgba(13,110,253,.17); }
.btn-success { box-shadow: 0 6px 16px rgba(25,135,84,.14); }
.btn-group .btn { border-radius: 8px; }

/* Tablas */
.table { color: var(--sg-text); }
.table > :not(caption) > * > * { padding: .88rem .9rem; border-bottom-color: #edf1f5; vertical-align: middle; }
.table thead th {
  background: var(--sg-surface-2) !important;
  color: #475569;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .045em;
  font-weight: 700;
  white-space: nowrap;
}
.table-hover > tbody > tr:hover > * { background-color: #f8fbff; }
.table-responsive { scrollbar-width: thin; }

.badge { border-radius: 999px; font-weight: 700; padding: .45em .7em; }
.alert { border-radius: 12px; }

/* Dashboard */
.sg-kpi {
  height: 100%;
  position: relative;
  padding: 1.15rem;
  border: 1px solid var(--sg-border);
  border-radius: var(--sg-radius);
  background: #fff;
  box-shadow: var(--sg-shadow-sm);
  overflow: hidden;
}
.sg-kpi::after {
  content: '';
  position: absolute;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  right: -34px;
  top: -34px;
  background: var(--sg-kpi-soft, var(--sg-primary-soft));
}
.sg-kpi__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: relative; z-index: 1; }
.sg-kpi__icon { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--sg-kpi-soft, var(--sg-primary-soft)); color: var(--sg-kpi, var(--sg-primary)); font-size: 1.2rem; }
.sg-kpi__value { margin: 14px 0 3px; font-size: 1.95rem; line-height: 1; font-weight: 800; letter-spacing: -.04em; }
.sg-kpi__label { color: var(--sg-muted); font-size: .86rem; font-weight: 600; }
.sg-kpi--warning { --sg-kpi: #b77900; --sg-kpi-soft: #fff5d8; }
.sg-kpi--danger { --sg-kpi: #c2414d; --sg-kpi-soft: #ffedf0; }
.sg-kpi--success { --sg-kpi: #15805c; --sg-kpi-soft: #e9f8f1; }

.sg-page-title { display:flex; justify-content:space-between; align-items:flex-end; gap:16px; flex-wrap:wrap; }
.sg-page-title__eyebrow { color: var(--sg-primary); font-size:.72rem; font-weight:800; letter-spacing:.11em; text-transform:uppercase; margin-bottom:4px; }
.sg-page-title__subtitle { color: var(--sg-muted); margin: 3px 0 0; }
.sg-empty { padding: 48px 18px; text-align: center; color: var(--sg-muted); }
.sg-empty i { font-size: 2rem; display: block; margin-bottom: 8px; color: #94a3b8; }

/* Usuario */
.user-menu .user-image { object-fit: cover; border: 2px solid #dbe7fb; }
.user-menu .dropdown-menu { border: 1px solid var(--sg-border); border-radius: 15px; box-shadow: var(--sg-shadow); overflow: hidden; }
.user-header { background: linear-gradient(135deg, var(--sg-primary), var(--sg-primary-dark)) !important; padding: 22px 14px !important; }
.user-footer { padding: 12px !important; background: #fff !important; }

/* Accesibilidad */
:focus-visible { outline: 3px solid rgba(13,110,253,.28); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 30000; padding: 10px 14px; background: #111827; color:#fff; border-radius: 8px; }
.skip-link:focus { top: 12px; }

@media (max-width: 767.98px) {
  .app-content > .container-fluid, .app-content-header > .container-fluid { padding-left: 14px; padding-right: 14px; }
  .app-content-header { padding-top: 18px; }
  .card-body { padding: 1rem; }
  .btn { min-height: 42px; }
  .table > :not(caption) > * > * { padding: .75rem .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

.hover-card { transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.hover-card:hover { transform: translateY(-3px); box-shadow: var(--sg-shadow) !important; border-color: #cfe0ff !important; }


/* Marca de desarrollo · Innovam SpA */
.sg-footer-inner {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.sg-footer-product {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.sg-footer-product > span { color: #94a3b8; }
.sg-developed-by,
.sg-login-credit {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: #64748b;
  font-size: .72rem;
  line-height: 1;
  white-space: nowrap;
}
.sg-developed-by strong,
.sg-login-credit strong { color: #475569; font-weight: 700; }
.sg-developed-by img {
  width: 88px;
  height: 24px;
  object-fit: contain;
  opacity: .58;
  filter: saturate(.72);
}
.sg-login-credit {
  margin-top: 26px;
  width: 100%;
  opacity: .78;
}
.sg-login-credit img {
  width: 104px;
  height: 28px;
  object-fit: contain;
  opacity: .62;
  filter: saturate(.72);
}
@media (max-width: 575.98px) {
  .sg-footer-inner { justify-content: center; text-align: center; }
  .sg-footer-product > span { display: none; }
  .sg-developed-by span { display: none; }
  .sg-developed-by img { width: 76px; }
  .sg-login-credit { justify-content: center; flex-wrap: wrap; }
}
