/* ==========================================================================
   PYM Logística PWA - Core Stylesheet & Responsive System
   Mobile-First, Accessibility, iOS Insets, Dark/Light Mode, PWA UI
   ========================================================================== */

:root {
    --pym-brand: #4c2882;
    --pym-purple-600: #581c87;
    --pym-purple-700: #4c1d95;
    --pym-purple-800: #3b0764;
    --pym-purple-900: #2e1065;
    --color-ok: #10b981;
    --color-warn: #f59e0b;
    --color-exp: #ef4444;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* Base resets & smooth scrolling */
html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    padding-top: var(--safe-area-top);
    padding-bottom: calc(var(--safe-area-bottom) + 4rem); /* Leave space for bottom nav on mobile */
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

@media (min-width: 768px) {
    body {
        padding-bottom: var(--safe-area-bottom);
    }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}
.dark ::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.5);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.8);
}

/* High Visibility Focus Rings for Accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid #8b5cf6 !important;
    outline-offset: 2px !important;
}

/* Touch targets optimization */
button, 
[role="button"], 
input, 
select {
    touch-action: manipulation;
}

/* Bottom Navigation Bar for Mobile (Mobile-first UX) */
.mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(3.8rem + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(226, 232, 240, 0.9);
    z-index: 40;
    align-items: center;
    justify-content: space-around;
}

.dark .mobile-bottom-nav {
    background-color: rgba(15, 23, 42, 0.95);
    border-top-color: rgba(51, 65, 85, 0.9);
}

@media (min-width: 768px) {
    .mobile-bottom-nav {
        display: none !important;
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: #64748b;
    font-size: 0.68rem;
    font-weight: 600;
    transition: all 0.2s ease;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    padding: 4px 0;
}

.dark .mobile-nav-item {
    color: #94a3b8;
}

.mobile-nav-item i {
    font-size: 1.15rem;
    margin-bottom: 2px;
    transition: transform 0.2s ease;
}

.mobile-nav-item.active {
    color: #581c87;
    font-weight: 700;
}

.dark .mobile-nav-item.active {
    color: #c084fc;
}

.mobile-nav-item.active i {
    transform: translateY(-2px);
}

.mobile-nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background-color: #ef4444;
    color: white;
    font-size: 0.6rem;
    font-weight: 800;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid white;
}

.dark .mobile-nav-badge {
    border-color: #0f172a;
}

/* Offline Banner */
.offline-banner {
    background: linear-gradient(90deg, #b91c1c, #991b1b);
    color: #ffffff;
    padding: 0.65rem 1rem;
    display: none;
    align-items: center;
    justify-content: space-between;
    font-size: 0.825rem;
    font-weight: 600;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 50;
    transition: all 0.3s ease;
}

.offline-banner.active {
    display: flex;
}

.offline-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #fca5a5;
    display: inline-block;
    animation: blink 1.4s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.85); }
}

/* PWA Install Promo Bar / Banner */
.install-prompt-banner {
    background: linear-gradient(135deg, #4c1d95, #3b0764);
    color: white;
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    box-shadow: 0 10px 25px -5px rgba(76, 29, 149, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: none;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    animation: slideDown 0.35s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Table vs Card Layout for Smartphones */
@media (max-width: 767px) {
    .table-desktop-view {
        display: none !important;
    }
    .cards-mobile-view {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 0.875rem;
    }
}

@media (min-width: 768px) {
    .table-desktop-view {
        display: block !important;
    }
    .cards-mobile-view {
        display: none !important;
    }
}

/* Mobile Card component styling */
.mobile-entity-card {
    background: #ffffff;
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dark .mobile-entity-card {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
}

.mobile-entity-card:active {
    transform: scale(0.99);
}

/* iOS Status Bar & Standalone tweaks */
@media all and (display-mode: standalone) {
    .install-pwa-btn {
        display: none !important;
    }
    .header-pwa-badge {
        display: inline-flex !important;
    }
}

/* Print Clean Mode */
@media print {
    .no-print,
    .mobile-bottom-nav,
    .offline-banner,
    .install-prompt-banner {
        display: none !important;
    }
    body {
        background: #ffffff !important;
        color: #000000 !important;
        padding: 0 !important;
    }
    .print-only {
        display: block !important;
    }
    .table-desktop-view {
        display: block !important;
    }
    .cards-mobile-view {
        display: none !important;
    }
}
