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

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Segoe UI", Arial, sans-serif;
  background: linear-gradient(135deg, #e7edf7 0%, #f8faff 48%, #e5ebf5 100%);
  color: #222;
}

.card {
  position: relative;
  background: linear-gradient(
    140deg,
    rgba(255, 255, 255, 0.96) 0%,
    rgba(248, 250, 255, 0.94) 55%,
    rgba(235, 241, 250, 0.92) 100%
  );
  width: 340px;
  padding: 40px 50px;
  border-radius: 20px;
  corner-shape: squircle;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  text-align: center;
}

.icon-btn {
  width: 46px;
  height: 46px;
  display: flex;
  position: absolute;
  top: 14px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(223, 223, 223, 0.9);
  corner-shape: squircle;
  border-radius: 20px;
  color: #566579;
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.96),
    rgba(231, 238, 247, 0.78)
  );

  box-shadow:
    0 5px 12px rgba(53, 72, 99, 0.1),
    inset 0 2px 3px rgba(255, 255, 255, 1),
    inset 0 -2px 4px rgba(150, 168, 191, 0.15);
  cursor: pointer;
  transition:
    box-shadow 0.35s ease,
    background 0.35s ease,
    transform 0.35s ease,
    scale 0.35s ease,
    box-shadow 0.35s ease;
}

.icon-btn[hidden] {
  display: none !important;
}

.icon-btn:hover {
  transition:
    box-shadow 0.35s ease,
    background 0.35s ease,
    transform 0.35s ease,
    scale 0.35s ease,
    box-shadow 0.35s ease,
    color 0.35s ease;
  box-shadow: 0px 4px 8px rgba(10, 10, 10, 0.15);
  transform: translateY(-2px);
  scale: calc(105%);
}

.qr-btn {
  left: 14px;
}

.users-btn {
  right: 14px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  background: linear-gradient(145deg, #ffffff 0%, #f8faff 60%, #edf2f9 100%);
  padding: 28px 32px;
  border-radius: 20px;
  corner-shape: squircle;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.modal h2 {
  font-size: 1.2rem;
  margin-bottom: 18px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: none;
  background: none;
  font-size: 1.5rem;
  color: #888;
  cursor: pointer;
}

.modal-close:hover {
  color: #222;
}

.qr-box {
  width: 256px;
  height: 256px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #ccc;
  border-radius: 20px;
  corner-shape: squircle;
  color: #aaa;
  font-size: 0.9rem;
}

.qr-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.qr-box svg {
  width: 100%;
  height: 100%;
  border-radius: 20px;
  corner-shape: squircle;
}

.qr-url {
  padding: 12px;
  font-size: 0.75rem;
  color: #444;
  word-break: break-all;
  user-select: all;
}

.qr-refresh {
  width: 100%;
  margin-top: 18px;
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  corner-shape: squircle;
  background: #4a90d9;
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.qr-refresh:hover {
  background: #357abd;
}

/* Modal de confirmación */
.confirm-text {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.5;
  margin-bottom: 22px;
  max-width: 260px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border: none;
  border-radius: 20px;
  corner-shape: squircle;
  font-size: 0.9rem;
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s;
}

.btn-primary {
  background: #4a90d9;
  color: #fff;
}

.btn-primary:hover {
  background: #357abd;
}

.btn-secondary {
  background: #eef1f5;
  color: #555;
}

.btn-secondary:hover {
  background: #e0e4ea;
}

/* Toast de notificación (centrado, rojo claro semitransparente) */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 100;
  max-width: 320px;
  padding: 16px 22px;
  border-radius: 20px;
  corner-shape: squircle;
  background: rgba(255, 143, 143, 0.88);
  border: 1px solid rgba(183, 28, 28, 0.4);
  color: #7f1010;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s,
    transform 0.25s;
}

.toast[hidden] {
  display: none;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Modal de usuarios */
.users-count {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 12px;
  flex-shrink: 0;
}

#usersModal .modal {
  display: flex;
  flex-direction: column;
  width: 340px;
  height: 420px;
  max-height: 80vh;
}

.users-list {
  list-style: none;
  min-width: 280px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  text-align: left;
}

.users-limit {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}

.users-limit-label {
  font-size: 0.8rem;
  color: #888;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: #eef1f5;
  border-radius: 20px;
  corner-shape: squircle;
}

.stepper-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 20px;
  corner-shape: squircle;
  background: transparent;
  color: #4a90d9;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s;
}

.stepper-btn:hover {
  background: #4a90d9;
  color: #fff;
}

.stepper-btn:disabled {
  background: transparent;
  color: #bbb;
  cursor: not-allowed;
}

.stepper-value {
  width: 40px;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #333;
  appearance: textfield;
  -moz-appearance: textfield;
}

.stepper-value:focus {
  outline: none;
}

.stepper-value::-webkit-outer-spin-button,
.stepper-value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

.user-item:last-child {
  border-bottom: none;
}

.user-id {
  flex: 1;
  font-family: monospace;
  font-size: 0.8rem;
  color: #444;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 0.7rem;
  font-weight: 600;
  background: #eef1f5;
  color: #555;
  border-radius: 20px;
  corner-shape: squircle;
  padding: 2px 8px;
}

.user-delete {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 20px;
  corner-shape: squircle;
  background: #fdecea;
  color: #c0392b;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s;
}

.user-delete:hover {
  background: #d94a4a;
  color: #fff;
}

.user-delete:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.users-empty {
  color: #aaa;
  font-size: 0.9rem;
  padding: 12px 0;
  text-align: center;
}

h1 {
  font-size: 1.5rem;
  margin-bottom: 24px;
}

/* Botón LED: gris claro = OFF, verde claro = ON */
.led-btn {
  width: 140px;
  height: 140px;
  border-radius: 50% / 50%;
  margin-bottom: 28px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  font-size: 1.4rem;
  font-weight: bold;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition:
    background 0.25s,
    box-shadow 0.25s,
    transform 0.1s;
}

.led-btn.off {
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(226, 233, 243, 0.88) 45%,
    rgba(190, 202, 219, 0.78) 100%
  );
  color: #526176;
  box-shadow:
    inset 0 3px 5px rgba(255, 255, 255, 0.95),
    inset 0 -6px 12px rgba(113, 132, 158, 0.22),
    0 8px 20px rgba(68, 87, 116, 0.18),
    0 2px 4px rgba(255, 255, 255, 0.8);
}

.led-btn.on {
  background: linear-gradient(
    145deg,
    rgba(235, 255, 238, 0.98) 0%,
    rgba(144, 238, 144, 0.9) 48%,
    rgba(76, 201, 112, 0.82) 100%
  );
  color: #17652c;
  border-color: rgba(255, 255, 255, 0.85);
  box-shadow:
    inset 0 3px 6px rgba(255, 255, 255, 0.95),
    inset 0 -6px 12px rgba(27, 120, 59, 0.18),
    0 0 24px rgba(105, 235, 137, 0.48),
    0 8px 20px rgba(45, 150, 78, 0.2);
}

.led-btn:active {
  transform: scale(0.96);
}
.connect-btn {
  width: 100%;
  padding: 12px 24px;
  border: none;
  border-radius: 20px;
  corner-shape: squircle;
  background: #4a90d9;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.connect-btn:hover {
  background: #357abd;
}

.connect-btn.connected {
  background: #d94a4a;
}

.connect-btn.connected:hover {
  background: #c0392b;
}

.status {
  margin-top: 14px;
  font-size: 0.9rem;
  color: #888;
}

/* Modo oscuro automático según preferencia del sistema */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #0f1622 0%, #141d2b 48%, #0d141f 100%);
    color: #e6ebf2;
  }

  .card {
    background: linear-gradient(
      140deg,
      rgba(30, 40, 57, 0.96) 0%,
      rgba(24, 33, 48, 0.94) 55%,
      rgba(19, 27, 40, 0.92) 100%
    );
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }

  .icon-btn {
    border: 1px solid rgba(70, 84, 106, 0.9);
    color: #a9b6c9;
    background: linear-gradient(
      145deg,
      rgba(46, 58, 78, 0.96),
      rgba(30, 40, 56, 0.78)
    );
    box-shadow:
      0 5px 12px rgba(0, 0, 0, 0.35),
      inset 0 2px 3px rgba(255, 255, 255, 0.06),
      inset 0 -2px 4px rgba(0, 0, 0, 0.3);
  }

  .icon-btn:hover {
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5);
  }

  .modal {
    background: linear-gradient(145deg, #202b3d 0%, #1a2333 60%, #151d2b 100%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  }

  .modal-close {
    color: #7a8699;
  }

  .modal-close:hover {
    color: #f0f3f8;
  }

  .qr-box {
    border-color: #3b4658;
    color: #6b7688;
  }

  .qr-url {
    color: #c3cbd8;
  }

  .confirm-text {
    color: #a9b6c9;
  }

  .btn-secondary {
    background: #2a3547;
    color: #c3cbd8;
  }

  .btn-secondary:hover {
    background: #34415a;
  }

  .toast {
    background: rgba(150, 52, 52, 0.9);
    border: 1px solid rgba(220, 96, 96, 0.5);
    color: #ffe2e2;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  }

  .users-count {
    color: #8b96a8;
  }

  .users-limit {
    border-top: 1px solid #2c3748;
  }

  .users-limit-label {
    color: #8b96a8;
  }

  .stepper {
    background: #2a3547;
  }

  .stepper-btn {
    color: #6aa9e6;
  }

  .stepper-btn:hover {
    background: #4a90d9;
    color: #fff;
  }

  .stepper-btn:disabled {
    color: #566173;
  }

  .stepper-value {
    color: #e6ebf2;
  }

  .user-item {
    border-bottom: 1px solid #2c3748;
  }

  .user-id {
    color: #c3cbd8;
  }

  .user-role {
    background: #2a3547;
    color: #c3cbd8;
  }

  .user-delete {
    background: #3a2526;
    color: #f08a80;
  }

  .users-empty {
    color: #6b7688;
  }

  .led-btn.off {
    border: 1px solid rgba(120, 135, 158, 0.4);
    background: linear-gradient(
      145deg,
      rgba(52, 63, 82, 0.95) 0%,
      rgba(37, 46, 62, 0.88) 45%,
      rgba(26, 33, 46, 0.78) 100%
    );
    color: #a9b6c9;
    box-shadow:
      inset 0 3px 5px rgba(255, 255, 255, 0.06),
      inset 0 -6px 12px rgba(0, 0, 0, 0.4),
      0 8px 20px rgba(0, 0, 0, 0.45),
      0 2px 4px rgba(255, 255, 255, 0.04);
  }

  .led-btn.on {
    background: linear-gradient(
      145deg,
      rgba(60, 130, 82, 0.98) 0%,
      rgba(46, 150, 88, 0.9) 48%,
      rgba(34, 120, 68, 0.85) 100%
    );
    color: #d7ffe2;
    border-color: rgba(120, 220, 150, 0.5);
    box-shadow:
      inset 0 3px 6px rgba(255, 255, 255, 0.1),
      inset 0 -6px 12px rgba(0, 0, 0, 0.3),
      0 0 24px rgba(90, 220, 130, 0.4),
      0 8px 20px rgba(0, 0, 0, 0.45);
  }

  .status {
    color: #8b96a8;
  }
}
