/* ==========================================================
   Control Vehicular E/S - estilos propios sobre Bootstrap 5
   ========================================================== */
:root {
    --es-primary: #1d4e89;
    --es-primary-dark: #143a68;
    --bs-primary: #1d4e89;
    --bs-primary-rgb: 29, 78, 137;
    --bs-link-color: #1d4e89;
    --bs-link-color-rgb: 29, 78, 137;
}

body { min-height: 100vh; }

.bg-primary-dark { background-color: var(--es-primary-dark) !important; }

/* ==========================================================
   Estructura: menú lateral fijo + contenido + footer fijo
   ========================================================== */
.app-shell {
    --sidebar-w: 264px;
    --footer-h: 42px;
    --topbar-h: 56px;
    --sidebar-bg: linear-gradient(180deg, #143a68 0%, #0f2c50 100%);
    --sidebar-accent: #f7d117;
    background: #eef2f7;
}
.app-shell.theme-platform {
    --sidebar-bg: linear-gradient(180deg, #23272b 0%, #16181b 100%);
    --sidebar-accent: #4dabf7;
}

/* Barra superior: usuario y cierre de sesión (en móvil también el botón de menú) */
.app-topbar {
    position: sticky; top: 0; z-index: 1025;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1rem;
    background: var(--topbar-bg);
    color: rgb(var(--topbar-fg-rgb));
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
/* Valores predeterminados; /marca/tema.css los reemplaza con los colores de la empresa */
.app-shell {
    --topbar-bg: linear-gradient(90deg, #1d4e89 0%, #143a68 100%);
    --topbar-fg-rgb: 255, 255, 255;
    --sidebar-fg-rgb: 255, 255, 255;
    --accent-fg: #10233f;
}
.app-shell.theme-platform { --topbar-bg: linear-gradient(90deg, #343a40 0%, #212529 100%); }
.app-topbar-toggle, .app-topbar-toggle:hover { color: rgb(var(--topbar-fg-rgb)); }
.app-topbar-brand, .app-topbar-brand:hover { color: rgb(var(--topbar-fg-rgb)); font-weight: 600; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.app-topbar-muted { color: rgba(var(--topbar-fg-rgb), .7); }
.app-topbar-user { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.app-topbar .btn-topbar { color: rgb(var(--topbar-fg-rgb)); border: 1px solid rgba(var(--topbar-fg-rgb), .45); background: transparent; }
.app-topbar .btn-topbar:hover { background: rgba(var(--topbar-fg-rgb), .15); color: rgb(var(--topbar-fg-rgb)); }
.app-topbar .app-btn-salir:hover { background: #dc3545; border-color: #dc3545; color: #fff; }
.app-topbar-who { max-width: 240px; }
.app-topbar-user .btn { white-space: nowrap; }

/* Menú lateral */
.app-sidebar { --bs-offcanvas-width: 280px; border-right: 0 !important; }
.sidebar-inner {
    height: 100%;
    display: flex; flex-direction: column;
    background: var(--sidebar-bg);
    color: rgba(var(--sidebar-fg-rgb), .85);
}
.sidebar-brand {
    display: flex; align-items: center; gap: .5rem;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(var(--sidebar-fg-rgb), .08);
}
.sidebar-logo {
    width: 40px; height: 40px; flex: 0 0 40px;
    border-radius: .7rem;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(var(--sidebar-fg-rgb), .12); color: rgb(var(--sidebar-fg-rgb)); font-size: 1.3rem;
}
.sidebar-brand-name { max-width: 170px; }
/* Logo corporativo */
.sidebar-logo-img {
    display: inline-flex; align-items: center; justify-content: center;
    height: 44px; max-width: 150px; flex: 0 0 auto;
    border-radius: .5rem; padding: 4px;
}
.sidebar-logo-img img { max-height: 100%; max-width: 100%; object-fit: contain; display: block; }
.sidebar-logo-img.blanco { background: #fff; padding: 4px 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.app-topbar-logo { height: 30px; max-width: 110px; object-fit: contain; }
.app-topbar-logo.blanco { background: #fff; border-radius: .35rem; padding: 2px 6px; }
.sidebar-muted { color: rgba(var(--sidebar-fg-rgb), .55); font-size: .78rem; }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: .75rem .6rem; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(var(--sidebar-fg-rgb), .15); border-radius: 3px; }
.sidebar-section {
    margin: 1rem .6rem .35rem;
    font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
    color: rgba(var(--sidebar-fg-rgb), .45);
}
.sidebar-link {
    position: relative;
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .75rem; margin-bottom: 2px;
    border-radius: .5rem;
    color: rgba(var(--sidebar-fg-rgb), .82);
    text-decoration: none; font-size: .93rem;
    transition: background-color .15s, color .15s;
}
.sidebar-link > .bi:first-child { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .9; }
.sidebar-link > span { flex: 1 1 auto; }
.sidebar-link:hover, .sidebar-link:focus-visible { background: rgba(var(--sidebar-fg-rgb), .08); color: rgb(var(--sidebar-fg-rgb)); }
.sidebar-link.active { background: rgba(var(--sidebar-fg-rgb), .15); color: rgb(var(--sidebar-fg-rgb)); font-weight: 600; }
.sidebar-link.active::before {
    content: ""; position: absolute; left: -.6rem; top: 20%; bottom: 20%;
    width: 4px; border-radius: 0 4px 4px 0; background: var(--sidebar-accent);
}
.sidebar-toggle.open { color: rgb(var(--sidebar-fg-rgb)); }
.sidebar-caret { font-size: .75rem; transition: transform .2s; }
.sidebar-toggle:not(.collapsed) .sidebar-caret { transform: rotate(180deg); }
.sidebar-sub { margin: 0 0 .25rem 1.05rem; padding-left: .55rem; border-left: 1px solid rgba(var(--sidebar-fg-rgb), .12); }
.sidebar-sub .sidebar-link { font-size: .87rem; padding: .42rem .65rem; }
.sidebar-sub .sidebar-link.active::before { left: -.62rem; }

.sidebar-avatar {
    width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--sidebar-accent); color: var(--accent-fg); font-weight: 700; font-size: .85rem;
}

/* Contenido */
.app-content {
    padding: 1.25rem 1rem calc(var(--footer-h) + 1.5rem);
    max-width: 1600px;
    margin: 0 auto;
}

/* Footer fijo */
.app-footer {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1020;
    height: var(--footer-h);
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0 1rem;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, .08);
    box-shadow: 0 -2px 6px rgba(0, 0, 0, .04);
    font-size: .8rem; color: var(--bs-secondary-color);
}

/* Escritorio: menú fijo a la izquierda */
@media (min-width: 992px) {
    .app-sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 1030;
        width: var(--sidebar-w);
        box-shadow: 2px 0 10px rgba(0, 0, 0, .12);
    }
    .app-main { margin-left: var(--sidebar-w); }
    .app-topbar { margin-left: var(--sidebar-w); padding: 0 2rem; }
    .app-content { padding: 1.75rem 2rem calc(var(--footer-h) + 1.75rem); }
    .app-footer { left: var(--sidebar-w); padding: 0 2rem; }
}

.btn-primary {
    --bs-btn-bg: var(--es-primary);
    --bs-btn-border-color: var(--es-primary);
    --bs-btn-hover-bg: var(--es-primary-dark);
    --bs-btn-hover-border-color: var(--es-primary-dark);
    --bs-btn-active-bg: var(--es-primary-dark);
    --bs-btn-disabled-bg: var(--es-primary);
    --bs-btn-disabled-border-color: var(--es-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--es-primary);
    --bs-btn-border-color: var(--es-primary);
    --bs-btn-hover-bg: var(--es-primary);
    --bs-btn-hover-border-color: var(--es-primary);
    --bs-btn-active-bg: var(--es-primary);
    --bs-btn-active-border-color: var(--es-primary);
}
.btn-check:checked + .btn-outline-primary { color: #fff; }

/* ---- Acceso ---- */
.auth-bg {
    background: linear-gradient(135deg, #143a68 0%, #1d4e89 55%, #2a9d8f 100%);
    min-height: 100vh;
}
.brand-circle {
    width: 72px; height: 72px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--es-primary); color: #fff; font-size: 2rem;
}
.brand-dark { background: #212529; }

/* ---- Indicadores ---- */
.kpi .card-body { position: relative; container-type: inline-size; }
.kpi-icon {
    width: 40px; height: 40px; border-radius: .6rem;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.2rem; margin-bottom: .5rem;
}
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
/* Cifras largas (kg) en tarjetas angostas: se reducen en vez de partirse en dos líneas. */
.kpi-value-largo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@supports (font-size: 1cqi) {
    .kpi-value-largo { font-size: clamp(1rem, 17cqi, 1.6rem); }
}
.kpi-label { font-size: .8rem; color: var(--bs-secondary-color); }

.chart-box { position: relative; height: 280px; }

/* ---- Placas estilo Colombia ---- */
.placa {
    display: inline-block;
    font-family: "Arial Narrow", Arial, sans-serif;
    font-weight: 700; letter-spacing: .08em;
    background: #f7d117; color: #111;
    border: 2px solid #111; border-radius: .3rem;
    padding: 0 .4rem; font-size: .85rem; line-height: 1.5;
}
.placa-lg { font-size: 1.3rem; padding: .1rem .7rem; }
.placa-input { font-weight: 700; letter-spacing: .15em; }

/* ---- Tablas ---- */
tr.clickable { cursor: pointer; }
.cell-max { max-width: 220px; }
.audit-json { white-space: pre-wrap; max-width: 420px; max-height: 260px; overflow: auto; }

/* ---- Módulos por usuario ---- */
.module-option { cursor: pointer; }
.module-option:has(input:checked) { border-color: var(--es-primary) !important; background: rgba(var(--bs-primary-rgb), .05); }

/* ---- Imagen corporativa: textos según el fondo elegido ---- */
.sidebar-fg { color: rgb(var(--sidebar-fg-rgb)); }
.sidebar-brand .btn-close { filter: var(--sidebar-close-filter, invert(1) grayscale(100%) brightness(200%)); }

.informe-logo { max-height: 60px; max-width: 180px; object-fit: contain; }

/* Pantalla Apariencia */
.logo-actual {
    width: 220px; height: 90px; border-radius: .6rem; border: 1px dashed var(--bs-border-color);
    display: flex; align-items: center; justify-content: center; text-align: center; padding: .5rem;
}
.logo-actual img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-fondo-oscuro { background: #143a68; }
.paleta-muestra { display: inline-block; width: 34px; height: 14px; border-radius: 3px; vertical-align: middle; border: 1px solid rgba(0, 0, 0, .1); }
@media (min-width: 1200px) { .preview-card.sticky-xl-top { top: calc(var(--topbar-h, 56px) + 1rem); z-index: 1; } }
.theme-preview {
    display: flex; height: 280px; border-radius: .6rem; overflow: hidden;
    border: 1px solid var(--bs-border-color); background: #eef2f7;
    font-family: var(--pv-font); font-size: var(--pv-size);
}
.pv-sidebar { width: 42%; padding: .6rem .5rem; background: var(--pv-sidebar); color: var(--pv-sidebar-fg); }
.pv-brand { display: flex; align-items: center; gap: .4rem; margin-bottom: .6rem; font-weight: 600; font-size: .85em; }
.pv-logo { height: 30px; max-width: 80px; display: inline-flex; align-items: center; justify-content: center; border-radius: .35rem; }
.pv-logo img { max-height: 100%; max-width: 100%; object-fit: contain; }
.pv-logo-icono { width: 30px; background: rgba(255, 255, 255, .15); }
.pv-logo-blanco { background: #fff; padding: 2px 5px; }
.pv-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-link { padding: .3rem .45rem; border-radius: .35rem; margin-bottom: 2px; font-size: .82em; opacity: .9; position: relative; }
.pv-active { background: rgba(255, 255, 255, .15); font-weight: 600; opacity: 1; box-shadow: inset 3px 0 0 var(--pv-accent); }
.pv-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pv-topbar { display: flex; align-items: center; justify-content: flex-end; gap: .35rem; padding: .45rem .6rem; background: var(--pv-topbar); color: var(--pv-topbar-fg); font-size: .8em; }
.pv-avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--pv-accent); color: var(--pv-accent-fg); font-size: .65em; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.pv-body { padding: .8rem; }
.pv-title { font-weight: 700; margin-bottom: .3rem; }
.pv-text { font-size: .85em; color: #4b5563; }
.pv-enlace { color: var(--pv-primary); text-decoration: underline; }
.pv-btn { display: inline-block; padding: .3rem .7rem; border-radius: .35rem; background: var(--pv-primary); color: var(--pv-primary-fg); font-size: .82em; }

/* ---- Submódulos ---- */
.submodulos .form-check { margin-bottom: .35rem; }
.submodulo-desc { font-size: .78rem; }

/* ---- Planes ---- */
.plan-info { background: var(--bs-tertiary-bg); border-radius: .4rem; padding: .5rem .65rem; }

/* ---- Requisitos de contraseña ---- */
.password-strength { height: 6px; }
.password-strength .progress-bar { transition: width .25s, background-color .25s; }
.password-strength-label { min-width: 80px; text-align: right; font-weight: 600; }
.password-rules li { color: var(--bs-secondary-color); padding: 1px 0; transition: color .15s; }
.password-rules li.ok { color: var(--bs-success); }
.password-rules li.fail { color: var(--bs-danger); }
.password-rules .bi { margin-right: .3rem; }

/* ---- Cargue masivo ---- */
@media (min-width: 992px) {
    .import-form.sticky-lg-top { top: calc(var(--topbar-h, 56px) + 1rem); z-index: 1; }
}
.import-errors { max-height: 320px; overflow-y: auto; }

/* ---- Móvil: acciones fijas al pie en formularios largos ---- */
@media (max-width: 767.98px) {
    .sticky-actions {
        position: sticky; bottom: var(--footer-h, 0); z-index: 10;
        background: #eef2f7; padding: .75rem 0;
    }
    .kpi-value:not(.kpi-value-largo) { font-size: 1.35rem; }
    .chart-box { height: 230px; }
}

/* ---- Impresión ---- */
@media print {
    .app-sidebar, .app-topbar, .app-footer, footer, .btn, form, .d-print-none { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; max-width: none; }
    body, .app-shell, .bg-body-tertiary { background: #fff !important; }
    .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; break-inside: avoid; }
    .placa { border-width: 1px; }
    a { text-decoration: none; color: inherit; }
}

/* ---- Foto del conductor ---------------------------------------------- */
.foto-conductor {
    width: 72px;
    height: 72px;
    flex: 0 0 auto;
    border-radius: .5rem;
    object-fit: cover;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-tertiary-bg);
}
.foto-conductor-lg { width: 120px; height: 120px; }
.foto-vacia {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--bs-secondary-color);
}
.foto-vacia.d-none { display: none !important; }
.foto-vacia-txt { font-size: .7rem; line-height: 1; margin-top: .15rem; }
.min-w-0 { min-width: 0; }
@media print { .foto-conductor { border-color: #999; } }

/* ---- Términos de la licencia ----------------------------------------- */
.terminos-doc { max-width: 52rem; line-height: 1.6; }
.terminos-doc p, .terminos-doc li { text-align: justify; }
.terminos-scroll { max-height: 65vh; overflow-y: auto; }
@media print { .terminos-scroll { max-height: none; overflow: visible; } }

/* ---- Centro de ayuda --------------------------------------------------- */
.ayuda-card { transition: transform .12s ease, box-shadow .12s ease; }
.ayuda-card:hover { transform: translateY(-2px); box-shadow: 0 .5rem 1rem rgba(0,0,0,.08) !important; }
.ayuda-icono {
    flex: 0 0 auto; width: 2.75rem; height: 2.75rem; border-radius: .75rem;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem;
    color: var(--es-primary, var(--bs-primary)); background: rgba(var(--bs-primary-rgb), .1);
}
.ayuda-doc { max-width: 54rem; line-height: 1.65; }
.ayuda-doc ol, .ayuda-doc ul { padding-left: 1.4rem; }
.ayuda-doc li { margin-bottom: .25rem; }
.ayuda-figura { margin: 1rem 0 1.5rem; }
.ayuda-figura img {
    max-width: 100%; height: auto; border-radius: .5rem;
    border: 1px solid var(--bs-border-color); box-shadow: 0 .25rem .75rem rgba(0,0,0,.08);
}
.ayuda-figura figcaption { font-size: .85rem; color: var(--bs-secondary-color); margin-top: .4rem; }
.ayuda-indice { position: sticky; top: 5rem; }
.ayuda-indice .list-group-item.active { background: var(--es-primary, var(--bs-primary)); border-color: var(--es-primary, var(--bs-primary)); }
.ayuda-doc > :first-child { margin-top: 0 !important; }

/* ---- Subpermisos en el formulario de roles ---------------------------- */
.permisos-hijos {
    margin-left: 1.6rem; padding-left: .75rem; border-left: 2px solid var(--bs-border-color);
}
.perm-hijo { margin-bottom: .35rem; }
.perm-acciones { margin-top: .15rem; }
.perm-acciones .form-check-inline { margin-right: .9rem; }
.perm-acciones .form-check-input:disabled + .form-check-label { opacity: .55; }

/* ---- Facturación ------------------------------------------------------- */
.col-cantidad { width: 7rem; }
.col-valor { width: 11rem; }
.factura-doc { max-width: 52rem; }
.factura-doc .table tfoot td { border-bottom-width: 0; }
@media print { .factura-doc { max-width: none; font-size: 11pt; } }

/* ---- Código de verificación (dos pasos) ------------------------------ */
.otp-input { font-size: 1.75rem; letter-spacing: .5rem; font-variant-numeric: tabular-nums; }
.otp-boxes { display: flex; justify-content: center; gap: .5rem; }
.otp-recordar { background: var(--bs-tertiary-bg); border-radius: .5rem; padding: .6rem .75rem .6rem 2.25rem; }
.otp-box {
    width: 3rem; height: 3.5rem; padding: 0; flex: 0 1 3rem; min-width: 0;
    text-align: center; font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums;
    border-width: 2px; border-radius: .6rem; caret-color: var(--es-primary, var(--bs-primary));
}
.otp-box:focus { border-color: var(--es-primary, var(--bs-primary)); box-shadow: 0 0 0 .2rem rgba(var(--bs-primary-rgb), .2); }
.otp-box.lleno { border-color: var(--es-primary, var(--bs-primary)); }
.otp-boxes .otp-box:nth-child(3) { margin-right: .5rem; } /* 3 + 3, más fácil de leer */
@media (max-width: 380px) { .otp-boxes { gap: .3rem; } .otp-box { height: 3rem; font-size: 1.35rem; } }
