: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;
}

.sidebar {
  background: rgba(18, 34, 64, 0.95);
  color: #e8efff;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  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: 8px;
}

.menu-item {
  border: 1px solid #33486b;
  background: #1e3357;
  color: #d5e2fb;
  padding: 11px 12px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}

.menu-item.active,
.menu-item:hover {
  background: linear-gradient(135deg, #1b70bf, #155491);
  border-color: #5ca6e5;
}

.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 {
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.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 {
  display: grid;
  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: 80px;
  height: 80px;
  border-radius: 20px;
  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;
}

.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);
}

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;
}

.users-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  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);
}

.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;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #2a8bd3);
  color: #fff;
  box-shadow: 0 12px 20px rgba(15, 106, 184, 0.22);
}

.btn.ghost {
  border: 1px solid #9fb0c7;
  color: #274263;
  background: #f8fbff;
}

.btn.warn {
  background: #fff3f4;
  border: 1px solid #edb8c1;
  color: #8f1e32;
}

.btn.success {
  background: linear-gradient(135deg, #1e9f65, #22b573);
  color: #fff;
  box-shadow: 0 10px 18px rgba(20, 132, 84, 0.22);
}

.btn.small {
  padding: 6px 10px;
  font-size: 0.78rem;
  margin-right: 6px;
  margin-bottom: 4px;
}

.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;
}

.dashboard-hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
  align-items: end;
}

.dashboard-filters {
  margin: 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;
}

.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: 1.65rem;
  font-weight: 700;
}

.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;
}

.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;
}

.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(3) {
  background: linear-gradient(180deg, #fff9f2, #fff4e6);
}

.dashboard-grid .insight-card:nth-child(4) {
  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-track {
  height: 10px;
  border-radius: 999px;
  background: #e7eef8;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(135deg, #0d6e6e, #1b70bf);
}

.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;
}

#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;
}

.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;
}

.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);
}

.toast {
  margin-top: 14px;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
}

.toast.info {
  background: #e7f4ff;
  color: #0b609c;
  border: 1px solid #abd6f2;
}

.toast.error {
  background: #ffe9ee;
  color: #8f1e32;
  border: 1px solid #f1bfca;
}

.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;
  }

  .login-card {
    padding: 18px;
  }

  .sidebar {
    border-bottom: 1px solid #2d4468;
  }

  .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%;
  }

  .main {
    padding: 18px;
  }
}
