:root {
  --bg: #f4f6f8;
  --bg-card: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --bg-sidebar: #111318;
  --dark-bg: #111318;
  --dark-surface: #161920;
  --dark-elevated: #1e222b;
  --dark-border: #262b38;
  --text: #111318;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --muted: #64748b;
  --text-on-dark: #f8fafc;
  --accent: #e85d04;
  --accent-rgb: 232, 93, 4;
  --accent-dark: #c44d03;
  --accent-hover: #d45200;
  --accent-deep: #c94e02;
  --accent-soft: #fff7ed;
  --accent-light: #fb923c;
  --orange: var(--accent);
  --orange-dark: var(--accent-dark);
  --orange-hover: var(--accent-hover);
  --orange-soft: var(--accent-soft);
  --orange-border: rgba(var(--accent-rgb), 0.28);
  --border: #e2e8f0;
  --border-subtle: #edf2f7;
  --danger: #b91c1c;
  --ok: #15803d;
  --sidebar-w: 248px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-ui: 6px;
  --radius: 6px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(17, 19, 24, 0.04);
  --shadow: 0 1px 3px rgba(17, 19, 24, 0.06), 0 1px 2px rgba(17, 19, 24, 0.04);
}

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

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--orange); text-decoration: none; }
a:hover { color: var(--orange-dark); }

h1, h2, h3 {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

body.map-mode .app-footer { display: none; }
body.map-mode #content {
  max-width: none;
  padding: 0;
}

/* —— Botones (más compactos + redondeados) —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.25;
  cursor: pointer;
  text-align: center;
  background: var(--orange);
  color: #fff;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover {
  background: var(--orange-dark);
  color: #fff;
}
.btn:active {
  transform: translateY(0.5px);
}
.btn-outline {
  background: #fff;
  color: var(--orange);
  border-color: #f0c9a8;
  box-shadow: none;
}
.btn-outline:hover {
  background: var(--orange-soft);
  border-color: var(--orange);
  color: var(--orange-dark);
}
.btn-dark {
  background: var(--bg-sidebar);
  color: #fff;
  box-shadow: none;
}
.btn-dark:hover {
  background: #2a2b30;
  color: #fff;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #991b1b;
  color: #fff;
}
.btn-block { width: 100%; }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* —— Inputs / selects / textarea —— */
.input, select, textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ui);
  background: #fff;
  color: #1e293b;
  font-size: 13px;
  font-family: var(--font);
  line-height: 1.35;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input.input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select.input,
select {
  height: 36px;
}
.input:focus, select:focus, textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: #475569;
  margin-bottom: 5px;
}
.field { margin-bottom: 12px; }

/* —— Cards —— */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-ui);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  text-align: center;
  border-radius: var(--radius-ui);
  background: #f8fafc;
  color: #475569;
  border: 1px solid #e2e8f0;
}
.badge-on { background: #dcfce7; color: var(--ok); }
.badge-off { background: #f3f4f6; color: #4b5563; }
.badge-sin { background: #fee2e2; color: var(--danger); }

/* —— App shell —— */
body.app-body {
  display: flex;
  min-height: 100vh;
}

#sidebar-wrap { flex-shrink: 0; }

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: 248px;
  height: 100%;
  background: linear-gradient(180deg, #111318 0%, #161920 100%);
  color: var(--text-on-dark);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  transform: translateX(0);
  transition: transform 0.25s ease;
}
.sidebar-brand {
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 11px;
}
.sidebar-logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(var(--accent-rgb), 0.32);
}
.sidebar-logo-mark svg {
  width: 20px;
  height: 20px;
}
.sidebar-logo-mark.has-logo-img,
.brand-mark.has-logo-img {
  background: #ffffff;
  box-shadow: none;
  overflow: hidden;
}
.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.sidebar-brand-text {
  min-width: 0;
}
.sidebar-brand strong {
  display: block;
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.15;
  color: var(--accent);
}
.sidebar-brand strong span { color: var(--orange); }
.sidebar-brand small {
  color: #94a3b8;
  font-size: 10.5px;
  font-weight: 500;
  margin-top: 2px;
  display: block;
  letter-spacing: 0.01em;
}

.sidebar nav,
.sidebar .sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.14) transparent;
}
.nav-group {
  margin-bottom: 12px;
}
.nav-group:last-child {
  margin-bottom: 0;
}
.nav-group-superadmin {
  display: none;
}
body.role-superadmin .nav-group-superadmin {
  display: block;
}
.nav-group-title {
  padding: 6px 10px 5px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0.01em;
  color: #94a3b8;
  user-select: none;
}
.sidebar .menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8.5px 11px;
  margin-bottom: 2px;
  border-radius: 6px;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  border-left: none;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.sidebar .menu-item .nav-svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: #94a3b8;
  transition: color 0.15s ease;
}
.sidebar .menu-item-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar .menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}
.sidebar .menu-item:hover .nav-svg {
  color: #f8fafc;
}
.sidebar .menu-item.active {
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.22) 0%, rgba(var(--accent-rgb), 0.08) 100%);
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--orange);
}
.sidebar .menu-item.active .nav-svg {
  color: var(--orange);
}

.sidebar-footer {
  padding: 12px 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.2);
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  color: var(--accent-light);
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-user-info {
  min-width: 0;
  flex: 1;
}
.sidebar-user-name {
  font-size: 12px;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 10.5px;
  color: #94a3b8;
  font-weight: 500;
}
.btn-logout-corp {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(185, 28, 28, 0.16);
  color: #fca5a5;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-logout-corp svg {
  width: 15px;
  height: 15px;
}
.btn-logout-corp:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
}

.app-shell {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
}
#content {
  flex: 1;
  padding: 20px 24px;
  max-width: 1020px;
}
#content.full-bleed {
  max-width: none;
  padding: 0;
}

.app-footer {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 12px 28px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.app-footer a { color: var(--text-muted); }
.app-footer a:hover { color: var(--orange); }

body.map-mode .app-footer { display: none; }

#toggleMenu {
  display: none;
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1600;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--orange);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1400;
}
.sidebar-backdrop.show { display: block; }

.page-title,
h1.page-title {
  margin-bottom: 4px;
  font-size: 18px;
  font-weight: 700;
  color: #111318;
}
h2, h3 {
  font-size: 15px;
  font-weight: 600;
  color: #161920;
}
.page-sub {
  color: #475569;
  font-size: 13px;
  margin-bottom: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.msg {
  margin-top: 10px;
  padding: 8px 11px;
  font-size: 12px;
  text-align: center;
  display: none;
  border-radius: var(--radius-sm);
}
.msg.ok { display: block; background: #dcfce7; color: var(--ok); }
.msg.err { display: block; background: #fee2e2; color: var(--danger); }
.msg:empty, .msg.ok:empty, .msg.err:empty { display: none !important; padding: 0 !important; margin: 0 !important; border: 0 !important; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  #content { padding: 18px 14px; }
}

@media (max-width: 768px) {
  #toggleMenu { display: block; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .app-shell { margin-left: 0; }
  #content { padding-top: 58px; }
}

/* —— Modo mapa / geocerca —— */
body.map-mode {
  overflow: hidden;
}

body.map-mode .app-shell {
  height: 100vh;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

body.map-mode #content,
body.map-mode #content.full-bleed {
  flex: 1;
  max-width: none;
  padding: 0 !important;
  margin: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.map-mode .app-footer {
  display: none !important;
}

.mapa-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #e8e8e8;
}

.mapa-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.mapa-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  width: 210px;
  max-width: calc(100% - 24px);
  background: #ffffff !important;
  color: #1a1a1a !important;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mapa-panel b {
  font-size: 13px;
  color: #1a1a1a;
}

.mapa-panel span,
.mapa-panel p {
  color: #6b7280;
}

.mapa-panel .btn {
  padding: 7px 10px;
  font-size: 12px;
}

body.map-mode .geo-layout {
  flex: 1;
  height: 100%;
  min-height: 0;
  margin: 0;
  border: none;
}

body.map-mode .geo-map {
  flex: 1;
  min-height: 0;
  height: auto;
}

@media (max-width: 768px) {
  body.map-mode .app-shell {
    margin-left: 0;
  }

  .mapa-panel {
    top: 52px;
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
  }

  .mapa-panel .btn {
    padding: 8px 10px;
    font-size: 12px;
  }

  #toggleMenu {
    background: var(--accent);
    color: #fff;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  }
}

.geo-layout {
  display: flex;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  background: #fff;
}
.geo-map {
  flex: 1;
  min-height: 0;
  min-width: 0;
  background: #eee;
}
.geo-panel {
  width: 320px;
  max-width: 100%;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  background: #fff;
}
@media (max-width: 900px) {
  .geo-layout {
    flex-direction: column;
  }
  .geo-map {
    height: 45vh;
    flex: none;
  }
  .geo-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 55vh;
  }
}

/* Leaflet popups un poco más pulidos */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-popup-content {
  font-size: 12.5px !important;
  line-height: 1.45 !important;
  margin: 10px 12px !important;
}

/* —— Utilitarios adicionales de botones y mensajes —— */
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}
.msg.show {
  display: block;
}

/* Tipografía Inter unificada en tablas y popups de Leaflet */
table, th, td, button, input, select, textarea, .leaflet-container, .leaflet-popup-content {
  font-family: var(--font);
}


/* —— Ocultación síncrona sin parpadeo (0 ms flash) según rol y permisos de usuario —— */
body.role-user #cardSimulador,
body.role-user #cardSimuladorAlertas,
body.role-user #btnAbrirSimulador,
body.role-user #btnConfigCorreoAlertas,
body.role-user #btnSemanalFlotaPdf,
body.role-user #btnSemanalFlotaExcel,
body.role-user #btnBackupTrimestral,
body.role-user #btnOpenModalRegVeh,
body.role-user #thAccionMant,
body.role-user .btn-del-mant {
  display: none !important;
}

body.perm-hide-cuenta #dividerCambiarPass,
body.perm-hide-cuenta #subheadCambiarPass,
body.perm-hide-cuenta #wrapPassActual,
body.perm-hide-cuenta #wrapPassNuevas,
body.perm-hide-cuenta #btnToggleShowPass,
body.perm-hide-cuenta #btnGuardarCuenta {
  display: none !important;
}

body.perm-hide-personales #btnGuardarPersonal {
  display: none !important;
}

body.perm-hide-mantenimiento #cardRegistrarMant,
body.perm-hide-mantenimiento #cardFormMantenimiento {
  display: none !important;
}

body.perm-hide-rep-alertas #cardReporteAlertas,
body.perm-hide-rep-alertas #btnExportarAlertasPdf,
body.perm-hide-rep-alertas #btnExportarAlertasExcel {
  display: none !important;
}

body.perm-hide-rep-historico #exportBar,
body.perm-hide-rep-historico #btnReportePdf,
body.perm-hide-rep-historico #btnExportarExcel {
  display: none !important;
}

body.perm-hide-acciones .btn-card-action,
body.perm-hide-acciones a[href="#/acciones"],
body.perm-hide-acciones a[href^="#/acciones?"],
body.perm-hide-acciones .menu-item[data-route="acciones"] {
  display: none !important;
}

body.perm-hide-geocercas #panelCrearGeocerca,
body.perm-hide-geocercas #formSectionTitle,
body.perm-hide-geocercas #lblNombreGeo,
body.perm-hide-geocercas #nombre,
body.perm-hide-geocercas #lblVehGeo,
body.perm-hide-geocercas #vehiculo,
body.perm-hide-geocercas #rowTipoColorGeo,
body.perm-hide-geocercas #wrapRadio,
body.perm-hide-geocercas #wrapPolyInfo,
body.perm-hide-geocercas #rowActionsGeo,
body.perm-hide-geocercas #dividerCrearGeo {
  display: none !important;
}

body.perm-hide-vehiculos .btn-edit-veh,
body.perm-hide-vehiculos .btn-del-veh,
body.perm-hide-vehiculos [data-edit],
body.perm-hide-vehiculos [data-del] {
  display: none !important;
}


/* —— Escala tipográfica unificada (Inter: 18px / 15px / 13px / 11.5px) y bordes 6px —— */
body, input, select, textarea, button, table, th, td, code, pre, .mpop, .leaflet-container {
  font-family: var(--font) !important;
}
th {
  font-size: 11.5px !important;
  font-weight: 600 !important;
  color: #64748b !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
td {
  font-size: 13px;
  color: #1e293b;
}
#placa, input[name="placas"], input[id*="placa" i] {
  text-transform: uppercase;
}
