:root {
  --ink: #13213a;
  --muted: #5e6f88;
  --panel: #ffffff;
  --line: #d8e0ec;
  --surface: #f5f8ff;
  --accent: #0f6ab8;
  --accent-2: #ff8a00;
  --ok: #0c8a5a;
  --bad: #af2a3d;
  --shadow: 0 16px 34px rgba(16, 34, 67, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(165deg, #eef5ff 0%, #f7fff9 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.35;
  z-index: 0;
  pointer-events: none;
}

.orb-a {
  left: -120px;
  top: -120px;
  background: #7ec6ff;
}

.orb-b {
  right: -120px;
  bottom: -100px;
  background: #b8f2c3;
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.22s ease;
}

.layout.sidebar-hidden {
  grid-template-columns: 0 1fr;
}

.layout.sidebar-hidden .sidebar {
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  background: rgba(18, 34, 64, 0.95);
  color: #e8efff;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
  transition: opacity 0.18s ease, padding 0.22s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 64px;
  height: 44px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 12px 24px rgba(3, 12, 25, 0.26);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: #b5c3de;
}

.menu {
  display: grid;
  gap: 3px;
}

.menu-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: #a9bddc;
  padding: 10px 12px 10px 15px;
  border-radius: 9px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.menu-item::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  border-radius: 3px;
  background: #5ca6e5;
  transition: height 0.18s ease;
}

.menu-icon {
  flex-shrink: 0;
  display: inline-flex;
  width: 20px;
  justify-content: center;
  opacity: 0.75;
  transition: opacity 0.15s ease;
}

.menu-icon svg {
  width: 17px;
  height: 17px;
  display: block;
}

.menu-item.active .menu-icon,
.menu-item:hover .menu-icon {
  opacity: 1;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e8efff;
}

.menu-item.active {
  background: linear-gradient(135deg, #1b70bf, #155491);
  color: #f4f8ff;
  box-shadow: 0 8px 18px rgba(8, 20, 40, 0.3);
}

.menu-item.active::before {
  height: 60%;
}

.session-box {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 12px;
}

.session-title {
  margin: 0;
  font-size: 0.75rem;
  color: #afc3e6;
}

.session-user {
  margin: 8px 0 12px;
  font-weight: 700;
}

.main {
  /* En movil el sidebar pasa a position:fixed (queda fuera del flujo del grid). Sin
     esto, el auto-placement del grid reacomoda a ".main" en la 1ra columna (0px,
     reservada para el sidebar) en vez de la 2da (1fr), y termina angosto/cortado en
     vez de ocupar todo el ancho. Fijar la columna explicitamente evita ese reacomodo. */
  grid-column: 2;
  padding: 26px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar-title {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.sidebar-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid #9fb0c7;
  background: #f8fbff;
  color: #274263;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.sidebar-toggle svg {
  width: 19px;
  height: 19px;
}

.sidebar-toggle:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}

.topbar h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2.5vw, 2rem);
  font-family: "Space Grotesk", sans-serif;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.topbar-session {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-pill {
  min-width: 240px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(19, 33, 58, 0.08);
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
}

.session-pill-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

.session-user-trigger {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--ink);
  font-weight: 800;
  text-align: left;
  cursor: default;
}

.session-user-trigger.enabled {
  cursor: pointer;
  transition: color 0.2s ease;
}

.session-user-trigger.enabled:hover {
  color: var(--accent);
}

.panel {
  display: none;
  margin-top: 16px;
  animation: fadeUp 0.3s ease;
}

.panel.active {
  /* flex (no grid): las tarjetas hijas (.card) deben apilarse a todo el ancho
     disponible. Un grid de una sola columna sin "grid-template-columns" explicito
     dimensiona esa columna al contenido (auto = shrink-to-fit), no al ancho del
     contenedor, asi que las tarjetas quedaban angostas con espacio vacio al lado en
     pantallas chicas. Flex-column con el "stretch" por defecto si las estira. */
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.card-tight {
  max-width: 540px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #0d6e6e;
  font-weight: 800;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 210px);
  padding: 8px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-logo {
  width: 104px;
  height: 72px;
  object-fit: cover;
  border-radius: 50%;
  margin-bottom: 0;
  box-shadow: 0 14px 26px rgba(3, 12, 25, 0.2);
}

.login-card {
  align-self: center;
  width: min(460px, 100%);
  background:
    radial-gradient(circle at 100% 0%, rgba(41, 182, 246, 0.12), transparent 48%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(246, 251, 255, 0.94));
  border: 1px solid rgba(18, 62, 108, 0.14);
  border-radius: 22px;
  padding: 28px;
}

.login-card h3 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.65rem;
  margin-bottom: 6px;
  text-align: center;
}

.login-card .muted {
  text-align: center;
  margin-bottom: 10px;
}

.login-form {
  margin-top: 18px;
  grid-template-columns: 1fr;
  gap: 14px;
}

.login-form .btn.primary {
  width: auto;
  min-width: 170px;
  display: block;
  justify-self: center;
  margin-inline: auto;
  padding: 8px 12px;
  border-radius: 14px;
}

.login-form-links {
  text-align: center;
  margin-top: 14px;
}

.link-button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-button:hover {
  color: #0a4a80;
}

.field {
  gap: 8px;
}

.field input {
  border-radius: 14px;
  border: 1px solid #bfd2e9;
  background: linear-gradient(180deg, #ffffff, #f6faff);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.field input:focus {
  border-color: #2480cb;
  box-shadow: 0 0 0 4px rgba(36, 128, 203, 0.16), 0 10px 20px rgba(15, 106, 184, 0.12);
}

/* Honeypot anti-bot: oculto para usuarios reales, pero presente en el DOM
   para que los bots que autocompletan formularios lo rellenen y se delaten. */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

h3 {
  margin: 0 0 8px;
}

h4 {
  margin: 0;
}

.muted {
  color: var(--muted);
  margin-top: 0;
}

.form-grid,
.form-grid.login-form {
  grid-template-columns: 1fr;
}
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  grid-column: 1 / -1;
  min-width: 0;
}

.users-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  min-width: 0;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid #c9d6e7;
  border-radius: 14px;
  background: #fff;
  padding: 12px 14px;
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: #2a8bd3;
  box-shadow: 0 0 0 4px rgba(42, 139, 211, 0.14);
}

/* El input de archivo nativo (boton gris del SO) desentona con el resto de
   controles redondeados/azules del portal, asi que se restyla el boton interno. */
input[type="file"] {
  width: 100%;
  min-width: 0;
  padding: 7px 10px 7px 7px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  border: 0;
  border-radius: 9px;
  padding: 8px 14px;
  margin-right: 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #2a8bd3);
  color: #fff;
  transition: filter 0.15s ease, transform 0.15s ease;
}

input[type="file"]:hover::file-selector-button,
input[type="file"]:hover::-webkit-file-upload-button {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.inline-check {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-bottom: 10px;
}

.btn {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, background-color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.98);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  filter: none;
}

.btn-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btnSpin 0.7s linear infinite;
}

@keyframes btnSpin {
  to {
    transform: rotate(360deg);
  }
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #2a8bd3);
  color: #fff;
  box-shadow: 0 12px 20px rgba(15, 106, 184, 0.22);
}

.btn.primary:hover {
  box-shadow: 0 14px 26px rgba(15, 106, 184, 0.3);
}

.btn.ghost {
  border: 1px solid #9fb0c7;
  color: #274263;
  background: #f8fbff;
}

.btn.ghost:hover {
  background: #edf4ff;
  border-color: var(--accent);
}

.btn.warn {
  background: #fff3f4;
  border: 1px solid #edb8c1;
  color: #8f1e32;
}

.btn.warn:hover {
  background: #ffe7e9;
  border-color: #e08c9b;
}

.btn.success {
  background: linear-gradient(135deg, #1e9f65, #22b573);
  color: #fff;
  box-shadow: 0 10px 18px rgba(20, 132, 84, 0.22);
}

.btn.success:hover {
  box-shadow: 0 12px 22px rgba(20, 132, 84, 0.3);
}

.btn.small {
  padding: 6px 10px;
  font-size: 0.78rem;
  margin-right: 6px;
  margin-bottom: 4px;
}

/* Menu de acciones por fila (tablas con muchas acciones por registro) */
.row-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #9fb0c7;
  background: #f8fbff;
  color: #274263;
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.row-menu-toggle:hover,
.row-menu-toggle[aria-expanded="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.row-menu-dots {
  font-size: 1rem;
  line-height: 1;
}

.row-menu-panel {
  position: fixed;
  z-index: 1000;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.row-menu-item:hover,
.row-menu-item:focus-visible {
  background: var(--surface);
  color: var(--accent);
}

.row-menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.row-menu-item.danger {
  color: var(--bad);
}

.row-menu-item.danger:hover,
.row-menu-item.danger:focus-visible {
  color: var(--bad);
}

.row-menu-icon {
  display: inline-flex;
  opacity: 0.75;
}

.row-menu-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.row-menu-item:hover .row-menu-icon {
  opacity: 1;
}

.row-menu-empty {
  display: block;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.table-card {
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tool-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
}

.tool-inline select {
  min-width: 110px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.78rem;
}

.badge {
  background: #e6f4ff;
  color: #0f588f;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-ok {
  background: #ddf5ea;
  color: var(--ok);
}

.badge-warn {
  background: #fff3d9;
  color: #8a5a00;
}

.badge-bad {
  background: #ffe6ea;
  color: var(--bad);
}

.dashboard-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px 18px;
  padding: 14px 20px;
}

.dashboard-filters {
  margin: 0;
  flex: 1 1 340px;
}

.dashboard-quick-ranges {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin-top: 0;
}

.filters > .btn {
  align-self: end;
  margin-top: 22px;
}

.dashboard-alerts {
  display: grid;
  gap: 10px;
}

.alert-banner {
  border-radius: 14px;
  padding: 14px 16px;
  font-weight: 700;
  border: 1px solid #f1bfca;
  background: #fff3f4;
  color: #8f1e32;
}

.alert-banner.warn {
  border-color: #f4d7a1;
  background: #fff7e7;
  color: #8a5a00;
}

.dashboard-stats {
  display: grid;
  gap: 16px;
}

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

.stat-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(18, 62, 108, 0.12);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 38px rgba(16, 34, 67, 0.17);
}

.stats-grid .stat-card:nth-child(1) {
  background: linear-gradient(160deg, #eef7ff, #e7f1ff);
  border-color: #c6ddf8;
}

.stats-grid .stat-card:nth-child(2) {
  background: linear-gradient(160deg, #ecfff7, #e4f8f0);
  border-color: #bdebd7;
}

.stats-grid .stat-card:nth-child(3) {
  background: linear-gradient(160deg, #fff7ec, #fff0de);
  border-color: #f3d7ad;
}

.stats-grid .stat-card:nth-child(4) {
  background: linear-gradient(160deg, #fff1f3, #ffe7ec);
  border-color: #f3c2cc;
}

.stat-card .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.stat-card .value {
  display: block;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.15rem, 1.65vw + 0.85rem, 1.65rem);
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stat-card .stat-hint {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-top: 6px;
}

.stats-grid .stat-card:nth-child(1) .value {
  color: #0e4f84;
}

.stats-grid .stat-card:nth-child(2) .value {
  color: #0e7b58;
}

.stats-grid .stat-card:nth-child(3) .value {
  color: #9a5b00;
}

.stats-grid .stat-card:nth-child(4) .value {
  color: #a32845;
}

/* Variante compacta: KPIs embebidos arriba de una tabla (Emitidos, Recibidos), en vez de
   solo en el dashboard. Mismo lenguaje visual, menos espacio. */
.stats-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 14px;
}

.stats-grid.compact .stat-card:nth-child(5) {
  background: linear-gradient(160deg, #f1fbf9, #e6f7f2);
  border-color: #bfe8dd;
}

.stats-grid.compact .stat-card:nth-child(5) .value {
  color: #0d6e6e;
}

.stats-grid.compact:empty {
  display: none;
}

.stats-grid.compact .stat-card {
  padding: 10px 14px;
  border-radius: 12px;
}

.stats-grid.compact .stat-card .label {
  font-size: 0.7rem;
  margin-bottom: 4px;
}

.stats-grid.compact .stat-card .value {
  font-size: 1.2rem;
}

/* Fila principal de KPIs del dashboard: puede llevar una tarjeta extra (tasa de
   aceptacion) ademas de las 4 base, asi que se acomoda sola en vez de forzar 4 columnas. */
.stats-grid.dashboard-kpis {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.stats-grid.dashboard-kpis .stat-card:nth-child(5) {
  background: linear-gradient(160deg, #f1fbf9, #e6f7f2);
  border-color: #bfe8dd;
}

.stats-grid.dashboard-kpis .stat-card:nth-child(5) .value {
  color: #0d6e6e;
}

.stats-grid.dashboard-kpis .stat-card:nth-child(6) {
  background: linear-gradient(160deg, #f3f0ff, #ece6fb);
  border-color: #d9cdf5;
}

.stats-grid.dashboard-kpis .stat-card:nth-child(6) .value {
  color: #5b3fa8;
}

.stats-grid.dashboard-kpis .stat-card:nth-child(7) {
  background: linear-gradient(160deg, #eafbff, #dff5fb);
  border-color: #bfe6f2;
}

.stats-grid.dashboard-kpis .stat-card:nth-child(7) .value {
  color: #0a7ea3;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

.chart-card,
.insight-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(18, 62, 108, 0.11);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  transition: box-shadow 0.18s ease;
}

.chart-card:hover,
.insight-card:hover {
  box-shadow: 0 20px 38px rgba(16, 34, 67, 0.16);
}

.dashboard-grid .chart-card:nth-child(1) {
  background: linear-gradient(180deg, #f7fbff, #f2f9ff);
}

.dashboard-grid .chart-card:nth-child(2) {
  background: linear-gradient(180deg, #f9fff6, #f2faee);
}

.dashboard-grid .insight-card:nth-child(1) {
  background: linear-gradient(180deg, #fff9f2, #fff4e6);
}

.dashboard-grid .insight-card:nth-child(2) {
  background: linear-gradient(180deg, #fff5f8, #ffedf2);
}

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-item {
  display: grid;
  gap: 6px;
}

.bar-item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  font-weight: 700;
}

.bar-item-numbers {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.bar-item-pct {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #e7eef8;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(135deg, #0d6e6e, #1b70bf);
}

.bar-fill.ok {
  background: linear-gradient(135deg, #0c8a5a, #22b573);
}

.bar-fill.bad {
  background: linear-gradient(135deg, #af2a3d, #d94b60);
}

.bar-fill.warn {
  background: linear-gradient(135deg, #b3760a, #e0a530);
}

.bar-fill.info {
  background: linear-gradient(135deg, #0f6ab8, #2a8bd3);
}

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.donut-svg {
  width: 140px;
  height: 140px;
  flex: 0 0 auto;
}

.donut-segment {
  transition: opacity 0.15s ease;
}

.donut-segment:hover {
  opacity: 0.8;
}

.donut-legend {
  display: grid;
  gap: 8px;
  flex: 1 1 200px;
  min-width: 0;
}

.donut-legend-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
}

.donut-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  align-self: center;
}

.donut-legend-label {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donut-legend-numbers {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex: 0 0 auto;
}

.trend-scroll {
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.trend-list {
  display: grid;
  gap: 10px;
}

.trend-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.cert-form,
.users-form,
#formPermisos {
  gap: 14px;
}

/* Acciones de formularios con mas de un boton (guardar/nuevo, guardar/desactivar):
   van en un contenedor propio, fuera del grid de campos. Si se hicieran parte del
   mismo grid "auto-fit" abarcando toda la fila (grid-column: 1 / -1), el navegador
   cuenta esa fila como si tocara todas las columnas auto-generadas, evitando que las
   columnas vacias colapsen y dejando los campos angostos y con texto cortado. */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
}

.checkbox-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #23405f;
}

.checkbox-inline input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Formulario de Configuracion de Correo (SMTP): agrupado por secciones para que
   campos de distinta naturaleza (host, credenciales, mensaje, toggles, acciones)
   no queden todos mezclados en una sola grilla pareja. */
.correo-form {
  display: grid;
  gap: 18px;
}

.correo-form-section {
  display: grid;
  gap: 12px;
}

.correo-form-section-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.correo-form-hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
}

.correo-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.correo-form-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.correo-form-toggles .checkbox-inline {
  margin: 0;
}

.correo-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.correo-prueba-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.correo-prueba-form label {
  flex: 1 1 260px;
}

.prueba-correo {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.prueba-correo h4 {
  margin: 0 0 4px;
}

#formPermisos {
  margin-top: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: stretch;
}

#formPermisos > label:first-child {
  grid-column: 1 / -1;
  max-width: 320px;
}

#formPermisos .inline-check {
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid #c6d7ec;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #f5f9ff);
  font-weight: 700;
  color: #23405f;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

#formPermisos .inline-check:hover {
  border-color: #8eb7e0;
  box-shadow: 0 8px 18px rgba(23, 84, 146, 0.12);
  transform: translateY(-1px);
}

#formPermisos .inline-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

#formLogin .btn.primary,
#formDashboardFilters .btn.primary,
#formRecibidos .btn.primary,
#formEmitidos .btn.primary,
#formUsuario .btn.primary,
#formPermisos .btn.primary,
#formLogsSeguridad .btn.primary,
#formLogsRelevantes .btn.primary,
#formCertificado .btn.primary,
#formChangePassword .btn.primary {
  padding: 8px 12px;
  font-size: 0.88rem;
  border-radius: 10px;
  min-height: 38px;
}

#formDashboardFilters .btn.primary,
#formRecibidos .btn.primary,
#formEmitidos .btn.primary,
#formUsuario .btn.primary,
#formLogsSeguridad .btn.primary,
#formLogsRelevantes .btn.primary,
#formCertificado .btn.primary {
  justify-self: start;
  width: auto;
  min-width: 150px;
}

#formPermisos .btn.primary {
  grid-column: 1 / -1;
  justify-self: end;
  min-width: 170px;
  padding: 8px 12px;
}

/* Fecha de vencimiento del certificado: destacada aparte de los info-tile genericos
   (archivo, thumbprint, subject), con color segun urgencia. */
.cert-vencimiento {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--surface);
}

.cert-vencimiento .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.cert-vencimiento .value {
  display: block;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
}

.cert-vencimiento-ok {
  background: linear-gradient(160deg, #ecfff7, #e4f8f0);
  border-color: #bdebd7;
}

.cert-vencimiento-ok .value {
  color: #0e7b58;
}

.cert-vencimiento-warn {
  background: linear-gradient(160deg, #fff7ec, #fff0de);
  border-color: #f3d7ad;
}

.cert-vencimiento-warn .value {
  color: #9a5b00;
}

.cert-vencimiento-bad {
  background: linear-gradient(160deg, #fff1f3, #ffe7ec);
  border-color: #f3c2cc;
}

.cert-vencimiento-bad .value {
  color: #a32845;
}

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

.info-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.info-tile .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.info-tile .value {
  display: block;
  font-weight: 700;
  word-break: break-word;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  font-size: 0.9rem;
}

th {
  color: #2e4666;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 2px solid var(--line);
}

tbody tr {
  transition: background-color 0.15s ease;
}

tbody tr:nth-child(even) {
  background: rgba(15, 106, 184, 0.03);
}

tbody tr:hover {
  background: rgba(15, 106, 184, 0.07);
}

tbody tr:last-child td {
  border-bottom: none;
}

.tag {
  font-size: 0.76rem;
  padding: 4px 8px;
  border-radius: 999px;
  display: inline-block;
  font-weight: 700;
}

.tag.ok {
  background: #ddf5ea;
  color: var(--ok);
}

.tag.bad {
  background: #ffe6ea;
  color: var(--bad);
}

.tag.warn {
  background: #fff3d9;
  color: #8a5a00;
}

.tag.info {
  background: #e6f4ff;
  color: #0f588f;
}

.toast {
  margin-top: 14px;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  animation: toastIn 0.22s ease;
}

.toast-icon {
  flex-shrink: 0;
  display: inline-flex;
}

.toast-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.toast.info {
  background: #e7f4ff;
  color: #0b609c;
  border: 1px solid #abd6f2;
}

.toast.error {
  background: #ffe9ee;
  color: #8f1e32;
  border: 1px solid #f1bfca;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Estado vacio de tablas: mensaje centrado y discreto en vez de una celda
   de texto plano pegada al borde izquierdo. */
.table-empty {
  text-align: center !important;
  padding: 28px 10px !important;
  color: var(--muted);
  font-weight: 600;
}

.table-empty-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
  opacity: 0.5;
}

.table-empty-icon svg {
  width: 30px;
  height: 30px;
}

.hidden {
  display: none;
}

.xml-box {
  margin: 0;
  max-height: 70vh;
  overflow: auto;
  background: #0d1c33;
  color: #eaf2ff;
  border-radius: 10px;
  padding: 14px;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre;
  word-break: break-word;
}

.xml-box .xml-tag {
  color: #8ad8ff;
  font-weight: 700;
}

.xml-box .xml-attr {
  color: #ffd479;
}

.xml-box .xml-value {
  color: #a7f4bf;
}

.xml-box .xml-comment {
  color: #95a7c4;
  font-style: italic;
}

#xmlViewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  padding: 24px;
  background: rgba(8, 18, 35, 0.62);
  backdrop-filter: blur(3px);
}

#xmlViewer .card {
  width: min(1200px, 95vw);
  max-height: 90vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

#xmlViewer.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: 24px;
  background: rgba(8, 18, 35, 0.62);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-layer.hidden {
  display: none;
}

.password-modal-card {
  width: min(460px, 92vw);
}

.aprobacion-modal-card {
  width: min(860px, 96vw);
  max-height: 88vh;
  overflow: auto;
}

.aprobacion-modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.aprobacion-modal-form label:nth-of-type(3) {
  grid-column: 1 / -1;
}

.aprobacion-modal-form .inline-check {
  grid-column: 1 / -1;
  margin: 0;
  border: 1px solid #d7e2f0;
  border-radius: 10px;
  background: #f7fbff;
  padding: 10px 12px;
}

.aprobacion-modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.aprobacion-modal-actions .btn.primary {
  min-width: 180px;
}

.password-modal-form {
  display: grid;
  gap: 12px;
}

.password-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.pager-info {
  color: var(--muted);
  font-size: 0.82rem;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .topbar,
  .dashboard-hero,
  .dashboard-grid,
  .login-shell {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar-session,
  .login-metrics,
  .stats-grid,
  .certificado-resumen {
    grid-template-columns: 1fr;
  }

  /* .stats-grid.compact y .stats-grid.dashboard-kpis definen su propio
     grid-template-columns fuera de este media query con mayor especificidad (dos
     clases), asi que la regla ".stats-grid { 1fr }" de arriba no les gana y sin esto
     seguirian intentando varias columnas angostas en vez de una sola columna completa. */
  .stats-grid.compact,
  .stats-grid.dashboard-kpis {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 18px;
  }

  /* En movil el menu deja de apilarse arriba del contenido: se convierte en un panel
     deslizante (drawer) que flota sobre la pagina, oculto por defecto, con un fondo
     oscuro (backdrop) detras para cerrarlo tocando fuera. */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 84vw);
    z-index: 60;
    border-bottom: 0;
    border-right: 1px solid #2d4468;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  .layout:not(.sidebar-hidden) .sidebar {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(9, 14, 26, 0.45);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .layout:not(.sidebar-hidden) .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.no-scroll {
    overflow: hidden;
  }

  .menu-item {
    padding: 13px 12px 13px 15px;
    min-height: 44px;
  }

  .btn {
    min-height: 42px;
  }

  .password-modal-actions {
    justify-content: stretch;
  }

  .password-modal-actions .btn {
    flex: 1;
  }

  .aprobacion-modal-form {
    grid-template-columns: 1fr;
  }

  .aprobacion-modal-actions {
    justify-content: stretch;
  }

  .aprobacion-modal-actions .btn {
    flex: 1;
  }

  .filters > .btn {
    margin-top: 0;
  }

  #formPermisos .btn.primary {
    justify-self: stretch;
    width: 100%;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn {
    width: 100%;
    min-width: 0;
  }

  .main {
    padding: 18px;
  }
}

/* ============================================================
   Modo oscuro: sigue la preferencia del sistema operativo.
   Los tokens de :root cubren texto/superficies/bordes neutros;
   el resto de las reglas de esta seccion oscurece puntualmente
   fondos y colores que estaban fijos en tonos pastel claros
   (KPIs, vencimiento de certificado, inputs) para que sigan
   siendo legibles sobre fondo oscuro sin perder su identidad.
   Los colores de marca/acento (--accent, --ok, --bad) y los
   badges/tags/alertas (fondo+texto pastel autocontenidos) se
   dejan igual: ya tienen buen contraste en ambos temas.
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7ecf3;
    --muted: #93a1b8;
    --panel: #1b2333;
    --line: #313c52;
    --surface: #232c3f;
    --shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
  }

  body {
    background: linear-gradient(165deg, #0f1420 0%, #10181a 100%);
  }

  .bg-orb {
    opacity: 0.16;
  }

  .card,
  .chart-card,
  .insight-card {
    background: rgba(27, 35, 51, 0.92);
  }

  .login-card {
    background:
      radial-gradient(circle at 100% 0%, rgba(41, 182, 246, 0.14), transparent 48%),
      linear-gradient(180deg, rgba(27, 35, 51, 0.97), rgba(20, 27, 40, 0.95));
    border-color: rgba(96, 150, 210, 0.22);
  }

  input,
  select,
  .field input {
    background: #1b2333;
    border-color: #3a465e;
    color: var(--ink);
  }

  .session-pill {
    background: rgba(27, 35, 51, 0.75);
    border-color: rgba(255, 255, 255, 0.08);
  }

  th {
    color: #aebbd4;
  }

  tbody tr:nth-child(even) {
    background: rgba(77, 159, 232, 0.06);
  }

  tbody tr:hover {
    background: rgba(77, 159, 232, 0.12);
  }

  .checkbox-inline,
  #formPermisos .inline-check {
    color: var(--ink);
  }

  #formPermisos .inline-check {
    background: var(--surface);
    border-color: var(--line);
  }

  .aprobacion-modal-form .inline-check {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
  }

  .stats-grid .stat-card:nth-child(1) { background: linear-gradient(160deg, #17324f, #142943); border-color: #1f4a72; }
  .stats-grid .stat-card:nth-child(2) { background: linear-gradient(160deg, #113827, #0f2e21); border-color: #1c5a3f; }
  .stats-grid .stat-card:nth-child(3) { background: linear-gradient(160deg, #3a2c10, #33260c); border-color: #6b4f14; }
  .stats-grid .stat-card:nth-child(4) { background: linear-gradient(160deg, #3a1620, #33121b); border-color: #6b2537; }
  .stats-grid.compact .stat-card:nth-child(5),
  .stats-grid.dashboard-kpis .stat-card:nth-child(5) { background: linear-gradient(160deg, #103430, #0e2b28); border-color: #1c5952; }
  .stats-grid.dashboard-kpis .stat-card:nth-child(6) { background: linear-gradient(160deg, #241c3d, #1e1733); border-color: #3d2f66; }
  .stats-grid.dashboard-kpis .stat-card:nth-child(7) { background: linear-gradient(160deg, #0f2f38, #0c2730); border-color: #1c5266; }

  .stat-card .label {
    color: #93a1b8;
  }

  .stats-grid .stat-card:nth-child(1) .value { color: #7cc4ff; }
  .stats-grid .stat-card:nth-child(2) .value { color: #5be0a8; }
  .stats-grid .stat-card:nth-child(3) .value { color: #f0b444; }
  .stats-grid .stat-card:nth-child(4) .value { color: #ff8fa3; }
  .stats-grid.compact .stat-card:nth-child(5) .value,
  .stats-grid.dashboard-kpis .stat-card:nth-child(5) .value { color: #4fd6c4; }
  .stats-grid.dashboard-kpis .stat-card:nth-child(6) .value { color: #b79ef0; }
  .stats-grid.dashboard-kpis .stat-card:nth-child(7) .value { color: #5fc9e8; }

  .dashboard-grid .chart-card:nth-child(1) { background: linear-gradient(180deg, #172538, #131f30); }
  .dashboard-grid .chart-card:nth-child(2) { background: linear-gradient(180deg, #142418, #101d14); }
  .dashboard-grid .insight-card:nth-child(1) { background: linear-gradient(180deg, #2b2213, #241c0e); }
  .dashboard-grid .insight-card:nth-child(2) { background: linear-gradient(180deg, #2c1620, #23121a); }

  .cert-vencimiento-ok { background: linear-gradient(160deg, #113827, #0f2e21); border-color: #1c5a3f; }
  .cert-vencimiento-warn { background: linear-gradient(160deg, #3a2c10, #33260c); border-color: #6b4f14; }
  .cert-vencimiento-bad { background: linear-gradient(160deg, #3a1620, #33121b); border-color: #6b2537; }

  .cert-vencimiento-ok .value { color: #5be0a8; }
  .cert-vencimiento-warn .value { color: #f0b444; }
  .cert-vencimiento-bad .value { color: #ff8fa3; }

  .bar-track {
    background: rgba(255, 255, 255, 0.08);
  }

  .modal-layer,
  #xmlViewer {
    background: rgba(0, 0, 0, 0.72);
  }

  .toast.info {
    background: #12293d;
    color: #8fcdf6;
    border-color: #1d4a6c;
  }

  .toast.error {
    background: #3a1620;
    color: #f5aabb;
    border-color: #6b2537;
  }
}
