:root {
  --bg-page: #f6f6f4;
  --bg-card: #ffffff;
  --bg-subtle: #ededea;
  --border-color: #e4e4e0;
  --border-hover: #bdbdb6;
  --text-main: #121211;
  --text-muted: #6e6e68;
  --text-soft: #9a9a93;
  --accent: #121211;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
}

html.dark {
  --bg-page: #0d0e10;
  --bg-card: #151619;
  --bg-subtle: #1e2024;
  --border-color: #25272c;
  --border-hover: #3e4149;
  --text-main: #f4f4f6;
  --text-muted: #989aa1;
  --text-soft: #63666e;
  --accent: #f4f4f6;
  --accent-fg: #121211;
  --danger: #f87171;
  --danger-bg: rgba(220, 38, 38, 0.14);
  --success: #34d399;
  --success-bg: rgba(5, 150, 105, 0.14);
  --warning: #fbbf24;
  --warning-bg: rgba(217, 119, 6, 0.14);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden; /* Elimina cualquier scroll horizontal no deseado */
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

.mono {
  font-family:
    "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* =========================================================
   LAYOUT Y CONTENEDORES
   ========================================================= */
.container {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px;
}

/* LA SOLUCIÓN: Altura auto y min-height para que jamás se coma el contenido hacia arriba */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  width: 100%;
  height: auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.04em;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   NAVEGACIÓN (TABS)
   ========================================================= */
.nav-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-main);
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* =========================================================
   BOTONES
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-outline {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-outline:hover {
  border-color: var(--border-hover);
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-danger:hover {
  opacity: 0.85;
}

.btn-sm {
  padding: 4px 9px;
  font-size: 11.5px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
}

/* =========================================================
   TARJETAS Y ESTADÍSTICAS
   ========================================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 2px;
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  flex-shrink: 0;
}

/* =========================================================
   TABLAS LIMPIAS
   ========================================================= */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
  font-size: 12.5px;
  vertical-align: middle;
}

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

tr:hover td {
  background: color-mix(in srgb, var(--bg-subtle) 40%, transparent);
}

/* =========================================================
   BADGES Y FORMULARIOS
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-neutral {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.form-control:focus {
  border-color: var(--text-muted);
  background: var(--bg-card);
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 25%, transparent);
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

/* =========================================================
   MODALES
   ========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

/* Checkboxes */
.perm-group {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--bg-page);
}

.perm-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 7px;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 11.5px;
  transition: border-color 0.15s;
}

.perm-item:hover {
  border-color: var(--border-hover);
}

.perm-item input {
  accent-color: var(--text-main);
  width: 15px;
  height: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

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

/* =========================================================
   REGLAS GLOBALES RESPONSIVE (MÓVIL / TABLET)
   ========================================================= */
@media (max-width: 768px) {
  .container {
    padding: 0 12px;
  }

  .topbar {
    padding: 8px 0;
  }

  .topbar-inner {
    flex-wrap: wrap;
    gap: 10px;
  }

  .brand-title {
    font-size: 13.5px;
  }

  .brand-sub {
    display: none;
  }

  .modal-backdrop {
    padding: 8px;
    align-items: flex-end;
  }

  .modal-content {
    padding: 16px;
    border-radius: 16px 16px 8px 8px;
    max-height: 88vh;
  }

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

  .perm-grid {
    grid-template-columns: 1fr;
  }
}
