:root {
  --navy: #042d57;
  --blue: #0753a0;
  --bright: #0a79e9;
  --sky: #489ff7;
  --ink: #1f2a37;
  --muted: #64748b;
  --line: #d4d4d4;
  --bg: #f3f6fa;
  --card: #ffffff;
  --ok: #0f9d58;
  --warn: #b45309;
  --danger: #c62828;
  --radius: 15px;
  --shadow: 0 10px 30px rgba(4, 45, 87, 0.08);
  --sidebar-width: 76px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: var(--blue);
}

h1,
h2,
h3 {
  color: rgb(59, 103, 140);
}

/* ------------------------------------------------------------------ */
/* Tarjetas y layout                                                   */
/* ------------------------------------------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.card-title {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
  color: rgb(59, 103, 140);
}

.container {
  width: min(1440px, 100% - 32px);
  margin: 22px auto 60px;
}

/* Contenido a todo el ancho, dejando espacio para la barra lateral. */
.app-main {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  max-width: none;
  padding: 20px 24px 48px;
}

/* ------------------------------------------------------------------ */
/* Barra lateral                                                      */
/* ------------------------------------------------------------------ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 12px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--blue) 100%);
  box-shadow: 4px 0 18px rgba(4, 45, 87, 0.18);
}

.sidebar-logo {
  display: block;
  text-decoration: none;
  flex: none;
}

.sidebar-logo .logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  font-size: 21px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 26px;
}

.sidebar-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.side-link,
.side-btn {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: #dce9f8;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
}

.side-link svg,
.side-btn svg {
  width: 22px;
  height: 22px;
}

.side-link:hover,
.side-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.side-link.active {
  background: #ffffff;
  color: var(--navy);
  box-shadow: 0 6px 16px rgba(2, 20, 40, 0.25);
}

.side-link::after,
.side-btn::after {
  content: attr(data-label);
  position: absolute;
  left: 56px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--navy);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 7px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  box-shadow: 0 6px 18px rgba(4, 45, 87, 0.28);
  z-index: 60;
}

.side-link:hover::after,
.side-btn:hover::after {
  opacity: 1;
}

.side-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-top: 4px;
  cursor: default;
  user-select: none;
}

.stack {
  display: grid;
  gap: 18px;
}

/* Evita que una tabla ancha (con scroll interno) ensanche el track del grid
   y desborde horizontalmente toda la página. */
.stack > * {
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12.5px;
}

.right {
  margin-left: auto;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ */
/* Login                                                               */
/* ------------------------------------------------------------------ */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 15% -10%, #0a79e9 0%, #042d57 55%, #021a33 100%);
  padding: 20px;
}

.login-card {
  width: min(430px, 100%);
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  padding: 36px 34px 30px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  background: linear-gradient(135deg, var(--navy), var(--bright));
  flex: none;
}

.login-brand h1 {
  font-size: 21px;
  margin: 0;
}

.login-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 15px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14.5px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(10, 121, 233, 0.28);
  border-color: var(--bright);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--bright);
}

.btn-secondary {
  background: #eef4fb;
  color: var(--navy);
  border-color: #cfe0f3;
}

.btn-ghost {
  background: transparent;
  color: var(--blue);
  border-color: transparent;
  padding: 7px 10px;
}

.btn-danger {
  background: #fdecec;
  color: var(--danger);
  border-color: #f5c6c6;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  margin: 0 0 14px;
  display: none;
}

.alert.show {
  display: block;
}

.alert-error {
  background: #fdecec;
  color: #8e1b1b;
  border: 1px solid #f5c6c6;
}

.alert-ok {
  background: #e8f7ee;
  color: #0b6b3a;
  border: 1px solid #bfe8cf;
}

/* ------------------------------------------------------------------ */
/* Cabecera                                                            */
/* ------------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(100deg, var(--navy), var(--blue));
  color: #fff;
  padding: 12px 0;
  box-shadow: 0 6px 20px rgba(4, 45, 87, 0.25);
}

.topbar-inner {
  width: min(1440px, 100% - 32px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.topbar .brand h1 {
  color: #fff;
  font-size: 18px;
  margin: 0;
}

.topbar .brand p {
  margin: 1px 0 0;
  font-size: 12px;
  color: #c7dcf5;
}

.nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav a {
  color: #dce9f8;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.nav a.active {
  background: #fff;
  color: var(--navy);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: #dce9f8;
  font-size: 13px;
}

.user-menu .btn-ghost {
  color: #fff;
}

/* ------------------------------------------------------------------ */
/* Filtros                                                             */
/* ------------------------------------------------------------------ */
.filters {
  display: flex;
  align-items: end;
  gap: 14px;
  flex-wrap: wrap;
}

.filters .field {
  margin: 0;
  min-width: 165px;
  flex: 1 1 165px;
  max-width: 240px;
}

/* ------------------------------------------------------------------ */
/* Selects personalizados                                              */
/* ------------------------------------------------------------------ */
.cselect {
  position: relative;
  width: 100%;
}

.cselect-native {
  display: none;
}

.cselect-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14.5px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cselect-trigger:hover {
  border-color: var(--sky);
}

.cselect-trigger:focus-visible,
.cselect.is-open .cselect-trigger {
  outline: none;
  border-color: var(--bright);
  box-shadow: 0 0 0 3px rgba(10, 121, 233, 0.16);
}

.cselect-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cselect-chevron {
  flex: none;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: transform 0.18s ease, color 0.18s ease;
}

.cselect-chevron svg {
  width: 16px;
  height: 16px;
}

.cselect.is-open .cselect-chevron {
  transform: rotate(180deg);
  color: var(--bright);
}

.cselect-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 60;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #ffffff;
  border: 1px solid #d4d4d4;
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(4, 45, 87, 0.18);
  max-height: 280px;
  overflow: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s ease;
}

.cselect.is-open .cselect-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.cselect-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.cselect-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cselect-option:hover,
.cselect-option.is-active {
  background: #eef4fb;
}

.cselect-option.is-selected {
  background: #e8f1fc;
  color: var(--navy);
  font-weight: 600;
}

.cselect-option.is-selected::after {
  content: "✓";
  flex: none;
  color: var(--bright);
  font-size: 13px;
  font-weight: 700;
}

.cselect-menu::-webkit-scrollbar {
  width: 8px;
}

.cselect-menu::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-basis: 100%;
  margin-top: 12px;
  min-height: 26px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #e8f1fc;
  border: 1px solid #cfe0f3;
  color: var(--navy);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
}

.chip button {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

/* ------------------------------------------------------------------ */
/* KPIs y gráficos                                                     */
/* ------------------------------------------------------------------ */
.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.kpi .label {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.kpi .value {
  font-size: 30px;
  font-weight: 800;
  color: var(--navy);
  margin-top: 4px;
  line-height: 1.1;
}

.kpi .hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.chart-title {
  text-align: center;
}

.chart {
  height: 360px;
  width: 100%;
}

/* ------------------------------------------------------------------ */
/* Tablas                                                              */
/* ------------------------------------------------------------------ */
.table-wrap {
  overflow: auto;
  height: 380px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

table.data {
  border-collapse: collapse;
  width: 100%;
  min-width: 1706px;
  table-layout: fixed;
  font-size: 12.5px;
}

table.data th {
  position: sticky;
  top: 0;
  background: #eef4fb;
  color: var(--navy);
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid #d7e4f3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12.5px;
  z-index: 1;
}

table.data th:nth-child(1) { width: 84px; }
table.data th:nth-child(2) { width: 124px; }
table.data th:nth-child(3) { width: 94px; }
table.data th:nth-child(4) { width: 128px; }
table.data th:nth-child(5) { width: 104px; }
table.data th:nth-child(6) { width: 158px; }
table.data th:nth-child(7) { width: 158px; }
table.data th:nth-child(8) { width: 108px; }
table.data th:nth-child(9) { width: 108px; }
table.data th:nth-child(10) { width: 114px; }
table.data th:nth-child(11) { width: 40px; }
table.data th:nth-child(12) { width: 40px; }
table.data th:nth-child(13) { width: 58px; }
table.data th:nth-child(14) { width: 60px; }
table.data th:nth-child(15) { width: 84px; }
table.data th:nth-child(16) { width: 94px; }
table.data th:nth-child(17) { width: 150px; }

table.data th.sortable {
  cursor: pointer;
  user-select: none;
}

table.data th.sortable:hover {
  background: #e2edf9;
}

table.data td {
  padding: 8px 8px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: middle;
  line-height: 1.3;
  height: 34px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.data tbody tr:nth-child(even) {
  background: #fbfdff;
}

table.data tbody tr:hover {
  background: #f1f7fe;
}

.cell-clip {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: #eef4fb;
  color: var(--blue);
  border: 1px solid #d7e4f3;
}

.badge-warn {
  background: #fff4e5;
  color: var(--warn);
  border-color: #f6d6a8;
}

.badge-ok {
  background: #e8f7ee;
  color: #0b6b3a;
  border-color: #bfe8cf;
}

.badge-muted {
  background: #f1f5f9;
  color: #64748b;
  border-color: #e2e8f0;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}

.pagination .btn {
  padding: 6px 11px;
  font-size: 12.5px;
}

/* ------------------------------------------------------------------ */
/* Admin                                                               */
/* ------------------------------------------------------------------ */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.tabs button {
  border: 0;
  background: transparent;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-family: inherit;
}

.tabs button.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .field {
  margin: 0;
  min-width: 180px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

/* ------------------------------------------------------------------ */
/* Modal / diálogo                                                     */
/* ------------------------------------------------------------------ */
dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(760px, calc(100% - 28px));
  max-height: calc(100vh - 40px);
  box-shadow: 0 30px 80px rgba(2, 20, 40, 0.4);
}

dialog::backdrop {
  background: rgba(4, 25, 48, 0.55);
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 17px;
}

.dialog-body {
  padding: 18px 20px;
  overflow: auto;
  max-height: calc(100vh - 210px);
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: #fbfdff;
}

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

.scope-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.scope-box {
  border: 1px solid #dbe5f0;
  border-radius: 12px;
  padding: 10px;
  background: #fbfdff;
}

.scope-box header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--navy);
  font-size: 13px;
}

.scope-box select {
  height: 230px;
  padding: 6px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  padding: 5px 0;
}

.check input {
  width: 16px;
  height: 16px;
}

/* ------------------------------------------------------------------ */
/* Registros (iframe)                                                  */
/* ------------------------------------------------------------------ */
.iframe-card {
  padding: 0;
  overflow: hidden;
}

.iframe-card iframe {
  display: block;
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 620px;
  border: 0;
}

/* ------------------------------------------------------------------ */
/* Toasts                                                              */
/* ------------------------------------------------------------------ */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100% - 36px));
}

.toast {
  background: #fff;
  border-left: 5px solid var(--ok);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 14px 40px rgba(4, 45, 87, 0.25);
  font-size: 13.5px;
}

.toast.error {
  border-left-color: var(--danger);
}

/* ------------------------------------------------------------------ */
/* Utilidades                                                          */
/* ------------------------------------------------------------------ */
.hidden {
  display: none !important;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.nowrap {
  white-space: nowrap;
}

@media (max-width: 1280px) {
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1200px) {
  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

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

@media (max-width: 820px) {
  .grid-2,
  .scope-grid {
    grid-template-columns: 1fr;
  }
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .chart {
    height: 300px;
  }
}

@media (max-width: 760px) {
  :root {
    --sidebar-width: 64px;
  }
  .app-main {
    padding: 16px 14px 36px;
  }
  .side-link,
  .side-btn {
    width: 42px;
    height: 42px;
  }
  .sidebar-logo .logo {
    width: 40px;
    height: 40px;
  }
  .side-link::after,
  .side-btn::after {
    display: none;
  }
}

@media (max-width: 560px) {
  .kpis {
    grid-template-columns: 1fr;
  }
}
