/* ============================================================================
   LLANTARTE - Estilos globales
   Paleta extraída de los logos oficiales de ARTE PET COLOMBIA SAS
   ============================================================================ */

:root {
  --verde-primario: #91CC29;
  --verde-primario-rgb: 145, 204, 41;
  --verde-oscuro: #77AF2E;
  --verde-claro: #B8E066;
  --verde-suave: #EEF7DD;
  --negro: #1A1A1A;
  --gris-texto: #4A4A4A;
  --gris-borde: #E2E6DA;
  --gris-fondo: #F7F9F3;
  --blanco: #FFFFFF;
  --rojo-alerta: #D64545;
  --naranja-alerta: #E0922B;
  --amarillo-alerta: #D9B92C;

  --radio-base: 10px;
  --radio-chico: 6px;
  --sombra-card: 0 2px 10px rgba(26, 26, 26, 0.06);
  --sombra-hover: 0 6px 20px rgba(26, 26, 26, 0.10);

  --fuente-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --fuente-display: 'Sora', 'Inter', sans-serif;
}

* { box-sizing: border-box; }

body {
  font-family: var(--fuente-base);
  background-color: var(--gris-fondo);
  color: var(--negro);
  margin: 0;
}

h1, h2, h3, h4, .display {
  font-family: var(--fuente-display);
  font-weight: 700;
  letter-spacing: -0.01em;
}

a { color: var(--verde-oscuro); text-decoration: none; }
a:hover { color: var(--verde-primario); }

/* ---------- Topbar / Sidebar ---------- */
.sidebar {
  background: var(--negro);
  height: 100vh;
  width: 260px;
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform .25s ease;
  overflow: hidden;
}
.sidebar .brand {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar .brand img { height: 38px; }
.sidebar .brand-text {
  color: var(--blanco);
  font-family: var(--fuente-display);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.1;
}
.sidebar .brand-text span { color: var(--verde-primario); }
.sidebar nav {
  padding: 12px 10px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
}
/* Barra de scroll fina y discreta dentro del menú (Chrome/Edge/Firefox) */
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-track { background: transparent; }
.sidebar nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 6px; }
.sidebar nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.3); }
.sidebar nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.sidebar .nav-section-label {
  color: rgba(255,255,255,.35);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 14px 12px 6px;
}
.sidebar .nav-link {
  color: rgba(255,255,255,.78);
  padding: 10px 12px;
  border-radius: var(--radio-chico);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .92rem;
  margin-bottom: 2px;
}
.sidebar .nav-link i { width: 18px; text-align: center; opacity: .85; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: var(--blanco); }
.sidebar .nav-link.active {
  background: var(--verde-primario);
  color: var(--negro);
  font-weight: 600;
}
.sidebar .nav-link.active i { opacity: 1; }

.main-content { margin-left: 260px; padding: 24px 28px 60px; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.topbar .page-title { margin: 0; font-size: 1.5rem; color: var(--negro); }
.topbar .page-subtitle { color: var(--gris-texto); font-size: .9rem; margin-top: 2px; }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-radius: 30px;
  padding: 6px 14px 6px 6px;
}
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--verde-suave); color: var(--verde-oscuro);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}

/* ---------- Cards / KPIs ---------- */
.card-llantarte {
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio-base);
  box-shadow: var(--sombra-card);
  transition: box-shadow .2s ease, transform .2s ease;
}
.card-llantarte:hover { box-shadow: var(--sombra-hover); }

.kpi-card { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi-card .kpi-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--verde-suave); color: var(--verde-oscuro);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; margin-bottom: 12px;
}
.kpi-card .kpi-value { font-family: var(--fuente-display); font-size: 1.9rem; font-weight: 800; color: var(--negro); line-height: 1; }
.kpi-card .kpi-label { color: var(--gris-texto); font-size: .82rem; margin-top: 4px; }
.kpi-card .kpi-trend { font-size: .78rem; font-weight: 600; margin-top: 8px; display: inline-flex; align-items: center; gap: 4px; }
.kpi-card .kpi-trend.up { color: var(--verde-oscuro); }
.kpi-card .kpi-trend.down { color: var(--rojo-alerta); }

/* ---------- Botones ---------- */
.btn-llantarte {
  background: var(--verde-primario);
  color: var(--negro);
  border: none;
  font-weight: 600;
  border-radius: var(--radio-chico);
  padding: 9px 18px;
  transition: background .15s ease, transform .1s ease;
}
.btn-llantarte:hover { background: var(--verde-oscuro); color: var(--blanco); }
.btn-llantarte:active { transform: scale(.98); }
.btn-outline-llantarte {
  background: transparent;
  border: 1.5px solid var(--verde-primario);
  color: var(--verde-oscuro);
  font-weight: 600;
  border-radius: var(--radio-chico);
  padding: 8px 16px;
}
.btn-outline-llantarte:hover { background: var(--verde-suave); }

/* ---------- Badges de estado ---------- */
.badge-estado { font-weight: 600; font-size: .72rem; padding: 4px 10px; border-radius: 20px; }
.badge-pendiente { background: #FFF3DA; color: #97650D; }
.badge-programada { background: #DCEBFF; color: #1C5DBE; }
.badge-en_ruta, .badge-en-ruta { background: #E4DBFF; color: #5B3FBE; }
.badge-recogida { background: var(--verde-suave); color: var(--verde-oscuro); }
.badge-cerrada { background: #E8E8E8; color: #5B5B5B; }
.badge-cancelada { background: #FBE3E3; color: #B23232; }
.badge-riesgo-bajo { background: var(--verde-suave); color: var(--verde-oscuro); }
.badge-riesgo-medio { background: #FFF3DA; color: #97650D; }
.badge-riesgo-alto { background: #FFE2D1; color: #B2521C; }
.badge-riesgo-critico { background: #FBE3E3; color: #B23232; }

/* ---------- Login ---------- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  background: var(--negro);
}
.login-aside {
  flex: 1.1;
  background: radial-gradient(circle at 30% 20%, var(--verde-oscuro), var(--negro) 70%);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 60px;
  color: var(--blanco);
}
.login-aside img { max-width: 320px; margin-bottom: 24px; }
.login-aside p { color: rgba(255,255,255,.7); max-width: 380px; text-align: center; font-size: .95rem; }
.login-form-side {
  flex: 1;
  background: var(--blanco);
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { margin-bottom: 4px; }
.login-card .subtitle { color: var(--gris-texto); margin-bottom: 28px; font-size: .92rem; }
.form-control-llantarte {
  border: 1.5px solid var(--gris-borde);
  border-radius: var(--radio-chico);
  padding: 11px 14px;
  font-size: .95rem;
}
.form-control-llantarte:focus {
  border-color: var(--verde-primario);
  box-shadow: 0 0 0 3px rgba(var(--verde-primario-rgb), .18);
  outline: none;
}

/* Campo de contraseña con botón de mostrar/ocultar (ojito) */
.input-group-password { position: relative; display: flex; }
.input-group-password .form-control-llantarte { padding-right: 42px; }
.btn-toggle-password {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--gris-texto);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
}
.btn-toggle-password:hover { background: var(--gris-fondo); color: var(--verde-oscuro); }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.alert-success, .alert-exito { background: #DFF2C4; color: #3F6618; }
.alert-danger, .alert-error  { background: #FBE3E3; color: #B23232; }
.alert-warning, .alert-aviso { background: #FFF3DA; color: #97650D; }
.alert-info { background: #DCEBFF; color: #1C5DBE; }

.nav-badge {
  background: var(--rojo-alerta); color: #fff; font-size: .65rem; font-weight: 700;
  border-radius: 10px; padding: 1px 7px; margin-left: auto;
}

/* ============================================================================
   RESPONSIVE — el sistema se usa principalmente en celular en campo
   ============================================================================ */

/* Botón hamburguesa: oculto en desktop, visible en móvil */
.btn-menu-toggle {
  display: none;
  background: var(--negro);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: var(--radio-chico);
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* Overlay oscuro detrás del sidebar cuando está abierto en móvil */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
}
.sidebar-overlay.show { display: block; }

/* Tablas: en móvil se convierten en tarjetas apiladas, no scroll horizontal forzado */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Inputs y botones con altura táctil mínima de 44px (estándar de accesibilidad táctil) */
@media (max-width: 767px) {
  .form-control-llantarte, .form-select.form-control-llantarte,
  .btn-llantarte, .btn-outline-llantarte {
    min-height: 44px;
  }
}

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    width: 270px;
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 16px; }
  .btn-menu-toggle { display: flex; align-items: center; justify-content: center; }
  .login-aside { display: none; }
}

@media (max-width: 767px) {
  body { font-size: .95rem; }
  .main-content { padding: 12px; padding-bottom: 32px; }

  /* Topbar se apila: título arriba, acciones y usuario abajo, todo a lo ancho */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .topbar > div:first-child { display: flex; align-items: center; gap: 10px; }
  .topbar > div:last-child {
    display: flex; flex-wrap: wrap; gap: 8px;
    justify-content: space-between; align-items: center;
  }
  .page-title { font-size: 1.2rem; }
  .page-subtitle { font-size: .78rem; }

  /* Botones de acción de topbar (ej. "+ Nuevo establecimiento") a ancho completo */
  .topbar .btn-llantarte, .topbar .btn-outline-llantarte { width: 100%; text-align: center; }
  .topbar > div:last-child > a.btn-llantarte,
  .topbar > div:last-child > a.btn-outline-llantarte { flex: 1 1 100%; order: -1; margin-bottom: 4px; }

  .user-chip { padding: 5px 10px 5px 5px; }
  .user-chip > div:last-child { display: none; } /* ocultar nombre/rol en móvil, queda solo el avatar */

  /* KPIs: 2 columnas en vez de 4, texto más compacto */
  .kpi-card { padding: 14px 16px; }
  .kpi-card .kpi-value { font-size: 1.5rem; }
  .kpi-card .kpi-icon { width: 36px; height: 36px; font-size: 1rem; margin-bottom: 8px; }

  /* Cards con menos padding para aprovechar el ancho */
  .card-llantarte.p-4 { padding: 1rem !important; }
  .card-llantarte.p-3 { padding: .85rem !important; }

  /* Tablas: ocultar columnas secundarias y permitir scroll horizontal suave solo si es necesario */
  .table-responsive table { font-size: .82rem; }
  .table-responsive th, .table-responsive td { padding: .5rem .6rem; white-space: nowrap; }
  .table-responsive td.fw-semibold { white-space: normal; min-width: 110px; }

  /* Mapas Leaflet: un poco más bajos en pantallas chicas para no empujar todo el scroll */
  #mapaUbicacion, #mapaReporte, #mapaSolicitud, #mapaDetalle { height: 240px !important; }
  #mapaVotaderos, #mapaRutas { height: 280px !important; }
  #mapaGeneral { height: calc(100vh - 140px) !important; }

  /* Formularios en 1 sola columna siempre en móvil (Bootstrap ya lo hace col-md-*, refuerzo col-6) */
  .row.g-3 > [class*="col-6"] { flex: 0 0 100%; max-width: 100%; }

  /* Dropdown de acciones en tablas: que no se corte en pantallas chicas */
  .dropdown-menu { font-size: .85rem; }

  /* Login: una sola columna, formulario ocupa toda la pantalla */
  .login-wrapper { flex-direction: column; }
  .login-form-side { padding: 28px 20px; min-height: 100vh; }
  .login-card { max-width: 100%; }

  /* Botones de filtro en formularios GET: apilados a ancho completo */
  .card-llantarte form.row .col-md-2 button,
  .card-llantarte form.row .col-md-3 button { width: 100%; }

  /* Timeline de trazabilidad: vertical en vez de horizontal en móvil */
  .timeline { flex-direction: column; align-items: stretch; gap: 4px; }
  .timeline-step { display: flex; align-items: center; text-align: left; gap: 12px; padding: 6px 0; }
  .timeline-step .dot { margin: 0; flex-shrink: 0; }
  .timeline-step .line {
    position: absolute; left: 20px; top: -6px; width: 3px; height: calc(100% + 12px);
    transform: none;
  }
  .timeline-step .label, .timeline-step .date { text-align: left; }

  /* Gráficos Chart.js: evitar que se compriman demasiado o desborden */
  canvas { max-width: 100% !important; height: auto !important; }
}

@media (max-width: 480px) {
  .kpi-card .kpi-value { font-size: 1.3rem; }
  .brand-text { font-size: .95rem; }
  .login-aside img { max-width: 220px; }
}

/* ============================================================================
   LISTADOS RESPONSIVE: tabla en desktop, tarjetas apiladas en móvil
   Uso: envolver la tabla en <div class="list-table"> y agregar, después de
   la tabla, <div class="list-cards"> con un .list-card por fila.
   ============================================================================ */
.list-cards { display: none; }

.list-card {
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio-base);
  padding: 14px 16px;
  margin-bottom: 10px;
  overflow: hidden;
}
.list-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.list-card-top > div:first-child { min-width: 0; flex: 1 1 auto; }
.list-card-top > .badge-estado { flex-shrink: 0; }
.list-card-title {
  font-weight: 700; font-size: .95rem; color: var(--negro); line-height: 1.25;
  word-break: break-word; overflow-wrap: anywhere;
}
.list-card-subtitle {
  font-size: .78rem; color: var(--gris-texto); margin-top: 2px;
  word-break: break-word; overflow-wrap: anywhere;
}
.list-card-rows { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.list-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: .83rem;
}
.list-card-row .label { color: var(--gris-texto); flex-shrink: 0; }
.list-card-row .value {
  font-weight: 600; color: var(--negro); text-align: right;
  word-break: break-word; overflow-wrap: anywhere; min-width: 0;
}
.list-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--gris-borde);
}
.list-card-actions > * { flex: 1 1 auto; min-width: 0; }
.list-card-empty { text-align: center; color: var(--gris-texto); padding: 28px 16px; }

@media (max-width: 767px) {
  .list-table { display: none; }
  .list-cards { display: block; }
}

/* Asegurar que ningún elemento cause overflow horizontal de toda la página */
html, body { max-width: 100%; overflow-x: hidden; }
img { max-width: 100%; }

/* Utilidad: ocultar columnas/elementos secundarios solo en móvil, para que
   las tablas con muchas columnas no obliguen a hacer scroll horizontal
   (se mantiene como respaldo en tablas que todavía no migraron a tarjetas) */
@media (max-width: 767px) {
  .d-none-mobile { display: none !important; }
}

