/* =========================
   Tema moderno para Control IoT — Movimientos
   - Compatible con Bootstrap 5
   - Dark/Light auto por prefers-color-scheme
   - Glassmorphism suave, transiciones sutiles
   ========================= */

/* Reset básico */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  /* Paleta (modo oscuro por defecto) */
  --bg: hsl(240 10% 6%);
  --surface: hsl(240 14% 12% / 72%);
  --surface-strong: hsl(240 14% 12% / 92%);
  --border: hsl(240 10% 20% / 60%);
  --text: hsl(0 0% 98%);
  --muted: hsl(240 5% 70%);
  --primary: hsl(222 90% 56%);
  --primary-600: hsl(222 90% 52%);
  --primary-700: hsl(222 90% 48%);
  --success: hsl(150 70% 45%);
  --warning: hsl(42 95% 55%);
  --danger: hsl(0 85% 60%);
  --card-radius: 16px;
  --tile-radius: 14px;
  --shadow-lg: 0 10px 30px hsl(240 50% 2% / 35%);
  --shadow-md: 0 8px 20px hsl(240 50% 2% / 25%);
  --shadow-sm: 0 6px 12px hsl(240 50% 2% / 18%);
  --blur: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: hsl(0 0% 98%);
    --surface: hsl(0 0% 100% / 80%);
    --surface-strong: hsl(0 0% 100% / 96%);
    --border: hsl(240 6% 90% / 80%);
    --text: hsl(240 10% 12%);
    --muted: hsl(240 6% 40%);
    --primary: hsl(222 85% 55%);
    --primary-600: hsl(222 85% 52%);
    --primary-700: hsl(222 85% 48%);
    --success: hsl(150 60% 38%);
    --warning: hsl(42 95% 48%);
    --danger: hsl(0 75% 52%);
    --shadow-lg: 0 10px 30px hsl(240 20% 40% / 18%);
    --shadow-md: 0 8px 20px hsl(240 20% 40% / 14%);
    --shadow-sm: 0 6px 12px hsl(240 20% 40% / 10%);
  }
}

/* Fondo con gradiente sutil y patrón */
html, body {
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 800px at 85% -10%, hsl(222 90% 56% / 7%), transparent 60%),
    radial-gradient(1000px 700px at -10% 20%, hsl(280 85% 60% / 7%), transparent 55%),
    linear-gradient(180deg, hsl(240 10% 7%), var(--bg));
  color: var(--text);
}

/* Navbar glass */
.navbar {
  background: linear-gradient(180deg, hsl(240 14% 12% / 85%), hsl(240 14% 12% / 65%)) !important;
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.navbar .navbar-brand {
  letter-spacing: .2px;
}

/* Container ancho cómodo */
@media (min-width: 1200px) {
  .container {
    max-width: 1120px;
  }
}

/* Tarjetas base (incluye card de “Último estado”) */
.card {
  background: var(--surface);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease, background .25s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: hsl(222 85% 56% / 35%);
}

/* Títulos de sección */
main section > h5 {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
}

main section > h5::after {
  content: "";
  display: inline-block;
  height: 8px;
  width: 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), hsl(280 85% 60%));
  box-shadow: 0 0 0 4px hsl(222 85% 56% / 15%);
}

/* Formularios */
.form-label {
  color: var(--muted);
  font-weight: 600;
}

.form-control {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 hsl(0 0% 100% / 4%);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease, transform .04s ease;
}

.form-control::placeholder {
  color: hsl(240 5% 60%);
}

.form-control:focus {
  border-color: hsl(222 85% 56% / 55%);
  box-shadow:
    0 0 0 .2rem hsl(222 85% 56% / 15%),
    0 10px 20px -12px hsl(222 85% 56% / 25%);
  background: var(--surface-strong);
  color: var(--text);
}

/* Botones */
.btn {
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: .2px;
  transition: transform .08s ease, box-shadow .2s ease, background .2s ease, color .2s ease, border-color .2s ease;
}

.btn:active {
  transform: translateY(1px) scale(.99);
}

.btn-primary,
.btn-outline-primary:hover {
  background: linear-gradient(180deg, var(--primary), var(--primary-700));
  border-color: var(--primary-600);
  color: white;
  box-shadow: 0 10px 20px -10px hsl(222 85% 56% / 45%);
}

.btn-outline-primary {
  color: var(--primary);
  border-color: hsl(222 85% 56% / 55%);
  background: transparent;
}

.btn-outline-primary:active {
  color: white;
}

/* Badges de estado (para #lastStatusBadge) */
#lastStatusBadge.badge {
  font-weight: 700;
  letter-spacing: .3px;
  padding: .5rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
}

#lastStatusBadge.status-ok {
  color: hsl(150 70% 20%);
  background: hsl(150 70% 45% / 18%);
  border-color: hsl(150 70% 45% / 35%);
}

#lastStatusBadge.status-warn {
  color: hsl(42 90% 18%);
  background: hsl(42 95% 55% / 18%);
  border-color: hsl(42 95% 55% / 35%);
}

#lastStatusBadge.status-error {
  color: hsl(0 85% 22%);
  background: hsl(0 85% 60% / 18%);
  border-color: hsl(0 85% 60% / 35%);
}

/* Movimientos: tiles bonitos (útil si los hijos de #movesGrid son columnas con botones o tarjetas) */
#movesGrid .col,
#movesGrid [class*="col-"] {
  display: flex;
}

.move-tile {
  flex: 1 1 auto;
  background: var(--surface);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--tile-radius);
  padding: 1rem 1.1rem;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: .9rem;
  align-items: center;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .2s ease, border-color .2s ease, background .2s ease;
}

.move-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: hsl(222 85% 56% / 35%);
}

.move-tile:active {
  transform: translateY(0);
}

.move-icon {
  height: 40px;
  width: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), hsl(280 85% 60%));
  color: white;
  font-weight: 800;
  box-shadow: 0 8px 18px -10px hsl(222 85% 56% / 55%);
}

.move-title {
  font-weight: 700;
  line-height: 1.1;
}

.move-sub {
  font-size: .85rem;
  color: var(--muted);
}

.move-cta .btn {
  padding: .45rem .75rem;
}

/* Mensajería */
#msgArea .alert {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
}

/* Tabla “Últimos estatus” */
.table-responsive {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table {
  margin: 0;
  color: var(--text);
}

.table thead.table-light th {
  background: linear-gradient(180deg, hsl(240 14% 16% / 80%), hsl(240 14% 14% / 80%));
  color: hsl(0 0% 98%);
  border-bottom-color: var(--border);
}

@media (prefers-color-scheme: light) {
  .table thead.table-light th {
    background: linear-gradient(180deg, hsl(0 0% 100%), hsl(0 0% 98%));
    color: hsl(240 10% 12%);
  }
}

.table tbody tr {
  transition: background-color .15s ease;
}

.table tbody tr:nth-child(even) {
  background: hsl(240 14% 12% / 35%);
}

@media (prefers-color-scheme: light) {
  .table tbody tr:nth-child(even) {
    background: hsl(240 6% 96%);
  }
}

.table-hover > tbody > tr:hover > * {
  background: hsl(222 85% 56% / 10%) !important;
}

.table td, .table th {
  border-top-color: var(--border) !important;
}

/* Cabecera sticky dentro del contenedor responsivo */
.table-responsive thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Micro-interacciones */
.fade-in {
  animation: fadeIn .3s ease both;
}

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

/* Accesibilidad: foco visible y reducción de movimiento */
:focus-visible {
  outline: 2px solid hsl(222 85% 56% / 70%);
  outline-offset: 2px;
  border-radius: 10px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Utilidades pequeñas */
.text-muted {
  color: var(--muted) !important;
}