:root {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: rgba(255,255,255,0.08);
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --accent: #3b82f6;
  --accent-soft: rgba(59,130,246,0.15);
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 60px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; position: relative; overflow: hidden; }
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  height: calc(var(--nav-h) + var(--safe-bottom));
  flex-shrink: 0;
}
.bn-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; font-weight: 500; color: var(--text-3);
  text-decoration: none;
}
.bn-tab svg { width: 22px; height: 22px; }
.bn-tab.active { color: var(--accent); }

/* Map screen */
.map-screen { height: 100%; position: relative; }
#map { position: absolute; inset: 0; z-index: 1; }
.leaflet-container { background: var(--surface-2) !important; }
.leaflet-control-attribution { font-size: 9px !important; opacity: 0.5; }
.leaflet-control-zoom { display: none !important; }

.top-bar {
  position: absolute; top: calc(var(--safe-top) + 10px);
  left: 10px; right: 10px;
  z-index: 30;
  display: flex; gap: 8px; align-items: center;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; color: var(--text); }
.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.pill-search { flex: 1; min-width: 0; }
.pill-search svg { width: 14px; height: 14px; color: var(--text-3); flex-shrink: 0; }
.pill-search input {
  flex: 1; min-width: 0;
  border: none; background: transparent; color: var(--text);
  font-size: 14px; font-weight: 500; outline: none;
}
.pill-search input::placeholder { color: var(--text-3); }
.pill-stats {
  flex-shrink: 0;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.blue { background: var(--accent); }
.dot.green { background: var(--green); }
.dot.gray { background: var(--text-3); }
.dot-sep { width: 1px; height: 10px; background: var(--border); margin: 0 4px; }

/* FABs */
.fab {
  position: absolute; right: 12px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  z-index: 25;
  cursor: pointer;
}
.fab svg { width: 18px; height: 18px; color: var(--text); }
.fab.fab-layers { top: calc(var(--safe-top) + 70px); }

/* Markers */
.marker-static, .marker-pulse, .marker-offline {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.marker-static { background: var(--green); }
.marker-pulse { background: var(--accent); animation: marker-pulse 1.5s infinite; }
.marker-offline { background: var(--text-3); border-width: 2px; }
@keyframes marker-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.6), 0 2px 8px rgba(0,0,0,0.3); }
  50%      { box-shadow: 0 0 0 10px rgba(59,130,246,0), 0 2px 8px rgba(0,0,0,0.3); }
}
.leaflet-tooltip.device-label {
  background: rgba(15,23,42,0.92);
  color: #e2e8f0;
  padding: 2px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 500;
  border: 1px solid rgba(59,130,246,0.35);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  white-space: nowrap;
  pointer-events: none;
  z-index: 650;
}
.leaflet-tooltip.device-label::before { display: none; }

/* Bottom sheet */
.sheet-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity 200ms;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-top: 1px solid var(--border);
  z-index: 45;
  transform: translateY(calc(100% - 80px));
  transition: transform 250ms cubic-bezier(0.32, 0.72, 0, 1);
  max-height: calc(100vh - 80px - var(--safe-top));
  display: flex; flex-direction: column;
}
.sheet.peek { transform: translateY(calc(100% - 80px)); }
.sheet.full { transform: translateY(0); }
.sheet.closed { transform: translateY(100%); }
.sheet-handle-wrap {
  padding: 10px 0 4px;
  display: flex; justify-content: center;
  cursor: grab;
  flex-shrink: 0;
}
.sheet-handle {
  width: 40px; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}
.sheet-peek-label {
  text-align: center;
  font-size: 13px; font-weight: 500;
  color: var(--text-2);
  padding: 4px 0 12px;
  flex-shrink: 0;
}
.sheet-body { flex: 1; overflow-y: auto; padding: 0 16px 16px; }

/* Vehicle list */
.v-search-wrap {
  position: relative; padding: 8px 0;
}
.v-search-wrap > svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  width: 14px; height: 14px;
}
.v-search-wrap input {
  width: 100%; padding: 10px 10px 10px 36px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text); font-size: 13px;
  outline: none;
}
.v-filters {
  display: flex; gap: 6px;
  padding: 4px 0 12px;
  overflow-x: auto;
}
.v-filters::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11px; font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.v-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.v-row:last-child { border-bottom: none; }
.v-row:active { background: rgba(255,255,255,0.03); }
.v-row .dot { width: 10px; height: 10px; flex-shrink: 0; }
.v-info { flex: 1; min-width: 0; }
.v-name { font-weight: 500; font-size: 14px; }
.v-sub { font-size: 11px; color: var(--text-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-speed { font-size: 12px; font-weight: 500; flex-shrink: 0; color: var(--text-2); }
.v-speed.moving { color: var(--accent); }

/* Generic placeholder */
.placeholder {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 20px;
  text-align: center;
}
.placeholder h2 { font-size: 18px; font-weight: 500; margin: 0 0 8px; }
.placeholder p { color: var(--text-2); font-size: 13px; margin: 0; max-width: 280px; }
.placeholder svg { width: 48px; height: 48px; color: var(--text-3); margin-bottom: 16px; }

/* "Más" tab list */
.more-list {
  padding: 16px 0;
}
.more-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.more-item:active { background: rgba(255,255,255,0.03); }
.more-item svg { width: 20px; height: 20px; color: var(--text-2); flex-shrink: 0; }
.more-item-label { flex: 1; font-size: 14px; }
.more-item-chevron { color: var(--text-3); }
.more-item.danger .more-item-label { color: var(--red); }
.more-item.danger svg { color: var(--red); }
.more-header {
  padding: calc(var(--safe-top) + 16px) 20px 8px;
  font-size: 13px; color: var(--text-2);
}
.more-header strong { color: var(--text); display: block; font-size: 16px; font-weight: 600; margin-bottom: 2px; }

/* ─── Detail Sheet — Sprint 31.C ──────────────────────────────────────── */
.detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 60;
  opacity: 0; pointer-events: none;
  transition: opacity 200ms;
}
.detail-overlay.open { opacity: 1; pointer-events: auto; }

.detail-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-top: 1px solid var(--border);
  z-index: 65;
  transform: translateY(100%);
  transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
  max-height: calc(100vh - var(--safe-top) - 20px);
  display: flex; flex-direction: column;
}
.detail-sheet.open { transform: translateY(0); }

.ds-handle-wrap { padding: 10px 0 4px; display: flex; justify-content: center; flex-shrink: 0; }
.ds-handle { width: 40px; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; }

.ds-head {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ds-icon {
  width: 40px; height: 40px;
  background: var(--accent-soft);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: #60a5fa;
}
.ds-icon svg { width: 22px; height: 22px; }
.ds-head-text { flex: 1; min-width: 0; }
.ds-name { font-weight: 500; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-sub { font-size: 11px; color: var(--text-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-close { background: transparent; cursor: pointer; }

.ds-body { flex: 1; overflow-y: auto; padding: 12px 16px calc(20px + var(--safe-bottom)); }

.ds-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ds-kpi { background: rgba(255,255,255,0.04); border-radius: 10px; padding: 10px 8px; text-align: center; }
.ds-kpi-l { font-size: 9px; color: var(--text-2); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.ds-kpi-v { font-size: 16px; font-weight: 500; margin-top: 2px; }
.ds-kpi-v.green { color: var(--green); }
.ds-kpi-v.red { color: var(--red); }

.ds-state-wrap { text-align: center; margin: 8px 0 4px; }
.ds-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}
.ds-chip-accent { background: var(--accent-soft); color: #60a5fa; }
.ds-chip-green  { background: rgba(16,185,129,0.15); color: #34d399; }
.ds-chip-gray   { background: rgba(148,163,184,0.15); color: var(--text-2); }
.ds-chip .dot { width: 6px; height: 6px; }

.ds-info { margin-top: 8px; }
.ds-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 12px;
  gap: 12px;
}
.ds-row:last-child { border-bottom: none; }
.ds-l { color: var(--text-2); flex-shrink: 0; }
.ds-v { font-weight: 500; max-width: 65%; text-align: right; word-wrap: break-word; }

.ds-section-title {
  font-size: 10px; color: var(--text-2); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 14px 0 6px;
}

.ds-io { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ds-io-pill { background: rgba(255,255,255,0.04); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ds-io-l { font-size: 10px; color: var(--text-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-io-state { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.ds-io-state.on   { color: var(--green); }
.ds-io-state.off  { color: var(--red); }
.ds-io-state.idle { color: var(--text-2); }
.ds-io-dot { width: 8px; height: 8px; border-radius: 50%; }
.ds-io-dot.on   { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,0.18); }
.ds-io-dot.off  { background: var(--red); }
.ds-io-dot.idle { background: var(--text-3); }

.ds-cmds { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.ds-cmd {
  padding: 12px; border-radius: 10px; text-align: center;
  font-size: 13px; font-weight: 500; border: 1px solid;
  cursor: pointer; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.ds-cmd svg { width: 14px; height: 14px; }
.ds-cmd:disabled { opacity: 0.6; cursor: not-allowed; }
.ds-cmd-cut     { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.4); color: #fca5a5; }
.ds-cmd-restore { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.4); color: #6ee7b7; }

.ds-secondary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.ds-sec {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  padding: 10px 4px; border-radius: 8px;
  text-align: center; font-size: 11px; color: var(--text);
  cursor: pointer; font-family: inherit;
}
.ds-sec:active { background: rgba(255,255,255,0.1); }

/* ─── Share Modal — Sprint 31.C.1 ─────────────────────────────────── */
.share-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 70;
  opacity: 0; pointer-events: none;
  transition: opacity 200ms;
}
.share-overlay.open { opacity: 1; pointer-events: auto; }

.share-modal {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-top: 1px solid var(--border);
  z-index: 75;
  transform: translateY(100%);
  transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
  max-height: calc(100vh - var(--safe-top) - 20px);
  display: flex; flex-direction: column;
}
.share-modal.open { transform: translateY(0); }

.share-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.share-title { font-weight: 500; font-size: 15px; }
.share-close { background: transparent; cursor: pointer; }

.share-body {
  padding: 16px calc(16px) calc(20px + var(--safe-bottom));
  overflow-y: auto;
}
.share-label {
  font-size: 11px; color: var(--text-2); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.share-durs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.share-dur {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 10px;
  font-size: 13px; font-weight: 500; color: var(--text);
  cursor: pointer; font-family: inherit;
}
.share-dur.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #60a5fa;
}

.share-link-row { display: flex; gap: 8px; align-items: stretch; }
.share-link-row input {
  flex: 1; min-width: 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text); font-size: 12px;
  font-family: ui-monospace, monospace;
  outline: none;
}
.share-copy {
  background: var(--accent);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  color: #fff;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}
.share-copy.copied { background: var(--green); }

.share-note {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.5;
}

/* ─── Sprint 31.C.7 — Grupos jerárquicos en bottom sheet (clon desktop) ─ */
.dg-list { margin: 0 -16px; } /* anula el padding lateral del sheet body */
.dg-company {
  padding: 8px 16px;
  background: rgba(255,255,255,0.04);
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700; cursor: pointer;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.dg-company:active { background: rgba(255,255,255,0.06); }
.dg-caret {
  width: 12px; color: var(--text-2);
  font-size: 10px; display: inline-block;
  transition: transform 0.15s;
}
.dg-caret.collapsed { transform: rotate(-90deg); }
.dg-color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dg-color-square { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.dg-label {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dg-count { font-size: 10px; color: var(--text-2); font-weight: 500; }
.dg-subgroup {
  padding: 6px 16px 6px 32px;
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 600; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-2);
  background: rgba(255,255,255,0.015);
}
.dg-subgroup:active { background: rgba(255,255,255,0.04); }
.dg-subgroup.ungrouped { color: var(--text-3); font-style: italic; }

.device-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
}
.device-item:active { background: rgba(255,255,255,0.03); }
.device-item.nested { padding-left: 44px; }
.device-item.nested.subgrouped { padding-left: 56px; }
.device-item-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.device-item-dot.dot-moving  { background: var(--accent); animation: marker-pulse 1.5s infinite; }
.device-item-dot.dot-online  { background: var(--green); }
.device-item-dot.dot-offline { background: var(--text-3); }
.device-item-info { flex: 1; min-width: 0; }
.device-item-name {
  font-weight: 500; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.device-item-meta {
  font-size: 11px; color: var(--text-2); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.device-item-speed {
  font-size: 12px; font-weight: 500;
  color: var(--accent); flex-shrink: 0;
}

/* ─── Sprint 31.C.7 — I/O panel (clon desktop gps.html:1333-1340) ──── */
.detail-io {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.io-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text);
}
.io-label { font-weight: 500; }
.io-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-3);
  display: inline-block;
}
.io-dot.on  { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,0.18); }
.io-dot.off { background: var(--red); }

.dout-status {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0 0;
  font-size: 12px;
  color: var(--text-2);
}
.dout-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-3);
  display: inline-block;
}
.dout-dot.on  { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,0.18); }
.dout-dot.off { background: var(--red); }

/* ─── Sprint 31.D — Login screen propio del SPA mobile ────────────── */
.login-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  /* el bottom-nav del shell sigue presente cuando se renderiza directamente
     en #app, así que ocultémoslo mientras el login es visible */
  z-index: 100;
}
.login-screen ~ .bottom-nav,
body:has(.login-screen) .bottom-nav { display: none; }

.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 22px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  display: flex; flex-direction: column;
}

.login-logo {
  display: flex; justify-content: center;
  margin-bottom: 18px;
}
.login-logo img { height: 36px; width: auto; }

.login-title {
  font-size: 18px; font-weight: 600;
  margin: 0 0 4px;
  color: var(--text);
  text-align: center;
}
.login-sub {
  font-size: 12px; color: var(--text-2);
  margin: 0 0 22px;
  text-align: center;
}

.login-label {
  font-size: 11px; font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 6px;
  display: block;
}
.login-input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 14px;
  -webkit-appearance: none;
}
.login-input:focus {
  border-color: var(--accent);
  background: rgba(59,130,246,0.06);
}

.login-submit {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
}
.login-submit:active { opacity: 0.85; }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error {
  margin-top: 14px;
  font-size: 12px;
  color: var(--red);
  text-align: center;
  min-height: 16px;
}
