* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --c-bg: #f5f7fa;
  --c-surface: #ffffff;
  --c-border: #e4e7eb;
  --c-text: #1f2a37;
  --c-text-soft: #6b7280;
  --c-muted: #9ca3af;
  --c-primary: #1B5E20;
  --c-primary-soft: #E8F5E9;
  --c-primary-dark: #0d3311;
  --c-accent: #22C55E;
  --c-danger: #D32F2F;
  --c-warn: #F59E0B;
  --sidebar-w: 64px;
  --sidebar-w-open: 248px;
  --shadow-1: 0 1px 2px rgba(17,24,39,.04);
  --shadow-2: 0 4px 16px rgba(17,24,39,.08);
  --shadow-3: 0 8px 30px rgba(17,24,39,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════ LOGIN / SETUP ═══════════════ */

.login-page {
  display: flex; align-items: center; justify-content: center; height: 100vh;
  background: linear-gradient(135deg, #0d3311 0%, #1B5E20 50%, #388E3C 100%);
}
.login-box {
  background: #fff; border-radius: 16px; padding: 40px;
  width: 400px; max-width: 90vw; box-shadow: var(--shadow-3);
}
.login-box h2 { text-align: center; color: var(--c-primary); margin-bottom: 8px; font-size: 24px; }
.login-box .subtitle { text-align: center; color: var(--c-text-soft); font-size: 14px; margin-bottom: 24px; }
.login-box .form-group { margin-bottom: 16px; }
.login-box .form-group label { font-weight: 500; margin-bottom: 6px; }
.login-box input[type="text"],
.login-box input[type="password"] {
  width: 100%; padding: 10px 14px; border: 1px solid var(--c-border); border-radius: 8px; font-size: 15px;
}
.login-box input:focus { border-color: var(--c-primary); outline: none; box-shadow: 0 0 0 3px rgba(27,94,32,.12); }
.btn-login {
  width: 100%; padding: 12px; background: var(--c-primary); color: #fff;
  border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 8px;
}
.btn-login:hover { background: #2E7D32; }
.login-error { color: var(--c-danger); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }

/* ═══════════════ APP LAYOUT ═══════════════ */

.app { display: flex; height: 100vh; overflow: hidden; }

/* ════════ Sidebar moderna ════════ */

.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: linear-gradient(180deg, #0f2912 0%, #12331a 100%);
  color: #fff; display: flex; flex-direction: column;
  transition: width .25s cubic-bezier(.2,.8,.2,1), min-width .25s cubic-bezier(.2,.8,.2,1);
  overflow: hidden; z-index: 1001; position: relative;
  box-shadow: 2px 0 14px rgba(0,0,0,.08);
}
.sidebar.expanded { width: var(--sidebar-w-open); min-width: var(--sidebar-w-open); }

/* Brand / toggle */
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.06);
  white-space: nowrap; height: 56px; flex-shrink: 0;
  transition: background .15s;
}
.sidebar-brand:hover { background: rgba(255,255,255,.04); }
.sidebar-brand .brand-icon {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #22C55E, #16A34A);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(34,197,94,.3);
}
.sidebar-brand .brand-icon svg { width: 16px; height: 16px; color: #fff; }
.sidebar-brand .brand-text {
  font-weight: 700; font-size: 15px; letter-spacing: .3px;
  opacity: 0; transition: opacity .2s; flex: 1;
}
.sidebar.expanded .brand-text { opacity: 1; }

/* Nav */
.sidebar-nav {
  flex: 1; padding: 10px 8px;
  overflow-y: auto;       /* scroll si los items (+ submenu Marcageo) no entran */
  overflow-x: hidden;
  display: flex; flex-direction: column; gap: 2px;
  min-height: 0;
}
/* Scrollbar finita y discreta en el menu lateral */
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px; cursor: pointer;
  color: rgba(255,255,255,.65);
  transition: background .15s, color .15s;
  white-space: nowrap; position: relative;
  border-radius: 10px; flex-shrink: 0;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(34,197,94,.15);
  color: #fff;
}
.nav-item.active::before {
  content: ''; position: absolute; left: -8px; top: 10px; bottom: 10px;
  width: 3px; background: var(--c-accent); border-radius: 0 3px 3px 0;
}
.nav-item .nav-icon {
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-item .nav-icon svg { width: 20px; height: 20px; }
.nav-item .nav-label {
  font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity .2s; flex: 1;
  overflow: hidden; text-overflow: ellipsis;
}
.sidebar.expanded .nav-label { opacity: 1; }
.nav-item .nav-badge {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: var(--c-accent); color: #fff;
  font-size: 10px; padding: 1px 6px; border-radius: 8px; font-weight: 700;
  opacity: 0; transition: opacity .2s;
  min-width: 18px; text-align: center;
}
.sidebar.expanded .nav-badge { opacity: 1; }

/* Marcageo: item padre desplegable + submenu */
.nav-parent .nav-caret {
  margin-left: auto; font-size: 16px; line-height: 1;
  opacity: 0; transition: opacity .2s, transform .2s; flex-shrink: 0;
}
.sidebar.expanded .nav-parent .nav-caret { opacity: .7; }
.nav-parent.open .nav-caret { transform: rotate(90deg); }
.nav-submenu { display: flex; flex-direction: column; gap: 2px; margin: 2px 0; }
.nav-subitem {
  display: flex; align-items: center; cursor: pointer;
  color: rgba(255,255,255,.6);
  padding: 8px 12px 8px 46px;
  border-radius: 10px; position: relative; flex-shrink: 0;
  transition: background .15s, color .15s;
}
.nav-subitem:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-subitem.active { background: rgba(34,197,94,.15); color: #fff; }
.nav-subitem .nav-label {
  font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity .2s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar.expanded .nav-subitem .nav-label { opacity: 1; }
/* Sidebar colapsada: el submenu no aporta (solo labels), se oculta */
.sidebar:not(.expanded) .nav-submenu { display: none; }

.nav-divider {
  height: 1px; background: rgba(255,255,255,.08);
  margin: 6px 10px; flex-shrink: 0;
}
.nav-section-label {
  padding: 8px 14px 4px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  color: rgba(255,255,255,.35);
  opacity: 0; transition: opacity .2s; overflow: hidden;
  white-space: nowrap;
}
.sidebar.expanded .nav-section-label { opacity: 1; }

/* User section */
.sidebar-user {
  padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 10px;
  white-space: nowrap; flex-shrink: 0;
}
.sidebar-user .user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #22C55E, #16A34A);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.sidebar-user .user-details {
  opacity: 0; transition: opacity .2s; flex: 1; min-width: 0;
}
.sidebar.expanded .user-details { opacity: 1; }
.sidebar-user .user-name {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .user-role {
  font-size: 11px; color: rgba(255,255,255,.5);
  overflow: hidden; text-overflow: ellipsis;
}
.btn-logout-side {
  margin-left: auto; background: none; border: none;
  color: rgba(255,255,255,.5); cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s, background .15s, color .15s;
}
.btn-logout-side svg { width: 18px; height: 18px; }
.sidebar.expanded .btn-logout-side { opacity: 1; }
.btn-logout-side:hover { background: rgba(239,83,80,.15); color: #EF5350; }

/* ════════ Main area ════════ */

.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.top-bar {
  height: 52px; background: var(--c-surface); border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; padding: 0 18px; gap: 14px;
  z-index: 900;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.top-bar .page-title { font-size: 15px; font-weight: 700; color: var(--c-text); flex-shrink: 0; }
.top-bar .filter-bar { flex-shrink: 0; }

/* Toolbar flotante del mapa (Filtros / Capas / Zoom) —
   estilo compatible con los controles de Leaflet, arriba-izquierda */
.map-sup-bar .map-tool-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; min-width: 88px;
  background: #fff; border: 1px solid rgba(0,0,0,.2); border-radius: 6px;
  font-size: 12px; font-weight: 500; color: var(--c-text);
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  transition: background .12s, border-color .12s;
}
.map-sup-bar .map-tool-btn:hover { background: #f3f4f6; border-color: rgba(0,0,0,.35); }
.map-sup-bar .map-tool-btn:active { background: #e5e7eb; }
.map-sup-bar .map-tool-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Filas del panel Capas */
.layer-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; font-size: 13px; cursor: pointer;
}
.layer-row > span { display: flex; align-items: center; gap: 6px; }
.layer-row-sep {
  padding-top: 8px; margin-top: 8px;
  border-top: 1px solid var(--c-border);
}

/* Ocultar filas del panel Capas segun el modo del mapa (activos / entradaSalida / rastreo).
   El body recibe [data-map-mode="..."] al cambiar de pagina. */
body[data-map-mode="activos"] [data-layer-row="marcas"],
body[data-map-mode="activos"] [data-layer-row="route"],
body[data-map-mode="entradaSalida"] [data-layer-row="markers"],
body[data-map-mode="entradaSalida"] [data-layer-row="route"],
body[data-map-mode="rastreo"] [data-layer-row="markers"],
body[data-map-mode="rastreo"] [data-layer-row="marcas"] {
  display: none !important;
}

/* El boton "Filtros" solo tiene sentido en Rastreo y Entrada/Salida */
body[data-map-mode="activos"] #mapFiltersBtn { display: none !important; }

/* ── Panel de filtros del mapa (tipografia y espaciado) ── */
.map-filters-panel h4 {
  font-size: 12px; font-weight: 700; color: var(--c-text);
  text-transform: uppercase; letter-spacing: .4px; margin: 0;
}
.map-filters-panel .form-group { margin-bottom: 10px; }
.map-filters-panel .form-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--c-text); letter-spacing: .2px; margin-bottom: 4px;
  text-transform: uppercase;
}
.map-filters-panel .form-group input,
.map-filters-panel .form-group select {
  padding: 7px 10px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: #fff; color: var(--c-text);
  width: 100%;
}
.map-filters-panel .form-group input:focus,
.map-filters-panel .form-group select:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(27,94,32,.12);
}
.map-filters-panel .form-row { gap: 8px; }
.map-filters-panel p {
  font-size: 11px; color: var(--c-text-soft); line-height: 1.4;
  margin: 2px 0 10px;
}
.map-filters-panel .btn { font-size: 12px; font-weight: 600; }

/* Search */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: #f1f5f9; border: 1px solid transparent; border-radius: 10px;
  padding: 7px 12px; max-width: 360px; flex: 1;
  transition: all .15s;
}
.search-box:focus-within { background: #fff; border-color: var(--c-border); box-shadow: 0 0 0 3px rgba(27,94,32,.08); }
.search-box input { border: none; background: none; outline: none; font-size: 13px; width: 100%; color: var(--c-text); }
.search-box .search-icon { color: var(--c-muted); display: flex; }
.search-box .search-icon svg { width: 16px; height: 16px; }

.search-results {
  position: absolute; top: 46px; left: 0; right: 0;
  background: #fff; border: 1px solid var(--c-border); border-radius: 10px;
  box-shadow: var(--shadow-2); max-height: 400px; overflow-y: auto;
  z-index: 1200; display: none;
}
.search-results.visible { display: block; }
.search-result-item {
  padding: 10px 14px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #f3f4f6;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f9fafb; }
.search-result-item .result-status { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.search-result-item .result-status.online { background: var(--c-accent); box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.search-result-item .result-status.offline { background: #cbd5e1; }
.search-result-item .result-name { flex: 1; }
.search-result-item .result-meta { color: var(--c-muted); font-size: 11px; }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.filter-btn {
  padding: 5px 12px; border: 1px solid var(--c-border); border-radius: 16px;
  background: #fff; font-size: 12px; cursor: pointer; color: var(--c-text-soft);
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--c-muted); }
.filter-btn.active {
  background: var(--c-primary-soft); border-color: var(--c-primary);
  color: var(--c-primary); font-weight: 600;
}

/* ════════ Content ════════ */

.content-area { flex: 1; position: relative; display: flex; min-height: 0; }
.panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.panel.active { display: flex; }

#map { flex: 1; width: 100%; }

/* Device / rastreos side panel ── flota sobre el mapa, modo compacto ── */
.side-panel {
  position: absolute; top: 0; right: 0;
  width: 320px; height: 100%;
  background: #fff; border-left: 1px solid var(--c-border);
  z-index: 500; display: none;
  box-shadow: -4px 0 16px rgba(17,24,39,.08);
  flex-direction: column;
  font-size: 12px;
}
.side-panel.visible { display: flex; }
.side-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.side-panel-header h3 { font-size: 13px; margin: 0; font-weight: 700; line-height: 1.2; }
.side-panel-header .dp-subtitle { font-size: 10px; color: var(--c-text-soft); margin-top: 1px; }

/* Tabs dentro del side panel */
.sp-tabs {
  display: flex; border-bottom: 1px solid var(--c-border);
  background: #f9fafb; flex-shrink: 0;
}
.sp-tab {
  flex: 1; padding: 7px 4px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .3px;
  color: var(--c-text-soft); cursor: pointer; text-align: center;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.sp-tab:hover { color: var(--c-primary); background: #f3f4f6; }
.sp-tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); background: #fff; }

.sp-tab-panels { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.sp-tab-panel { display: none; flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 12px; }
.sp-tab-panel.active { display: block; }
.sp-tab-panel p { font-size: 12px; margin: 4px 0; }
.sp-tab-panel h4 { font-size: 10px !important; margin: 10px 0 6px !important; }
.sp-tab-panel .form-group { margin-bottom: 8px; }
.sp-tab-panel .form-group label { font-size: 11px; }
.sp-tab-panel .form-group input, .sp-tab-panel .form-group select {
  padding: 5px 8px; font-size: 12px;
}
.sp-tab-panel .btn-sm { padding: 5px 10px; font-size: 11px; }

/* Timeline items (marcas / rastreos) */
.timeline { position: relative; }
.tl-item {
  display: flex; gap: 12px; padding: 8px 4px; cursor: pointer;
  border-radius: 8px; transition: background .12s;
  position: relative;
}
.tl-item:hover { background: #f9fafb; }
.tl-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 12px; font-weight: 700; color: #fff;
  position: relative; z-index: 1;
}
.tl-icon svg { width: 16px; height: 16px; }
.tl-icon.entrada { background: #22C55E; }
.tl-icon.salida { background: #EF5350; }
.tl-icon.rastreo { background: #3B82F6; }
.tl-body { flex: 1; min-width: 0; padding-top: 2px; }
.tl-title { font-size: 13px; font-weight: 600; color: var(--c-text); }
.tl-meta { font-size: 11px; color: var(--c-text-soft); margin-top: 2px; }
.tl-meta .tl-warn { color: var(--c-danger); font-weight: 600; }
.tl-time {
  font-size: 12px; color: var(--c-muted); font-weight: 500;
  flex-shrink: 0; padding-top: 4px; font-variant-numeric: tabular-nums;
}

/* Conector vertical del timeline */
.timeline::before {
  content: ''; position: absolute; left: 16px; top: 16px; bottom: 16px;
  width: 2px; background: #e5e7eb; z-index: 0;
}
.timeline.empty::before { display: none; }

/* Stats row */
.stats-row {
  display: flex; gap: 10px; padding: 14px 18px;
  border-bottom: 1px solid var(--c-border); background: #fff;
}
.stat-card {
  flex: 1; text-align: center; padding: 12px 8px;
  background: #f9fafb; border-radius: 10px;
  border: 1px solid #f3f4f6;
}
.stat-card .stat-val { font-size: 22px; font-weight: 700; color: var(--c-primary); font-variant-numeric: tabular-nums; }
.stat-card .stat-lbl { font-size: 10px; color: var(--c-text-soft); text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }

/* List panels */
.list-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; background: #fff; }
.list-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--c-border); flex-shrink: 0;
}
.list-panel-header h3 { font-size: 15px; margin: 0; font-weight: 700; }
.list-panel-body { flex: 1; overflow-y: auto; padding: 14px 18px; }

/* Sub-tabs */
.sub-tabs { display: flex; border-bottom: 1px solid var(--c-border); flex-shrink: 0; }
.sub-tab {
  padding: 10px 16px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; color: var(--c-text-soft); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.sub-tab:hover { color: var(--c-primary); background: #f9fafb; }
.sub-tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.sub-panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.sub-panel.active { display: flex; }

/* ═══════════════ COMMON ═══════════════ */

.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--c-text-soft); margin-bottom: 5px; font-weight: 500; }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--c-border); border-radius: 8px;
  font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(27,94,32,.1);
}
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

.btn {
  padding: 8px 16px; border: 1px solid var(--c-border); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all .15s; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: #f9fafb; border-color: var(--c-muted); }
.btn svg { width: 14px; height: 14px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: #2E7D32; border-color: #2E7D32; }
.btn-danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: #FEF2F2; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
}
.badge-superadmin { background: #E0E7FF; color: #3730A3; }
.badge-admin { background: #FFEDD5; color: #9A3412; }
.badge-supervisor { background: #F3E8FF; color: #6B21A8; }
.badge-operador { background: #D1FAE5; color: #065F46; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: #fff; border: 1px solid #f0f2f4;
  border-radius: 10px; font-size: 13px; margin-bottom: 8px;
  transition: border-color .15s, box-shadow .15s;
}
.list-item:hover { border-color: var(--c-border); box-shadow: var(--shadow-1); }
.list-item .li-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--c-primary); color: #fff; display: flex;
  align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-meta { font-size: 11px; color: var(--c-text-soft); margin-top: 2px; }
.list-item .li-actions { display: flex; gap: 4px; flex-shrink: 0; }
.list-item .li-actions button {
  padding: 5px 9px; font-size: 11px; border-radius: 6px;
  border: 1px solid var(--c-border); background: #fff; cursor: pointer;
  color: var(--c-text-soft); transition: all .12s;
}
.list-item .li-actions button:hover { background: #f9fafb; color: var(--c-text); }
.list-item .li-actions .btn-del:hover { background: #FEF2F2; border-color: var(--c-danger); color: var(--c-danger); }

.empty-msg { color: var(--c-muted); font-size: 13px; text-align: center; padding: 40px 0; }

/* Tabla de Asistencias */
.asist-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: #fff; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--c-border);
}
.asist-table thead th {
  position: sticky; top: 0; background: #f9fafb;
  text-align: left; padding: 10px 12px;
  font-size: 11px; text-transform: uppercase; color: var(--c-text-soft);
  font-weight: 700; letter-spacing: .3px;
  border-bottom: 1px solid var(--c-border); z-index: 1;
  white-space: nowrap;
}
.asist-table tbody tr { border-bottom: 1px solid #f3f4f6; }
.asist-table tbody tr:last-child { border-bottom: none; }
.asist-table tbody tr:hover { background: #f9fafb; }
.asist-table td { padding: 10px 12px; vertical-align: middle; }
.asist-table td.time { font-variant-numeric: tabular-nums; }
.asist-table .li-icon {
  width: 26px; height: 26px; font-size: 11px; border-radius: 50%;
  background: var(--c-primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}
.asist-table tr.anulada-row { background: #fafafa; opacity: .85; }
.asist-table tr.anulada-row:hover { background: #f3f4f6; }

.close-btn {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--c-text-soft); padding: 0 6px; border-radius: 6px;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
}
.close-btn:hover { background: #f3f4f6; color: var(--c-text); }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(17,24,39,.5);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff; border-radius: 14px; padding: 24px;
  width: 520px; max-width: 92vw; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-3);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px;
}
.modal-header h3 { font-size: 17px; margin: 0; font-weight: 700; }

/* Context menu */
.ctx-menu {
  position: fixed; background: #fff; border: 1px solid var(--c-border);
  border-radius: 10px; box-shadow: var(--shadow-2);
  z-index: 3000; min-width: 180px; padding: 4px; display: none;
}
.ctx-menu.visible { display: block; }
.ctx-menu-item {
  padding: 9px 14px; font-size: 13px; cursor: pointer; display: flex;
  align-items: center; gap: 10px; border-radius: 6px;
}
.ctx-menu-item:hover { background: #f3f4f6; }
.ctx-menu-item svg { width: 14px; height: 14px; color: var(--c-text-soft); }

/* ═══════════════ HAMBURGUESA + BACKDROP MOBILE ═══════════════ */

.hamburger-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: transparent; border: 1px solid var(--c-border); border-radius: 8px;
  cursor: pointer; flex-shrink: 0;
  color: var(--c-text);
  padding: 0;
}
.hamburger-btn:hover { background: #f3f4f6; }
.hamburger-btn svg { width: 20px; height: 20px; }

/* Backdrop semitransparente detras del sidebar en mobile */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 1000;
}
.sidebar-backdrop.visible { display: block; }

/* ═══════════════ RESPONSIVE ═══════════════ */

@media (max-width: 768px) {
  :root { --sidebar-w: 0; --sidebar-w-open: 240px; }
  .sidebar.expanded { position: fixed; height: 100vh; top: 0; left: 0; }
  .side-panel { width: 100%; }
  .hamburger-btn { display: inline-flex; }
}

@media (max-height: 620px) {
  /* Si la ventana es muy corta, aún más compacto para evitar clip */
  .nav-item { padding: 7px 12px; }
  .sidebar-brand { height: 48px; }
  .sidebar-user { padding: 8px 12px; }
  .sidebar-user .user-avatar { width: 30px; height: 30px; }
}

/* ===== Seccion Marcageo ===== */
.mg-header { display: flex; align-items: center; gap: 16px; }
.mg-badge { margin-left: auto; font-size: 12px; font-weight: 600; }
.mg-topmenu { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--c-border, #e0e0e0); background: #fafafa; }
.mg-toptab { border: 1px solid transparent; background: transparent; padding: 8px 16px; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px; color: var(--c-text-soft, #555); }
.mg-toptab:hover { background: #f0f0f0; }
.mg-toptab.active { background: #fff; color: var(--c-primary, #2e7d32); font-weight: 600; border-color: var(--c-border, #e0e0e0); border-bottom-color: #fff; margin-bottom: -1px; }
.mg-tab-content { display: none; }
.mg-tab-content.active { display: block; }

/* ── ABM Tipo notas (modal a medida) ── */
.mg-tn-tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 16px 0; border-bottom: 1px solid var(--c-border, #e0e0e0); }
.mg-tn-tab { border: 1px solid transparent; background: transparent; padding: 7px 14px; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px; color: var(--c-text-soft, #555); }
.mg-tn-tab:hover { background: #f0f0f0; }
.mg-tn-tab.active { background: #fff; color: var(--c-primary, #2e7d32); font-weight: 600; border-color: var(--c-border, #e0e0e0); border-bottom-color: #fff; margin-bottom: -1px; }
.mg-tn-pane { display: none; }
.mg-tn-pane.active { display: block; }
.mg-tn-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.mg-tn-preset { width: 44px; height: 44px; border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px; background: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--c-primary, #2e7d32); }
.mg-tn-preset:hover { background: #e8f5e9; border-color: var(--c-primary, #2e7d32); }
.mg-tn-preset svg { width: 24px; height: 24px; }
.mg-tn-row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.mg-tn-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 8px; margin-top: 6px; }
.mg-tn-check { display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center;
  font-weight: 400; font-size: 12px; cursor: pointer; color: var(--c-text-soft, #555); }
.mg-tn-check-lbl { line-height: 1.2; min-height: 2.4em; display: flex; align-items: center; }
.mg-tn-check input { width: 18px; height: 18px; cursor: pointer; }
.mg-tn-permstr { margin-top: 12px; width: 220px; max-width: 100%; font-family: monospace; font-size: 15px;
  letter-spacing: 4px; text-align: center; background: #f5f5f5; color: #333; }
.mg-tn-svg { display: flex; gap: 10px; align-items: stretch; }
.mg-tn-svg textarea { flex: 1; font-family: monospace; font-size: 12px; }
.mg-tn-svg-prev { width: 64px; min-width: 64px; height: auto; border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 8px; background: #fff; }
.mg-tn-svg-prev svg { width: 40px; height: 40px; }
.mg-tn-svg-prev .mg-type { font-size: 10px; text-align: center; }
.mg-tn-campos { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.mg-tn-campo { border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px; padding: 8px; background: #fafafa; }
.mg-tn-campo-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mg-tn-campo-tipo { width: 150px; }
.mg-tn-campo-label { flex: 1; min-width: 160px; }
.mg-tn-campo-extra { margin-top: 8px; }
.mg-tn-campo-extra textarea { width: 100%; font-size: 13px; }
.mg-tn-num { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mg-tn-num label { font-size: 11px; color: var(--c-text-soft, #666); }

/* ── Detalle de nota (Gestion -> Notas) ── */
.mg-nota-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 6px; }
.mg-nota-campo { padding: 8px 0; border-top: 1px solid var(--c-border, #eee); }
.mg-nota-label { font-size: 11px; font-weight: 600; color: var(--c-text-soft, #666); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; }
.mg-nota-sub { margin: 14px 0 2px; font-size: 14px; color: var(--c-primary, #2e7d32); }
.mg-nota-img { max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid var(--c-border, #e0e0e0); display: block; margin-top: 4px; background: #fff; cursor: zoom-in; }
.mg-nota-firma { background: #fff; }
.mg-nota-mapa { width: 100%; height: 240px; border-radius: 8px; overflow: hidden; border: 1px solid var(--c-border, #e0e0e0); margin: 4px 0; }

/* Asistencias por supervisor */
.mg-asist-grupo { margin-bottom: 18px; }
.mg-asist-sup { font-weight: 600; color: var(--c-primary, #2e7d32); margin: 6px 0 4px; }

/* Tab Cliente: 50% datos + 50% mapa (mapa ocupa toda la altura de la columna) */
.mg-nota-cliente { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: stretch; }
.mg-nota-mapwrap { display: flex; flex-direction: column; gap: 4px; }
.mg-nota-mapwrap .mg-nota-mapa { flex: 1; min-height: 340px; height: 100%; margin-top: 0; }
@media (max-width: 640px) { .mg-nota-cliente { grid-template-columns: 1fr; } .mg-nota-mapwrap .mg-nota-mapa { min-height: 260px; } }

/* Carrusel de imagenes */
.mg-nota-carrusel { display: flex; flex-direction: column; gap: 8px; }
.mg-nota-car-main { display: flex; align-items: center; gap: 8px; justify-content: center; }
.mg-nota-car-main img { max-width: 100%; max-height: 380px; border-radius: 8px; border: 1px solid var(--c-border, #e0e0e0); cursor: zoom-in; background: #fff; }
.mg-nota-car-nav { border: 1px solid var(--c-border, #e0e0e0); background: #fff; border-radius: 50%; width: 36px; height: 36px; font-size: 22px; line-height: 1; cursor: pointer; flex-shrink: 0; color: var(--c-primary, #2e7d32); }
.mg-nota-car-nav:hover { background: #e8f5e9; }
.mg-nota-car-info { text-align: center; font-size: 13px; }
.mg-nota-thumbs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.mg-nota-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--c-border, #e0e0e0); cursor: pointer; background: #fff; }
.mg-nota-thumb:hover { border-color: var(--c-primary, #2e7d32); }

/* Lightbox zoom + giro */
.mg-zoom-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 4000; display: flex; flex-direction: column; }
.mg-zoom-bar { display: flex; gap: 8px; justify-content: center; padding: 12px; flex-wrap: wrap; }
.mg-zoom-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 12px; }
.mg-zoom-stage img { max-width: 92vw; max-height: 82vh; transition: transform .2s; }

.mg-tables-layout { display: flex; gap: 16px; height: calc(100vh - 190px); min-height: 360px; }
.mg-tables-side { width: 240px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; }
.mg-tables-list { overflow-y: auto; border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px; flex: 1; }
.mg-table-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.mg-table-item:hover { background: #f7faf7; }
.mg-table-item.active { background: #e8f5e9; font-weight: 600; }
.mg-table-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-table-count { color: var(--c-muted, #999); font-size: 11px; margin-left: 8px; }
.mg-tables-main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.mg-data { display: block; }
.mg-data-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 0; }
.mg-data-info { color: var(--c-text-soft, #555); font-size: 12px; margin-left: auto; }
.mg-search-input { padding: 8px 11px; border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px; font-size: 13px; background: #fff; min-width: 170px; }
select.mg-search-input { cursor: pointer; }
.mg-grid-wrap { overflow: auto; border: 1px solid var(--c-border, #e0e0e0); border-radius: 10px; max-height: calc(100vh - 300px); }
.mg-grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.mg-grid th, .mg-grid td { padding: 9px 12px; text-align: left; white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid #eef0f2; }
.mg-grid thead th { position: sticky; top: 0; background: #f6f8f6; z-index: 1; color: var(--c-text-soft, #555); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.mg-grid tbody tr:nth-child(even) { background: #fcfdfc; }
.mg-grid tbody tr:hover { background: #f1f8f1; }
.mg-pk { font-size: 9px; background: var(--c-primary, #2e7d32); color: #fff; border-radius: 3px; padding: 1px 4px; vertical-align: middle; }
.mg-null { color: #c4c4c4; font-style: italic; }
.mg-actions-col { width: 1%; white-space: nowrap; text-align: center; }
.mg-actions { display: inline-flex; gap: 6px; }
.mg-ico { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 1px solid var(--c-border, #e0e0e0); background: #fff; border-radius: 8px; cursor: pointer; color: var(--c-text-soft, #666); transition: background .12s, color .12s, border-color .12s; }
.mg-ico:hover { background: #f0f4f0; color: var(--c-primary, #2e7d32); border-color: #cfe3cf; }
.mg-ico-reset:hover { background: #e8f1fb; color: #1565c0; border-color: #b6d4f0; }
.mg-ico-del:hover { background: #fdecea; color: #c62828; border-color: #f5b3ad; }
.mg-empty { padding: 28px; text-align: center; color: var(--c-muted, #999); font-size: 13px; }
.mg-warn { background: #fff8e1; border: 1px solid #ffe082; color: #8a6d00; padding: 8px 12px; border-radius: 6px; font-size: 12px; margin-bottom: 10px; }

/* Modal del editor de filas */
.mg-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.mg-modal { background: #fff; border-radius: 12px; width: min(560px, 92vw); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.mg-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--c-border, #eee); }
.mg-modal-head h3 { margin: 0; font-size: 15px; }
.mg-modal-body { padding: 16px 18px; overflow-y: auto; }
.mg-modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--c-border, #eee); }
.mg-editor-msg { flex: 1; font-size: 12px; color: #c62828; }
.mg-field { margin-bottom: 12px; }
.mg-field label { display: block; font-size: 12px; color: var(--c-text-soft, #555); margin-bottom: 4px; }
.mg-field input, .mg-field select, .mg-field textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--c-border, #e0e0e0); border-radius: 6px; font-size: 13px; box-sizing: border-box; background: #fff; font-family: inherit; }
.mg-field select { cursor: pointer; }
.mg-field input[readonly] { background: #f5f5f5; color: #888; }
.mg-modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.mg-modal-body .mg-hint { grid-column: 1 / -1; }
/* Modales con tabs (nota / tipo_notas): cuerpo en bloque, NO grilla de 2 columnas */
.mg-modal-body.mg-body-plain { display: block; }
.mg-field { margin-bottom: 0; }
.mg-type { color: var(--c-muted, #aaa); font-weight: 400; font-size: 10px; }
.mg-hint { font-size: 12px; color: var(--c-text-soft, #666); margin: 0 0 14px; }
.mg-qr-json { margin-top: 12px; font-family: monospace; font-size: 11px; color: var(--c-muted, #888); word-break: break-all; max-width: 520px; background: #f7f7f7; border: 1px solid var(--c-border, #eee); border-radius: 6px; padding: 8px 10px; }
.mg-qr-json:empty { display: none; }

/* Boton mapa en acciones de fila (places) */
.mg-ico-map:hover { background: #e8f1fb; color: #1565c0; border-color: #b6d4f0; }

/* Permisos de visibilidad en el modal de usuario */
.permisos-box { display: flex; gap: 14px; flex-wrap: wrap; border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px; padding: 10px; background: #fafafa; }
.permisos-group { flex: 1; min-width: 200px; }
.permisos-group-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-soft, #666); margin-bottom: 6px; }
.permisos-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 0; cursor: pointer; }
.permisos-item input { cursor: pointer; margin: 0; }

/* Pestana "Asignar places a usuarios" */
.mg-asg-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.mg-seg-group { display: inline-flex; border: 1px solid var(--c-border, #e0e0e0); border-radius: 8px; overflow: hidden; }
.mg-seg { border: none; background: #fff; padding: 7px 14px; font-size: 12.5px; cursor: pointer; color: var(--c-text-soft, #555); border-right: 1px solid var(--c-border, #eee); }
.mg-seg:last-child { border-right: none; }
.mg-seg:hover { background: #f3f7f3; }
.mg-seg.active { background: var(--c-primary, #2e7d32); color: #fff; }
.mg-asg-bar label { font-size: 12px; color: var(--c-text-soft, #555); }
.mg-asg-bar select { padding: 7px 10px; border: 1px solid var(--c-border, #e0e0e0); border-radius: 6px; font-size: 13px; background: #fff; cursor: pointer; min-width: 220px; }
.mg-asg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mg-asg-col { border: 1px solid var(--c-border, #e0e0e0); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; background: #fff; }
.mg-asg-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--c-border, #eee); background: #fafafa; }
.mg-asg-head h4 { margin: 0; font-size: 13px; }
.mg-asg-count { font-size: 11px; color: var(--c-muted, #999); }
.mg-asg-search { margin: 8px 10px; padding: 7px 10px; border: 1px solid var(--c-border, #e0e0e0); border-radius: 6px; font-size: 13px; box-sizing: border-box; width: calc(100% - 20px); font-family: inherit; }
.mg-asg-list { max-height: 420px; overflow-y: auto; padding: 0 6px 8px; }
.mg-asg-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; font-size: 12.5px; cursor: pointer; }
.mg-asg-item:hover { background: #f3f7f3; }
.mg-asg-item input { cursor: pointer; margin: 0; }
.mg-asg-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-asg-assigned { background: #eef7ee; }
.mg-asg-dot { color: #2e7d32; font-size: 11px; }
.mg-asg-foot { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--c-border, #eee); }
.mg-asg-foot .mg-editor-msg { color: var(--c-text-soft, #555); }
@media (max-width: 760px) { .mg-asg-cols { grid-template-columns: 1fr; } }
