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

:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #3b82f6;
  --success: #059669;
  --success-dark: #047857;
  --success-light: #10b981;
  --error: #dc2626;
  --warning: #f59e0b;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --surface-hover: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #475569;
  --shadow: rgba(0, 0, 0, 0.6);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

.container {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--surface);
  border-radius: 0;
  padding: 1.25rem;
  box-shadow: none;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
  padding-top: 0.5rem;
}

h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.status {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  border-radius: 9999px;
  font-size: 0.9375rem;
  font-weight: 600;
  background: var(--surface-light);
  color: var(--text-muted);
  border: 2px solid var(--border);
  transition: all 0.2s ease;
}

.status-active {
  background: rgba(5, 150, 105, 0.2);
  color: var(--success-light);
  border-color: var(--success);
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
  }
}

.section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex: 1;
  justify-content: center;
  padding: 1rem 0;
}

.hidden {
  display: none !important;
}

.info-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.0625rem;
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

.welcome-text {
  text-align: center;
  font-size: 1.375rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text);
  line-height: 1.4;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.125rem 1.75rem;
  border: none;
  border-radius: 1rem;
  font-size: 1.0625rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  color: var(--text);
  min-height: 56px;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
}

.btn-success:hover:not(:disabled) {
  background: var(--success-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(5, 150, 105, 0.5);
}

.btn-success:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.4);
}

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
}

.btn-door {
  background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
  color: white;
  padding: 3rem 2rem;
  font-size: 1.625rem;
  flex-direction: column;
  gap: 1.25rem;
  border-radius: 1.5rem;
  box-shadow: 0 10px 30px rgba(5, 150, 105, 0.5);
  font-weight: 700;
  letter-spacing: -0.02em;
  min-height: auto;
  position: relative;
  overflow: hidden;
}

.btn-door::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transform: rotate(45deg);
  transition: all 0.6s ease;
}

.btn-door:hover:not(:disabled)::before {
  left: 100%;
}

.btn-door:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--success-dark) 0%, #065f46 100%);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 15px 40px rgba(5, 150, 105, 0.6);
}

.btn-door:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 5px 15px rgba(5, 150, 105, 0.5);
}

.btn-door.loading {
  animation: doorPulse 1.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes doorPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.85;
    transform: scale(0.97);
  }
}

.btn-secondary {
  background: var(--surface-light);
  border: 2px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-text {
  background: transparent;
  color: var(--text-muted);
  padding: 0.875rem 1.25rem;
  min-height: 48px;
  border-radius: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-text:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-light);
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.icon {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.icon-large {
  width: 5rem;
  height: 5rem;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.btn-door:hover:not(:disabled) .icon-large {
  transform: scale(1.1);
}

.message {
  pointer-events: auto;
  box-sizing: border-box;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: rgba(0,0,0,.8);
  backdrop-filter: blur(8px);
  font-size: 0.875rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

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

.message-success {
  background: rgba(5, 150, 105, 0.2);
  color: var(--success-light);
  border: 2px solid var(--success);
}

.message-error {
  background: rgba(82, 29, 29, 0.2);
  color: var(--error);
  border: 2px solid var(--error);
}

.message-info {
  background: rgba(37, 99, 235, 0.2);
  color: var(--primary-light);
  border: 2px solid var(--primary);
}

.table-container {
  overflow-x: auto;
  margin-top: 1rem;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.75rem;
  border: 2px solid var(--border);
  background: var(--bg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th,
td {
  padding: 0.875rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-light);
  position: sticky;
  top: 0;
  z-index: 10;
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: nowrap;
}

.btn-small {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  min-height: 44px;
  border-radius: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-invite {
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-invite:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.btn-delete {
  background: var(--error);
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

.btn-delete:hover {
  background: #b91c1c;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 48px;
}

input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  accent-color: var(--primary);
}

.btn-danger {
  background-color: var(--error);
  color: white;
  border: none;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4);
}

.btn-danger:hover:not(:disabled) {
  background-color: #b91c1c;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(220, 38, 38, 0.5);
}

.btn-danger:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
}

.col-token {
  display: none;
}

html .col-token {
  display: table-cell;
}

.table-empty {
  text-align: center;
  opacity: 0.7;
  padding: 2.5rem 1rem;
  font-size: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

input[type="text"],
input[type="email"] {
  padding: 1.125rem 1.5rem;
  border: 2px solid var(--border);
  border-radius: 1rem;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  min-height: 56px;
  transition: all 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.form-group select {
  width: 100%;
  padding: 1.125rem 1.5rem;
  border: 2px solid var(--border);
  border-radius: 1rem;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  min-height: 56px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 1.5rem) calc(1.125rem + 2px), calc(100% - 1.125rem) calc(1.125rem + 2px);
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
  transition: all 0.2s ease;
  cursor: pointer;
}

.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  background-color: var(--surface);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.form-group select:hover {
  border-color: var(--text-muted);
}

.tabs {
  display: flex;
  justify-content: space-between;
  background: var(--surface-light);
  border-radius: 1rem;
  padding: 0.5rem;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 1rem;
  padding: 1rem 1.25rem;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px;
}

.tabs button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.tabs button.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.switch {
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  user-select: none;
  min-height: 48px;
}

.switch input[type="checkbox"] {
  position: relative;
  width: 3.5rem;
  height: 2rem;
  appearance: none;
  background: var(--surface-light);
  border-radius: 9999px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.switch input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.switch input[type="checkbox"]::before {
  content: "";
  position: absolute;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: white;
  top: 50%;
  left: 0.25rem;
  transform: translateY(-50%);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.switch input[type="checkbox"]:checked::before {
  left: calc(100% - 1.75rem);
}

.switch span {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}

@media (min-width: 640px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .container {
    max-width: 500px;
    min-height: auto;
  }

  .card {
    border-radius: 1.5rem;
    padding: 3rem;
    box-shadow: 0 25px 50px var(--shadow);
  }

  .button-group {
    flex-direction: row;
  }

  .btn-door {
    padding: 3.5rem 2.5rem;
  }

  th,
  td {
    padding: 1.125rem 1rem;
  }

  table {
    font-size: 1rem;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 560px;
  }

  h1 {
    font-size: 2.5rem;
  }

  .btn-door {
    font-size: 1.875rem;
  }

  .icon-large {
    width: 6rem;
    height: 6rem;
  }
}

@media (max-width: 639px) {
  th,
  td {
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
  }

  th {
    font-size: 0.75rem;
  }

  .btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    min-height: 40px;
  }

  .action-buttons {
    gap: 0.375rem;
  }
}

@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .card {
    padding-top: max(1.25rem, calc(env(safe-area-inset-top) + 1.25rem));
    padding-bottom: max(1.25rem, calc(env(safe-area-inset-bottom) + 1.25rem));
  }
}

.btn,
.btn-door,
.icon-large,
.message {
  will-change: transform;
}

*:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
  border-radius: 0.5rem;
}

html {
  scroll-behavior: smooth;
}

.admin-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  background: var(--bg);
}

.admin-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: white;
  border-radius: 0.75rem;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9375rem;
  transition: all 0.2s ease;
  min-height: 44px;
  white-space: nowrap;
}

.btn-back:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.admin-title {
  flex: 1;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  text-align: center;
}

.admin-status {
  display: flex;
  align-items: center;
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.dev-switch-container {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.form-container {
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.users-list-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.user-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

.user-card:hover {
  border-color: var(--primary);
  background: var(--surface-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.user-card-info {
  flex: 1;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 0.375rem;
}

.user-card-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.user-card-role {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.user-card-arrow {
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.user-card:hover .user-card-arrow {
  transform: translateX(4px);
  color: var(--primary);
}

.role-badge {
  display: inline-block;
  padding: 0.375rem 0.875rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--surface-light);
  color: var(--text-muted);
}

.role-badge.role-admin {
  background: rgba(220, 38, 38, 0.2);
  color: var(--error);
}

.role-badge.role-porton {
  background: rgba(37, 99, 235, 0.2);
  color: var(--primary-light);
}

.role-badge.role-user {
  background: rgba(5, 150, 105, 0.2);
  color: var(--success-light);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 1.5rem 1.5rem 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 2px solid var(--border);
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: var(--surface-light);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-muted);
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.user-detail-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-detail-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.user-detail-value {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  font-size: 1rem;
  color: var(--text);
  word-break: break-word;
}

.token-value {
  font-family: "Courier New", monospace;
  font-size: 0.875rem;
}

.token-masked {
  flex: 1;
  letter-spacing: 0.1em;
}

.btn-icon-small {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--surface-light);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn-icon-small:hover {
  background: var(--primary);
  color: white;
}

.icon-small {
  width: 1rem;
  height: 1rem;
}

.modal-footer {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem 1.5rem;
  border-top: 2px solid var(--border);
}

.modal-footer .btn {
  flex: 1;
  min-height: 52px;
}

#usersListContent {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Contenedor global de toasts (se crea si no existe) */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999; /* por encima de modales/headers */
  pointer-events: none; /* no bloquea toques */
}

/* En móviles muy chicos, reducir tamaño */
@media (max-width: 360px) {
  .message { font-size: 13px; padding: 8px 10px; }
}


@media (min-width: 640px) {
  .admin-toolbar {
    padding: 1.25rem 2rem;
  }

  .admin-content {
    padding: 2rem;
  }

  .admin-title {
    font-size: 1.75rem;
  }

  .modal {
    align-items: center;
  }

  .modal-content {
    border-radius: 1.5rem;
    max-height: 90vh;
  }

  .users-list-container {
    max-width: 800px;
    margin: 0 auto;
  }
}

@media (min-width: 768px) {
  .admin-title {
    font-size: 2rem;
  }

  .user-card {
    padding: 1.5rem;
  }

  .user-card-name {
    font-size: 1.25rem;
  }
}
