/* ==========================================================
   PaqueteTrack — Estilos v3
   Mobile-first · Primary #2563EB · Accent #EA580C
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Fira+Code:wght@400;500;700&display=swap');

/* ── Variables ──────────────────────────────────────────── */
:root {
    --sw: 256px;          /* sidebar width */
    --th: 56px;           /* topbar height */
    --bh: 62px;           /* bottom nav height */

    --sbg: #0f172a;       /* sidebar bg */
    --stx: #94a3b8;       /* sidebar text */

    --p:   #2563EB;       /* primary */
    --pd:  #1D4ED8;       /* primary dark */
    --pl:  #DBEAFE;       /* primary light */
    --a:   #EA580C;       /* accent */

    --bg:  #f0f4ff;
    --c:   #ffffff;       /* card */
    --br:  #e2e8f0;       /* border */
    --brl: #f1f5f9;       /* border light */
    --tx:  #0f172a;
    --tm:  #64748b;       /* text muted */

    --r:   10px;
    --rl:  14px;
    --rx:  18px;
    --s1:  0 1px 3px rgba(0,0,0,.07);
    --s2:  0 4px 16px rgba(0,0,0,.10);
    --s3:  0 12px 40px rgba(0,0,0,.14);
    --t:   .2s ease;
}

/* ── Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--tx);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

img, svg { max-width: 100%; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-body {
    min-height: 100dvh;
    background: linear-gradient(145deg,#0f172a 0%,#1e293b 50%,#1e3a8a 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
    background: #fff;
    border-radius: var(--rx);
    padding: 2rem 1.75rem 1.75rem;
    box-shadow: 0 32px 64px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.06);
}

.login-logo { text-align: center; margin-bottom: 1.75rem; }


.login-icon i { font-size: 2rem; color: #fff; }

.login-logo h2 { margin: 0 0 .2rem; font-size: 1.5rem; font-weight: 800; letter-spacing: -.5px; }
.login-logo p  { margin: 0; font-size: .875rem; color: var(--tm); }

.login-card .form-control  { height: 44px; font-size: .9rem; }
.login-card .input-group-text { width: 44px; justify-content: center; }

.btn-login {
    height: 48px; width: 100%; font-size: 1rem; font-weight: 700;
    background: linear-gradient(135deg,var(--p),var(--pd));
    border: none; border-radius: var(--r); color: #fff;
    box-shadow: 0 4px 14px rgba(37,99,235,.35);
    transition: var(--t);
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37,99,235,.45); color: #fff; }

.login-footer { text-align: center; margin-top: .65rem; color: rgba(255,255,255,.35); font-size: .78rem; }

.pwa-install-btn {
    display: none; width: 100%; height: 42px; margin-top: .6rem;
    border-radius: var(--r); font-size: .85rem; font-weight: 600;
    background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.25);
    color: rgba(255,255,255,.75); transition: var(--t);
}
.pwa-install-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ============================================================
   LAYOUT — sidebar fijo + main-content con margin
   ============================================================ */

/* Sidebar — siempre fuera de pantalla en mobile */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sw);
    background: var(--sbg);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1), box-shadow .28s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.07) transparent;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); }

/* Sidebar visible en desktop */
@media (min-width: 992px) {
    .sidebar { transform: none; box-shadow: none; }
}

/* Sidebar abierto (mobile — via JS) */
.sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 40px rgba(0,0,0,.5);
}

/* Brand */
.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1rem 1.25rem 1rem 1.4rem;
    color: #fff; text-decoration: none; flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,.06);
    transition: background var(--t);
}
.sidebar-brand:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar-brand i { font-size: 1.5rem; color: var(--p); flex-shrink: 0; }
.sidebar-brand span { font-size: 1.05rem; font-weight: 800; letter-spacing: -.4px; }

/* Nav links */
.sidebar-nav { flex: 1; padding: .4rem 0; }

.nav-section-title {
    padding: .7rem 1.4rem .2rem;
    font-size: .62rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1.4px;
    color: #334155;
}

.sidebar .nav-link {
    display: flex; align-items: center; gap: .65rem;
    padding: .58rem 1.4rem;
    color: var(--stx); text-decoration: none;
    font-size: .85rem; font-weight: 500;
    border-right: 3px solid transparent;
    min-height: 44px;
    transition: background var(--t), color var(--t);
}
.sidebar .nav-link i { font-size: 1.05rem; width: 20px; flex-shrink: 0; opacity: .75; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.sidebar .nav-link:hover i { opacity: 1; }
.sidebar .nav-link.active {
    background: rgba(37,99,235,.18); color: #93c5fd;
    border-right-color: var(--p);
}
.sidebar .nav-link.active i { opacity: 1; }

/* User area */
.sidebar-user {
    display: flex; align-items: center; gap: .65rem;
    padding: .85rem 1rem .85rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0;
}
.sidebar-logout {
    margin-left: auto; color: #475569; text-decoration: none;
    font-size: 1.1rem; padding: .3rem; border-radius: 6px;
    transition: color var(--t);
}
.sidebar-logout:hover { color: #ef4444; }

/* Overlay oscuro */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
    z-index: 1035;
}
.sidebar-overlay.show { display: block; }

/* Main content
   Solución correcta: margin-left simple (sidebar es position:fixed).
   NO usar flex en wrapper — el sidebar fixed no participa en el flujo flex
   y haría que main-content tuviera 100% ancho + el margin → overflow. */
.main-content {
    margin-left: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}

@media (min-width: 992px) {
    .main-content { margin-left: var(--sw); }
}

/* Topbar */
.topbar {
    position: sticky; top: 0; z-index: 900;
    height: var(--th);
    background: #fff;
    border-bottom: 1px solid var(--br);
    box-shadow: var(--s1);
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1rem;
    flex-shrink: 0;
}

.topbar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    font-size: 1.5rem; color: var(--tm);
    width: 40px; height: 40px; border-radius: 8px;
    transition: background var(--t), color var(--t);
    flex-shrink: 0;
}
.topbar-toggle:hover { background: var(--brl); color: var(--tx); }

/* Ocultar hamburger en desktop (sidebar siempre visible) */
@media (min-width: 992px) { .topbar-toggle { display: none; } }

.topbar-title {
    flex: 1; font-size: .95rem; font-weight: 700; color: var(--tx);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
}

.topbar-actions {
    display: flex; align-items: center; gap: .5rem; flex-shrink: 0;
}

.topbar-date {
    font-size: .78rem; color: var(--tm);
    display: none; /* solo desktop */
}
@media (min-width: 768px) { .topbar-date { display: inline; } }

.topbar-logout {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    color: var(--tm); text-decoration: none; font-size: 1.1rem;
    transition: background var(--t), color var(--t);
}
.topbar-logout:hover { background: var(--brl); color: #ef4444; }

/* Área de contenido */
.page-content {
    flex: 1;
    padding: 1.25rem;
    /* En mobile: espacio bajo bottom nav */
    padding-bottom: calc(1.25rem + var(--bh) + env(safe-area-inset-bottom, 0px));
    min-width: 0;
    overflow-x: hidden;
}

@media (min-width: 992px) {
    .page-content {
        padding: 1.5rem;
        padding-bottom: calc(1.5rem + var(--bh) + env(safe-area-inset-bottom, 0px));
    }
}

/* Animación entrada */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeIn .22s ease both; }
@media (prefers-reduced-motion: reduce) { .animate-in { animation: none; } }

/* ============================================================
   BOTTOM NAV — todas las pantallas
   ============================================================ */
.bnav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    z-index: 1030;
    background: #fff;
    border-top: 1px solid var(--br);
    box-shadow: 0 -3px 16px rgba(0,0,0,.10);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    align-items: stretch;
}

@media (min-width: 992px) {
    .bnav {
        left: var(--sw); /* no solapar sidebar */
    }
}

/* Botones regulares */
.bnav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: var(--bh);
    padding: 0 .5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tm);
    text-decoration: none;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .1px;
    transition: color var(--t);
    position: relative;
    -webkit-tap-highlight-color: transparent;
}
.bnav-btn i {
    font-size: 1.5rem;
    line-height: 1;
}
.bnav-btn span {
    line-height: 1;
    margin-top: 1px;
}
.bnav-btn:hover  { color: var(--p); }
.bnav-btn.is-active { color: var(--p); }
.bnav-btn.is-active::after {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 3px;
    background: var(--p);
    border-radius: 0 0 4px 4px;
}

/* FAB central — círculo azul elevado */
.bnav-fab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: var(--bh);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.bnav-fab-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--p), var(--pd));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(37,99,235,.5);
    transition: transform var(--t), box-shadow var(--t);
    margin-top: -12px; /* sube el círculo sobre la barra */
}
.bnav-fab-circle i {
    font-size: 1.5rem;
    color: #fff;
    line-height: 1;
}
.bnav-fab span {
    font-size: .68rem;
    font-weight: 600;
    color: var(--tm);
    line-height: 1;
}
.bnav-fab:hover .bnav-fab-circle {
    transform: scale(1.1);
    box-shadow: 0 6px 22px rgba(37,99,235,.6);
}
.bnav-fab:active .bnav-fab-circle {
    transform: scale(.96);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-wrap {
    position: fixed;
    bottom: calc(var(--bh) + env(safe-area-inset-bottom, 0px) + .75rem);
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-width: 340px;
}
@media (min-width: 992px) {
    .toast-wrap { bottom: calc(var(--bh) + 1rem); }
}
.toast-item {
    background: #1e293b;
    color: #f8fafc;
    padding: .75rem 1rem;
    border-radius: .6rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    font-size: .875rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,.3);
    animation: toastIn .2s ease both;
    cursor: pointer;
}
.toast-item.toast-success { border-left: 4px solid #22c55e; }
.toast-item.toast-danger  { border-left: 4px solid #ef4444; }
.toast-item.toast-warning { border-left: 4px solid #f59e0b; }
.toast-item.toast-info    { border-left: 4px solid #3b82f6; }
.toast-item i { font-size: 1.1rem; flex-shrink: 0; }
.toast-item.toast-success i { color: #22c55e; }
.toast-item.toast-danger  i { color: #ef4444; }
.toast-item.toast-warning i { color: #f59e0b; }
.toast-item.toast-info    i { color: #3b82f6; }
@keyframes toastIn {
    from { opacity:0; transform: translateX(20px); }
    to   { opacity:1; transform: translateX(0); }
}

/* view-area transition */
#view-area { transition: opacity .12s ease; }
#view-area.view-loading { opacity: .4; pointer-events: none; }

/* ============================================================
   AVATARS
   ============================================================ */
.avatar {
    width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%;
    background: linear-gradient(135deg,var(--p),#3b82f6);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .8rem; color: #fff;
}
.avatar-sm {
    width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
    background: linear-gradient(135deg,var(--p),#3b82f6);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .7rem; font-weight: 700; color: #fff;
}
.user-info  { flex: 1; min-width: 0; overflow: hidden; }
.user-name  { color: #e2e8f0; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { color: #475569; font-size: .68rem; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
    background: var(--c); border: 1px solid var(--br);
    border-radius: var(--rl); padding: 1rem 1.1rem;
    display: flex; align-items: center; gap: .85rem;
    text-decoration: none; color: inherit; box-shadow: var(--s1);
    transition: transform var(--t), box-shadow var(--t);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--s2); color: inherit; }

.stat-icon {
    width: 46px; height: 46px; flex-shrink: 0;
    border-radius: var(--r);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
}
.stat-info h3 {
    font-size: 1.6rem; font-weight: 800; color: var(--tx);
    line-height: 1; margin: 0 0 .2rem; letter-spacing: -.8px;
}
.stat-info p  { color: var(--tm); font-size: .78rem; font-weight: 500; margin: 0; }

/* ============================================================
   CARDS
   ============================================================ */
.card { border: 1px solid var(--br); border-radius: var(--rl); box-shadow: var(--s1); background: var(--c); }
.card-header {
    background: var(--c); border-bottom: 1px solid var(--br);
    border-radius: var(--rl) var(--rl) 0 0 !important;
    padding: .8rem 1.1rem; font-weight: 700; font-size: .875rem; color: var(--tx);
}
.card-footer {
    background: var(--bg); border-top: 1px solid var(--br);
    border-radius: 0 0 var(--rl) var(--rl) !important;
    padding: .65rem 1.1rem;
}

/* ============================================================
   TABLAS
   ============================================================ */
.table-responsive { -webkit-overflow-scrolling: touch; }

.table-envios thead th {
    background: var(--bg); border-bottom: 1px solid var(--br) !important;
    font-size: .68rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .7px; color: var(--tm); white-space: nowrap; padding: .65rem .75rem;
}
.table-envios tbody td {
    vertical-align: middle; font-size: .845rem;
    border-color: var(--brl); padding: .55rem .75rem;
}
.table-envios tbody tr:hover td { background: var(--pl); }

.numero-envio {
    font-family: 'Fira Code', monospace; font-weight: 700;
    color: var(--p) !important; font-size: .85rem; letter-spacing: -.2px;
}

/* ============================================================
   BADGES · BUTTONS · FORMS
   ============================================================ */
.badge { font-weight: 600; font-size: .68rem; padding: .3em .62em; border-radius: 6px; }

.btn { font-weight: 600; border-radius: var(--r); font-size: .875rem; }
.btn-primary { background: var(--p); border-color: var(--p); }
.btn-primary:hover, .btn-primary:focus {
    background: var(--pd); border-color: var(--pd);
    box-shadow: 0 3px 10px rgba(37,99,235,.3);
}

.form-control, .form-select {
    border-color: var(--br); border-radius: var(--r); font-size: .875rem; min-height: 40px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--p); box-shadow: 0 0 0 3px rgba(37,99,235,.13);
}
.form-label { font-size: .8rem; font-weight: 600; color: #374151; margin-bottom: .3rem; }
.input-group-text { border-color: var(--br); background: var(--bg); font-size: .875rem; }

/* ============================================================
   PAGE HEADER · FORM SECTIONS · TIMELINE · MISC
   ============================================================ */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .65rem; margin-bottom: 1.1rem;
}
.page-header h4 { font-weight: 800; color: var(--tx); margin: 0; font-size: 1.15rem; letter-spacing: -.4px; }

.form-section { background: var(--c); border: 1px solid var(--br); border-radius: var(--rl); padding: 1.1rem 1.1rem 1.35rem; height: 100%; }
.form-section-title {
    font-size: .67rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1.1px;
    color: var(--tm); margin-bottom: .85rem; padding-bottom: .5rem;
    border-bottom: 1px solid var(--brl); display: flex; align-items: center;
}

.timeline { position: relative; padding-left: 1.6rem; }
.timeline::before {
    content: ''; position: absolute; left: .38rem; top: .3rem; bottom: .5rem;
    width: 2px; background: var(--br); border-radius: 1px;
}
.timeline-item { position: relative; margin-bottom: .85rem; }
.timeline-dot {
    position: absolute; left: -1.3rem; top: .3rem;
    width: 10px; height: 10px; border-radius: 50%;
    border: 2px solid #fff; box-shadow: 0 0 0 2px currentColor;
}
.timeline-content { background: var(--bg); border: 1px solid var(--br); border-radius: var(--r); padding: .55rem .8rem; }

.progress { background: var(--brl); border-radius: 10px; overflow: hidden; }
.progress-bar { border-radius: 10px; transition: width .6s ease; }

.alert { border-radius: var(--r); font-size: .875rem; }

.page-link { border-color: var(--br); color: var(--p); font-size: .8rem; border-radius: var(--r) !important; }
.page-item.active .page-link { background: var(--p); border-color: var(--p); }

.modal-content { border-radius: var(--rx); border: 1px solid var(--br); box-shadow: var(--s3); }
.modal-header { border-bottom: 1px solid var(--br); padding: .95rem 1.15rem; }
.modal-footer { border-top: 1px solid var(--br); padding: .75rem 1.15rem; }

dl.row dt { font-weight: 600; color: var(--tm); }

.modal-backdrop {
    display: none !important;
}
