/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --color-primary:      #1a56db;
  --color-primary-dark: #1e429f;
  --color-primary-light:#eff3fe;
  --color-accent:       #0ea5e9;
  --color-success:      #16a34a;
  --color-success-bg:   #f0fdf4;
  --color-warning:      #d97706;
  --color-warning-bg:   #fffbeb;
  --color-danger:       #dc2626;
  --color-danger-bg:    #fef2f2;
  --color-neutral-50:   #f9fafb;
  --color-neutral-100:  #f3f4f6;
  --color-neutral-200:  #e5e7eb;
  --color-neutral-300:  #d1d5db;
  --color-neutral-400:  #9ca3af;
  --color-neutral-500:  #6b7280;
  --color-neutral-600:  #4b5563;
  --color-neutral-700:  #374151;
  --color-neutral-900:  #111827;
  --color-surface:      #ffffff;
  --color-bg:           #f3f4f6;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --text-xs:   .75rem;
  --text-sm:   .875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);

  --sidebar-w: 240px;
  --header-h:  60px;
  --transition: .15s ease;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-neutral-700);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
input, button, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  padding: 1rem;
}
.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}
.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo img { height: 48px; margin: 0 auto .75rem; }
.login-logo h1 { font-size: var(--text-xl); font-weight: 700; color: var(--color-neutral-900); }
.login-logo p  { font-size: var(--text-sm); color: var(--color-neutral-500); margin-top: .25rem; }

/* ── App Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-neutral-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-left { display: flex; align-items: center; gap: .75rem; }
.header-logo { height: 32px; }
.header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-neutral-900);
}
.header-title span { color: var(--color-neutral-400); font-weight: 400; font-size: var(--text-base); }
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: .4rem;
  color: var(--color-neutral-600);
  border-radius: var(--radius-sm);
}
.hamburger:hover { background: var(--color-neutral-100); }
.header-right { display: flex; align-items: center; gap: .625rem; }

/* ── Avatar de usuario con dropdown ───────────────────────────────────────── */
.user-menu { position: relative; }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s;
  flex-shrink: 0;
}
.user-avatar:hover { opacity: .85; }

.user-dropdown {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-neutral-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
}
.user-dropdown-name {
  padding: .625rem .875rem .5rem;
  font-size: var(--text-xs);
  color: var(--color-neutral-500);
  font-weight: 500;
  max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-dropdown-divider { height: 1px; background: var(--color-neutral-100); margin: .25rem 0; }
.user-dropdown-item {
  display: flex; align-items: center; gap: .5rem;
  width: 100%; padding: .5rem .875rem;
  font-size: var(--text-sm); color: var(--color-neutral-700);
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background .12s;
}
.user-dropdown-item:hover { background: var(--color-neutral-50); }
.user-dropdown-item--danger { color: var(--color-danger); }
.user-dropdown-item--danger:hover { background: #fff5f5; }
.user-dropdown-icon { font-size: .9rem; width: 1.1rem; text-align: center; flex-shrink: 0; }

/* ── Indicador de fortaleza de contraseña ──────────────────────────────────── */
.password-strength { display: flex; align-items: center; gap: .5rem; }
.password-strength-bar {
  flex: 1; height: 4px; border-radius: 99px;
  background: var(--color-neutral-200);
  position: relative; overflow: hidden;
}
.password-strength-bar::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 99px;
  width: var(--strength, 0%);
  background: var(--strength-color, var(--color-neutral-300));
  transition: width .3s, background .3s;
}
.password-strength-label { font-size: 10px; color: var(--color-neutral-500); white-space: nowrap; }

/* ── Body layout ───────────────────────────────────────────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-neutral-200);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform var(--transition);
  /* Por encima del stacking context que crea Leaflet en su mapa */
  position: relative;
  z-index: 50;
}
.sidebar-section { padding: .75rem .75rem .25rem; }
.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-neutral-400);
  padding: .25rem .5rem;
  margin-bottom: .25rem;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  color: var(--color-neutral-600);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.nav-link:hover { background: var(--color-neutral-100); color: var(--color-neutral-900); text-decoration: none; }
.nav-link.active { background: var(--color-primary-light); color: var(--color-primary); }
.nav-link .icon { font-size: 1.1rem; flex-shrink: 0; }
.sidebar-divider { height: 1px; background: var(--color-neutral-200); margin: .5rem .75rem; }
.sidebar-bottom { margin-top: auto; padding: .75rem; }

/* ── Main content ──────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  min-width: 0;
}
.view { display: none; }
.view.active { display: block; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.page-title { font-size: var(--text-2xl); font-weight: 700; color: var(--color-neutral-900); }
.page-subtitle { font-size: var(--text-sm); color: var(--color-neutral-500); margin-top: .2rem; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-neutral-200);
  padding: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-title { font-size: var(--text-base); font-weight: 600; color: var(--color-neutral-900); }

/* ── Stat cards ────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-neutral-200);
  padding: 1.25rem 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-value { font-size: var(--text-3xl); font-weight: 800; color: var(--color-neutral-900); }
.stat-label { font-size: var(--text-xs); color: var(--color-neutral-500); margin-top: .25rem; text-transform: uppercase; letter-spacing: .05em; }
.stat-card.stat-online .stat-value  { color: var(--color-success); }
.stat-card.stat-offline .stat-value { color: var(--color-danger); }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-online  { background: var(--color-success-bg); color: var(--color-success); }
.badge-online::before  { background: var(--color-success); }
.badge-offline { background: var(--color-danger-bg);  color: var(--color-danger);  }
.badge-offline::before { background: var(--color-danger); }
.badge-warn    { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-warn::before    { background: var(--color-warning); }
.badge-neutral { background: var(--color-neutral-100); color: var(--color-neutral-500); }
.badge-neutral::before { background: var(--color-neutral-400); }

/* ── Device list ───────────────────────────────────────────────────────────── */
.device-list { display: flex; flex-direction: column; gap: .75rem; }
.device-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .875rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-neutral-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.device-row:hover { border-color: var(--color-primary); box-shadow: var(--shadow); }
.device-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.device-status-dot.online  { background: var(--color-success); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.device-status-dot.offline { background: var(--color-danger); }
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 600; color: var(--color-neutral-900); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-meta { font-size: var(--text-xs); color: var(--color-neutral-400); margin-top: .15rem; }
.device-right { display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.device-fw { font-size: var(--text-xs); color: var(--color-neutral-400); font-family: var(--font-mono); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: var(--text-sm); font-weight: 500; color: var(--color-neutral-700); margin-bottom: .4rem; }
.form-help { font-size: var(--text-xs); color: var(--color-neutral-500); margin-top: .35rem; }
.form-input, .form-textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--color-neutral-300);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--color-neutral-900);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus, .form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover:not(:disabled)  { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-secondary { background: var(--color-neutral-100); color: var(--color-neutral-700); border-color: var(--color-neutral-200); }
.btn-secondary:hover:not(:disabled) { background: var(--color-neutral-200); }
.btn-danger   { background: var(--color-danger-bg); color: var(--color-danger); border-color: #fca5a5; }
.btn-danger:hover:not(:disabled)  { background: #fee2e2; }
.btn-ghost    { background: none; color: var(--color-neutral-600); border-color: transparent; }
.btn-ghost:hover:not(:disabled)   { background: var(--color-neutral-100); }
.btn-sm  { padding: .3rem .65rem;  font-size: var(--text-xs); }
.btn-xs  { padding: .2rem .5rem;   font-size: 11px; }
.btn-full { width: 100%; }
.btn .btn-spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }

/* ── Skeleton ──────────────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--color-neutral-100) 25%, var(--color-neutral-200) 50%, var(--color-neutral-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius);
}
.skeleton-text  { height: .9em; margin-bottom: .4em; }
.skeleton-badge { height: 22px; width: 60px; border-radius: 99px; }
.skeleton-row   { height: 64px; border-radius: var(--radius-lg); margin-bottom: .75rem; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: slideIn .2s ease;
  max-width: 360px;
}
.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error   { background: #fef2f2; color: #7f1d1d; border: 1px solid #fca5a5; }
.toast-info    { background: #eff6ff; color: #1e3a8a; border: 1px solid #bfdbfe; }
.toast-icon { font-size: 1rem; flex-shrink: 0; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 440px;
  animation: scaleIn .15s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; gap: .5rem; }
.modal-title  { font-size: var(--text-xl); font-weight: 700; color: var(--color-neutral-900); margin: 0; }
.modal-close  {
  flex-shrink: 0;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none; border-radius: 50%;
  color: var(--color-neutral-400); font-size: 1rem; cursor: pointer;
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--color-neutral-100); color: var(--color-neutral-700); }
.modal-body   { font-size: var(--text-sm); color: var(--color-neutral-600); margin-bottom: 1.5rem; line-height: 1.6; }
.modal-footer { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.25rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; }

/* ── Dashboard nativo ──────────────────────────────────────────────────────── */

/* Cuando el dashboard está activo, app-main cede el padding y overflow */
.app-main.dashboard-mode {
  padding: 0;
  overflow: hidden;
}
/* El view del dashboard debe ocupar toda la altura disponible */
.app-main.dashboard-mode #view-overview {
  height: 100%;
}

.dashboard-layout {
  display: flex;
  height: 100%;   /* hereda del view que hereda de app-main en dashboard-mode */
  overflow: hidden;
}

/* Mapa — cadena flex correcta para que #dashboard-map tenga altura real */
.map-container {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  /* isolation: isolate crea un stacking context propio que contiene los
     z-index internos de Leaflet (200-700), evitando que cubran el sidebar */
  isolation: isolate;
}
#dashboard-map {
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--color-neutral-100);
}

/* Marcadores custom Leaflet */
.device-marker {
  width: 28px; height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  cursor: pointer;
  transition: transform .15s;
}
.device-marker:hover { transform: rotate(-45deg) scale(1.15); }
.device-marker.online  { background: var(--color-success); }
.device-marker.offline { background: var(--color-danger); }
.device-marker.selected { transform: rotate(-45deg) scale(1.2); box-shadow: 0 0 0 4px rgba(26,86,219,.3), 0 2px 8px rgba(0,0,0,.3); }

/* Panel lateral de dispositivos */
.device-panel {
  width: 320px;
  min-width: 280px;
  min-height: 0;
  background: var(--color-surface);
  border-left: 1px solid var(--color-neutral-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.device-panel-head {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--color-neutral-200);
  flex-shrink: 0;
}
.device-panel-stats {
  display: flex;
  gap: .5rem;
  margin-bottom: .625rem;
}
.mini-stat {
  flex: 1;
  text-align: center;
  padding: .4rem .25rem;
  border-radius: var(--radius);
  background: var(--color-neutral-50);
}
.mini-stat-val { font-size: var(--text-lg); font-weight: 800; color: var(--color-neutral-900); }
.mini-stat-lbl { font-size: 10px; color: var(--color-neutral-400); text-transform: uppercase; letter-spacing:.04em; }
.mini-stat.s-online  .mini-stat-val { color: var(--color-success); }
.mini-stat.s-offline .mini-stat-val { color: var(--color-danger); }
.search-input {
  width: 100%;
  padding: .4rem .625rem;
  border: 1px solid var(--color-neutral-200);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  background: var(--color-neutral-50);
  outline: none;
}
.search-input:focus { border-color: var(--color-primary); background: #fff; }

.device-panel-list { flex: 1; overflow-y: auto; padding: .5rem; }
.device-item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .625rem .75rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: .25rem;
}
.device-item:hover { background: var(--color-neutral-100); }
.device-item.selected { background: var(--color-primary-light); }
.device-item .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.device-item .dot.online  { background: var(--color-success); box-shadow: 0 0 0 2px rgba(22,163,74,.2); }
.device-item .dot.offline { background: var(--color-danger); }
.device-item-info { flex: 1; min-width: 0; }
.device-item-name { font-size: var(--text-sm); font-weight: 600; color: var(--color-neutral-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-item-sub  { font-size: var(--text-xs); color: var(--color-neutral-400); margin-top: 1px; }
.device-item-hours { font-size: var(--text-xs); font-weight: 700; color: var(--color-neutral-600); flex-shrink: 0; }

/* Panel de detalle (deslizable desde abajo del mapa) */
.detail-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;   /* cubre solo el map-container, no el device-panel */
  background: var(--color-surface);
  border-top: 1px solid var(--color-neutral-200);
  border-right: 1px solid var(--color-neutral-200);
  max-height: 48%;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .25s ease;
  z-index: 500;
  box-shadow: 0 -4px 20px rgba(0,0,0,.1);
}
.detail-panel.open { transform: none; }
.detail-panel-inner { padding: 1rem 1.25rem; }
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .875rem;
}
.detail-title { font-size: var(--text-lg); font-weight: 700; color: var(--color-neutral-900); }
.detail-close {
  background: none; border: none; cursor: pointer;
  color: var(--color-neutral-400); font-size: 1.25rem; padding: .2rem .4rem;
  border-radius: var(--radius-sm); line-height: 1;
}
.detail-close:hover { background: var(--color-neutral-100); color: var(--color-neutral-700); }

.detail-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
  margin-bottom: 1rem;
}
.kpi-card {
  background: var(--color-neutral-50);
  border: 1px solid var(--color-neutral-200);
  border-radius: var(--radius);
  padding: .75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.kpi-card:hover { border-color: var(--color-primary); background: #eff6ff; }
.kpi-card.active { border-color: var(--color-primary); background: #eff6ff; box-shadow: 0 0 0 1px var(--color-primary); }
.kpi-value { font-size: var(--text-2xl); font-weight: 800; color: var(--color-primary); }
.kpi-label { font-size: var(--text-xs); color: var(--color-neutral-500); margin-top: .2rem; text-transform: uppercase; letter-spacing: .04em; }

.detail-bottom {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.detail-section-title { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--color-neutral-500); margin-bottom: .5rem; }

/* Barras de máquinas */
.machine-bars { display: flex; flex-direction: column; gap: .4rem; }
.machine-bar-row { display: flex; align-items: center; gap: .5rem; font-size: var(--text-xs); }
.machine-bar-label { width: 24px; color: var(--color-neutral-500); flex-shrink: 0; text-align: right; }
.machine-bar-track { flex: 1; height: 8px; background: var(--color-neutral-200); border-radius: 99px; overflow: hidden; }
.machine-bar-fill  { height: 100%; background: var(--color-primary); border-radius: 99px; min-width: 2px; transition: width .4s ease; }
.machine-bar-val   { width: 36px; text-align: right; color: var(--color-neutral-600); font-weight: 600; }

/* Chart container — tendencia 30d */
.chart-container { position: relative; height: 90px; }

/* Doughnut máquinas */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.donut-canvas-wrap {
  position: relative;
  width: 110px;
  height: 110px;
  flex-shrink: 0;
}
.donut-canvas-wrap canvas { width: 100%; height: 100%; display: block; }
.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.donut-center-val  { font-size: var(--text-sm); font-weight: 800; color: var(--color-neutral-900); line-height: 1; }
.donut-center-lbl  { font-size: 9px; color: var(--color-neutral-400); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }
.donut-legend { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.donut-legend-item { display: flex; align-items: center; gap: .4rem; font-size: var(--text-xs); }
.donut-legend-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.donut-legend-name { color: var(--color-neutral-600); flex-shrink: 0; }
.donut-legend-val  { color: var(--color-neutral-900); font-weight: 600; margin-left: auto; padding-left: .5rem; }

/* Panel de gestión de dispositivo (admin, dentro del detail panel) */
.mgmt-section {
  margin-top: .875rem;
  border-top: 1px solid var(--color-neutral-200);
  padding-top: .875rem;
}
.mgmt-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-neutral-600);
  padding: 0;
  width: 100%;
  text-align: left;
}
.mgmt-toggle:hover { color: var(--color-neutral-900); }
.mgmt-toggle .chevron { font-size: .75rem; transition: transform .2s; }
.mgmt-toggle.open .chevron { transform: rotate(90deg); }
.mgmt-body { display: none; padding-top: .75rem; }
.mgmt-body.open { display: block; }
.mgmt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .625rem; }
.mgmt-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }

/* Tabla de cierres mensuales */
.closures-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}
.closures-table th {
  text-align: left;
  color: var(--color-neutral-400);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .25rem .4rem;
  border-bottom: 1px solid var(--color-neutral-200);
}
.closures-table td {
  padding: .3rem .4rem;
  color: var(--color-neutral-700);
  border-bottom: 1px solid var(--color-neutral-100);
  white-space: nowrap;
}
.closures-table tr:last-child td { border-bottom: none; }
.closures-table td:last-child { font-weight: 700; color: var(--color-primary); text-align: right; }
.closures-table .empty-row td { color: var(--color-neutral-400); font-style: italic; text-align: center; }

/* ── Device Vitals card ─────────────────────────────────────────────────────── */
.vitals-card {
  background: var(--color-neutral-50);
  border: 1px solid var(--color-neutral-200);
  border-radius: 8px;
  padding: .625rem .75rem;
  margin-bottom: .75rem;
}
.vitals-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-neutral-400);
  margin-bottom: .5rem;
}
.vitals-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .5rem;
  margin-bottom: .5rem;
}
.vitals-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
}
.vitals-metric-label {
  font-size: 9px;
  color: var(--color-neutral-400);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.vitals-metric-val {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-neutral-700);
}
/* Signal bars */
.signal-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
}
.signal-bar {
  width: 5px;
  border-radius: 1px;
  background: var(--color-neutral-200);
  transition: background .3s;
}
.signal-bar:nth-child(1) { height: 4px; }
.signal-bar:nth-child(2) { height: 8px; }
.signal-bar:nth-child(3) { height: 12px; }
.signal-bar:nth-child(4) { height: 18px; }
.signal-bar.active-good    { background: var(--color-success); }
.signal-bar.active-fair    { background: var(--color-warning); }
.signal-bar.active-poor    { background: var(--color-danger); }
/* Heap bar */
.heap-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--color-neutral-200);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 2px;
}
.heap-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .5s ease;
}
/* Info chips */
.vitals-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .4rem;
  padding-top: .4rem;
  border-top: 1px solid var(--color-neutral-200);
}
.vitals-chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: 9px;
  color: var(--color-neutral-600);
  background: var(--color-surface);
  border: 1px solid var(--color-neutral-200);
  border-radius: 4px;
  padding: .15rem .35rem;
  white-space: nowrap;
}
.vitals-chip-label { color: var(--color-neutral-400); font-weight: 600; }
@keyframes pulse-dot { 0%,100%{opacity:1;} 50%{opacity:.3;} }
.vitals-live-dot {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--color-success);
  border-radius: 50%;
  margin-right: .3rem;
  animation: pulse-dot 2s infinite;
}

/* ── Device logs ────────────────────────────────────────────────────────────── */
.log-sub-toggle {
  display: flex; align-items: center; gap: .4rem;
  background: none; border: none; cursor: pointer;
  font-size: var(--text-xs); font-weight: 600;
  color: var(--color-neutral-600); padding: .25rem 0; width: 100%; text-align: left;
}
.log-sub-toggle:hover { color: var(--color-neutral-900); }
.log-sub-toggle .log-chevron { font-size: .7rem; transition: transform .2s; }
.log-sub-toggle.open .log-chevron { transform: rotate(90deg); }
.log-filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .4rem; align-items: center; }
.log-filter-label {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: 10px; color: var(--color-neutral-600); cursor: pointer; user-select: none;
}
.log-filter-label input[type=checkbox] { width: 12px; height: 12px; cursor: pointer; }
.log-info-icon {
  font-size: 10px; color: var(--color-neutral-400); cursor: help;
  border: 1px solid var(--color-neutral-300); border-radius: 50%;
  width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center;
  line-height: 1;
}
.log-info-icon:hover { color: var(--color-primary); border-color: var(--color-primary); }
.log-list {
  font-family: monospace; font-size: 10px; line-height: 1.5;
  max-height: 180px; overflow-y: auto;
  background: var(--color-neutral-50); border: 1px solid var(--color-neutral-200);
  border-radius: 6px; padding: .35rem .5rem;
}
.log-entry { padding: .1rem 0; border-bottom: 1px solid var(--color-neutral-100); display: flex; gap: .4rem; }
.log-entry:last-child { border-bottom: none; }
.log-ts { color: var(--color-neutral-400); white-space: nowrap; flex-shrink: 0; }
.log-text-hb    { color: var(--color-neutral-500); }
.log-text-ota   { color: #2563eb; }
.log-text-rpc   { color: #7c3aed; }
.log-text-other { color: var(--color-neutral-700); }

/* ── Danger zone (borrar dispositivo) ──────────────────────────────────────── */
.mgmt-danger-zone {
  margin-top: 1rem;
  padding-top: .75rem;
  border-top: 1px solid var(--color-danger-bg);
}
.btn-full { width: 100%; }

/* ── App loading overlay ────────────────────────────────────────────────────── */
#app-loading {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--color-surface);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.5rem;
  transition: opacity .3s ease;
}
#app-loading.fade-out { opacity: 0; pointer-events: none; }
.app-loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--color-neutral-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
#app-loading img { width: 72px; opacity: .85; }

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes shimmer  { to { background-position: -200% 0; } }
@keyframes slideIn  { from { opacity: 0; transform: translateX(1rem); } to { opacity: 1; transform: none; } }
@keyframes fadeIn   { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn  { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hamburger { display: flex; }
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    top: var(--header-h);
    background: rgba(0,0,0,.3);
    z-index: 199;
    display: none;
  }
  .sidebar-overlay.open { display: block; }
  .app-main { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .device-fw { display: none; }

  /* Dashboard móvil: mapa arriba, lista abajo */
  .dashboard-layout {
    flex-direction: column;
  }
  .map-container {
    height: 45vh;
    min-height: 280px;
    flex: none;
  }
  .device-panel {
    width: 100%;
    min-width: 0;
    flex: 1;
    border-left: none;
    border-top: 1px solid var(--color-neutral-200);
    min-height: 200px;
  }
  .device-panel-stats { gap: .35rem; }
  .mini-stat-val { font-size: var(--text-base); }

  /* Panel de detalle móvil: bottom sheet fijo al viewport
     (no absolute dentro del mapa) — botón de cerrar siempre visible */
  .detail-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 72vh;
    z-index: 1000;
    border-top: 2px solid var(--color-neutral-200);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 32px rgba(0,0,0,.15);
  }
  /* Handle visual en la parte superior del bottom sheet */
  .detail-panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--color-neutral-300);
    border-radius: 99px;
    margin: .625rem auto -.25rem;
  }
  .detail-kpis {
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
  }
  .detail-bottom { grid-template-columns: 1fr; }
  .kpi-value { font-size: var(--text-xl); }
}

/* ── Customer picker (modal de selección de cliente) ───────────────────────── */
.cust-picker-item {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding: .5rem .625rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.cust-picker-item:hover { background: var(--color-neutral-100); }
.cust-picker-item.selected {
  background: var(--color-primary);
  color: var(--color-surface);
}
.cust-picker-name  { font-size: var(--text-sm); font-weight: 500; }
.cust-picker-email { font-size: var(--text-xs); color: var(--color-neutral-500); }
.cust-picker-item.selected .cust-picker-email { color: rgba(255,255,255,.7); }

/* ── Divider con texto para modal multi-sección ────────────────────────────── */
.cust-modal-divider {
  display: flex;
  align-items: center;
  gap: .625rem;
  margin: .875rem 0 .625rem;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-neutral-500);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.cust-modal-divider::before,
.cust-modal-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-neutral-200);
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 1.25rem; }
  .map-container { height: 40vh; min-height: 240px; }
  .detail-kpis { gap: .35rem; }
  .kpi-card { padding: .5rem .35rem; }
  .kpi-value { font-size: var(--text-lg); }
  .kpi-label { font-size: 9px; }
  .header-title span { display: none; }   /* ocultar subtítulo */
  .header-user { display: none; }         /* ocultar nombre — queda flag + Salir */
  .lang-label  { display: none; }         /* solo bandera, sin código de idioma */
}

/* ══════════════════════════════════════════════════════════════════════════════
   Flasher ESP32
   ══════════════════════════════════════════════════════════════════════════════ */

/* Consola de salida (terminal) */
.flasher-console {
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  padding: 1rem;
  border-radius: var(--radius-lg);
  min-height: 320px;
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid #313244;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.25);
}
.flasher-console::-webkit-scrollbar { width: 6px; }
.flasher-console::-webkit-scrollbar-track { background: transparent; }
.flasher-console::-webkit-scrollbar-thumb { background: #45475a; border-radius: 99px; }

/* Colores de log */
.flash-log-info    { color: #89b4fa; }
.flash-log-success { color: #a6e3a1; }
.flash-log-error   { color: #f38ba8; }

/* Toolbar */
.flasher-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .25rem 0;
}
.flasher-toolbar-group {
  display: flex;
  align-items: center;
  gap: .375rem;
}

/* Barra de progreso */
.flasher-progress {
  position: relative;
  height: 22px;
  background: var(--color-neutral-200);
  border-radius: 99px;
  overflow: hidden;
  margin-top: .75rem;
}
.flasher-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 99px;
  transition: width .3s ease;
  min-width: 0;
}
.flasher-progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-neutral-900);
  mix-blend-mode: difference;
}

/* Instrucciones */
.flasher-instructions {
  margin-bottom: 1rem;
  border-left: 3px solid var(--color-accent);
}
.flasher-esp-diagram {
  background: var(--color-neutral-50);
  border-radius: var(--radius);
  padding: .5rem 1rem;
  display: inline-block;
}

/* Aviso de navegador no soportado */
.flasher-browser-warn {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-warning);
}
.flasher-browser-warn h3 {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-top: .5rem;
}

/* Responsive: flasher en móvil */
@media (max-width: 768px) {
  .flasher-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .flasher-toolbar-group {
    justify-content: stretch;
  }
  .flasher-toolbar-group:last-child {
    margin-left: 0;
    justify-content: flex-end;
  }
  .flasher-console {
    min-height: 200px;
    font-size: 11px;
  }
}
