/* ============================================================
   COOTRACEN — Sistema de Gestión
   Cooperativa de Transporte Centenario
   ============================================================ */

:root {
    --primary:        #1565C0;
    --primary-dark:   #0D47A1;
    --primary-light:  #1976D2;
    --accent:         #FF8F00;
    --accent-light:   #FFB300;
    --sidebar-bg:     #0D1B2A;
    --sidebar-width:  260px;
    --navbar-height:  60px;
    --text-muted-sidebar: rgba(255,255,255,.45);
    --sidebar-hover:  rgba(255,255,255,.07);
    --sidebar-active: rgba(21,101,192,.35);
    --surface:        #F5F7FA;
    --card-shadow:    0 2px 12px rgba(0,0,0,.08);
}

/* ── Reset / Body ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body.app-body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--surface);
    color: #212529;
    margin: 0;
    overflow-x: hidden;
}

/* ── Navbar ────────────────────────────────────────────────── */
.app-navbar {
    height: var(--navbar-height);
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
    z-index: 1050;
    padding: 0 1rem;
}

.brand-icon {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #fff;
    flex-shrink: 0;
}

.brand-logo-img {
    width: 36px; height: 36px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
}

.brand-name {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: .05em;
    color: #fff;
    line-height: 1.1;
}

.brand-sub {
    font-size: .65rem;
    color: rgba(255,255,255,.6);
    letter-spacing: .03em;
    line-height: 1;
}

.navbar-toggler-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background .2s;
}
.navbar-toggler-btn:hover { background: rgba(255,255,255,.1); }

.user-menu-btn {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    color: #fff;
    display: flex; align-items: center; gap: 8px;
    padding: 5px 10px;
    border-radius: 30px;
    transition: background .2s;
}
.user-menu-btn:hover { background: rgba(255,255,255,.2); color: #fff; }
.user-menu-btn::after { border-top-color: rgba(255,255,255,.7); }

.user-avatar-sm {
    width: 28px; height: 28px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-avatar-xs {
    width: 34px; height: 34px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

/* ── Layout ────────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    padding-top: var(--navbar-height);
    min-height: 100vh;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: calc(100vh - var(--navbar-height));
    transition: margin-left .3s ease;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .3s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}
.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.sidebar-inner { display: flex; flex-direction: column; height: 100%; }

.sidebar-nav { flex: 1; padding: 1rem 0; }

.nav-section { padding: 0 0 .5rem; }

.nav-section-title {
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted-sidebar);
    padding: .75rem 1.25rem .25rem;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: .5rem 1.25rem;
    color: rgba(255,255,255,.75);
    font-size: .875rem;
    border-radius: 0;
    transition: all .2s;
    white-space: nowrap;
    overflow: hidden;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
    border-left-color: var(--accent);
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
    border-left-color: var(--accent);
}

.nav-icon {
    width: 18px;
    text-align: center;
    font-size: .9rem;
    flex-shrink: 0;
    opacity: .8;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.08);
    background: rgba(0,0,0,.15);
}

.xsmall { font-size: .68rem; }

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1039;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #e8ecf0;
    border-radius: 12px 12px 0 0 !important;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Stat Cards */
.stat-card {
    border-radius: 14px;
    border: none;
    box-shadow: var(--card-shadow);
    overflow: hidden;
    transition: transform .2s, box-shadow .2s;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

.stat-icon {
    width: 56px; height: 56px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
}

.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: .8rem; color: #6c757d; font-weight: 500; }

/* ── Tables ────────────────────────────────────────────────── */
.table { font-size: .875rem; }
.table th {
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: #6c757d;
    border-bottom: 2px solid #e8ecf0;
    white-space: nowrap;
    padding: .75rem 1rem;
}
.table td { padding: .75rem 1rem; vertical-align: middle; }
.table-hover tbody tr:hover { background: #f0f4ff; }

/* Tabla densa de Vehículos (muchas columnas: docs, asociado, conductor...).
   Compacta en escritorio; en móvil se sirve como tarjetas (table-mobile-cards)
   y necesita texto de tamaño normal, no el compacto de escritorio. */
.vehiculos-table { font-size: .82rem; min-width: 900px; }
.vehiculo-sub { font-size: .72rem; }
.vehiculo-doc-badge { font-size: .68rem; }

/* ── Badges ────────────────────────────────────────────────── */
.badge-sm { font-size: .65rem; padding: 2px 6px; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn { border-radius: 8px; font-size: .875rem; font-weight: 500; }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-sm { padding: .25rem .65rem; font-size: .8rem; border-radius: 6px; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-control, .form-select {
    border-radius: 8px;
    border-color: #dee2e6;
    font-size: .875rem;
    padding: .5rem .85rem;
    transition: border-color .2s, box-shadow .2s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(21,101,192,.15);
}
.form-label { font-size: .825rem; font-weight: 600; color: #495057; margin-bottom: .3rem; }

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
    margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-header .breadcrumb { font-size: .8rem; margin: 0; }

/* ── Login Page ────────────────────────────────────────────── */
body.login-page {
    background: linear-gradient(135deg, #0D1B2A 0%, #1565C0 50%, #0D47A1 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-wrapper {
    width: 100%;
    max-width: 440px;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 2.5rem 2rem 2rem;
    text-align: center;
    color: #fff;
}

.login-logo {
    width: 72px; height: 72px;
    background: var(--accent);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
    box-shadow: 0 8px 20px rgba(0,0,0,.2);
}

.login-logo.login-logo-img {
    background: #fff;
    padding: 8px;
}
.login-logo-img img {
    width: 100%; height: 100%;
    object-fit: contain;
}

.login-title { font-size: 1.5rem; font-weight: 800; margin: 0; }
.login-subtitle { font-size: .8rem; opacity: .8; margin-top: .25rem; }

.login-body { padding: 2rem; }

.login-body .form-control {
    padding: .65rem 1rem .65rem 2.8rem;
    font-size: .9rem;
}

.input-icon-wrap { position: relative; }
.input-icon-wrap .icon {
    position: absolute;
    left: .9rem;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa;
    font-size: .9rem;
}

.btn-login {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    color: #fff;
    width: 100%;
    padding: .75rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 10px;
    letter-spacing: .03em;
    transition: all .2s;
    box-shadow: 0 4px 15px rgba(21,101,192,.35);
}
.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(21,101,192,.5);
    color: #fff;
}

.login-footer {
    padding: 1rem 2rem;
    background: #f8f9fa;
    border-top: 1px solid #eee;
    font-size: .75rem;
    color: #aaa;
    text-align: center;
}

/* ── Dispatch Badge Colors ─────────────────────────────────── */
.badge-despacho-con_auxiliar       { background: #1565C0; color: #fff; }
.badge-despacho-sin_auxiliar       { background: #2E7D32; color: #fff; }
.badge-despacho-taller_con_auxiliar{ background: #6A1B9A; color: #fff; }
.badge-despacho-taller_sin_auxiliar{ background: #E65100; color: #fff; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .sidebar-overlay.show {
        display: block;
    }
    .app-main {
        margin-left: 0;
    }
}

/* Tablets y móviles grandes */
@media (max-width: 767.98px) {
    .app-main .container-fluid { padding: 1rem .85rem; }

    .page-header { margin-bottom: 1rem; }
    .page-header h1 { font-size: 1.2rem; }
    .page-header .btn { width: 100%; justify-content: center; }
    .page-header > div:last-child:not(:first-child) { width: 100%; }

    .card-header { padding: .75rem 1rem; font-size: .95rem; }
    .card-body { padding: 1rem; }

    .stat-value { font-size: 1.35rem; }
    .stat-icon { width: 44px; height: 44px; font-size: 1.15rem; }

    /* En móvil las tablas normales (sin table-mobile-cards) siguen mostrando
       scroll horizontal, así que no tiene sentido encoger más la letra: se
       agranda para que sea legible tocando/haciendo zoom con el dedo. */
    .table { font-size: .95rem; }
    .table th, .table td { padding: .6rem .65rem; }

    /* Las tablas convertidas a tarjetas (table-mobile-cards) usan tamaño de
       letra cómodo de lectura, no el compacto pensado para escritorio. */
    .vehiculos-table { font-size: 1rem; min-width: 0; }
    .vehiculo-sub { font-size: .85rem; }
    .vehiculo-doc-badge { font-size: .75rem; }

    .despacho-total-row { font-size: 1rem; }

    /* Formularios: texto de 16px mínimo evita el zoom automático de iOS al
       enfocar un campo, y es más cómodo de tocar en cualquier móvil. */
    .form-control, .form-select { font-size: 1rem; }
    .form-label { font-size: .9rem; }

    /* Botones de acción al final de formularios: ancho completo y apilados */
    form .mt-4.d-flex.gap-2,
    form .d-flex.gap-2.align-items-center.flex-wrap { flex-wrap: wrap; }
    form .mt-4.d-flex.gap-2 > .btn,
    form .mt-4.d-flex.gap-2 > a.btn { flex: 1 1 auto; }

    /* Filtros en card (row g-2 align-items-end) */
    .card form.row.g-2 .col-auto { width: 100%; }
    .card form.row.g-2 .col-auto .form-control,
    .card form.row.g-2 .col-auto .form-select { width: 100%; }

    /* Tablas -> tarjetas apiladas (evita el scroll horizontal en móvil).
       Requiere clase "table-mobile-cards" en el <table> y atributo
       data-label="Encabezado" en cada <td> del <tbody> (vacío en columnas
       de acciones, para no repetir "Acciones:" antes de los botones). */
    .table-mobile-cards { min-width: 0 !important; }
    .table-mobile-cards thead { display: none; }
    .table-mobile-cards, .table-mobile-cards tbody { display: block; width: 100%; }
    .table-mobile-cards tr {
        display: block;
        width: 100%;
        margin-bottom: .75rem;
        border: 1px solid var(--bs-border-color, #dee2e6);
        border-radius: .5rem;
        padding: .25rem .85rem;
        background: #fff;
    }
    .table-mobile-cards tr:last-child { margin-bottom: 0; }
    .table-mobile-cards td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .75rem;
        text-align: right;
        padding: .5rem 0;
        border: 0;
        border-bottom: 1px solid #f1f3f5;
    }
    .table-mobile-cards td:last-child { border-bottom: 0; }
    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: .82rem;
        color: #6c757d;
        text-align: left;
        flex-shrink: 0;
    }
    .table-mobile-cards td[data-label=""]::before,
    .table-mobile-cards td:not([data-label])::before { content: none; }
    .table-mobile-cards td[data-label=""] { justify-content: center; }
    .table-responsive:has(.table-mobile-cards) { overflow-x: visible; }
}

/* Teléfonos pequeños */
@media (max-width: 575.98px) {
    .brand-sub { display: none; }
    .brand-name { font-size: .95rem; }
    .app-navbar { padding: 0 .65rem; }

    .page-header h1 { font-size: 1.15rem; }
    .page-header .breadcrumb { font-size: .78rem; }

    .stat-value { font-size: 1.25rem; }
    .stat-label { font-size: .78rem; }

    .btn { font-size: .875rem; }
    .btn-lg { font-size: .95rem; padding: .6rem 1rem; }

    /* DataTables: buscador y longitud apilados ya usan col-sm-6 → full width aquí */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length { text-align: left !important; margin-bottom: .5rem; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; margin-left: 0 !important; margin-top: .25rem; }

    .login-wrapper { padding: .5rem; }
    .login-header { padding: 1.75rem 1.25rem 1.5rem; }
    .login-body { padding: 1.25rem; }
}

/* ── Animations ─────────────────────────────────────────────── */
.fade-in {
    animation: fadeIn .3s ease-in-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Despacho Detail ────────────────────────────────────────── */
.despacho-detail-row {
    display: flex;
    justify-content: space-between;
    padding: .45rem 0;
    border-bottom: 1px dashed #e9ecef;
    font-size: .875rem;
}
.despacho-detail-row:last-child { border-bottom: none; }
.despacho-total-row {
    display: flex;
    justify-content: space-between;
    padding: .75rem 0 0;
    margin-top: .5rem;
    border-top: 2px solid var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-dark);
}
