/* ===================================
   BP Cantara - Mobile App Styles
   @version 1.0.0
   Estilos para app mobile via Capacitor
   =================================== */

/* ===================================
   SAFE AREAS (iOS notch, Android cutout)
   =================================== */

:root {
    --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);
    --mobile-header-height: 56px;
    --mobile-bottom-nav-height: 60px;
    --cantara-gold: #B8860B;
    --cantara-dark: #1A1A1A;
}

/* ===================================
   MOBILE HEADER
   =================================== */

.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    padding-top: var(--safe-area-top);
    background: var(--cantara-dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 12px;
    padding-right: 12px;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.is-ios .mobile-header {
    height: calc(var(--mobile-header-height) + var(--safe-area-top));
}

.mobile-header-left,
.mobile-header-right {
    flex-shrink: 0;
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    overflow: hidden;
}

.mobile-header-logo {
    height: 28px;
    width: auto;
}

.mobile-header-title {
    color: var(--cantara-gold);
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-header-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #fff;
    font-size: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.mobile-header-btn:active {
    background: rgba(255,255,255,0.1);
}

.mobile-notif-badge {
    position: absolute;
    top: 4px;
    right: 2px;
    background: #EF4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* ===================================
   BOTTOM NAVIGATION BAR
   =================================== */

.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-bottom-nav-height);
    padding-bottom: var(--safe-area-bottom);
    background: #fff;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    z-index: 9999;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    border-top: 1px solid #e5e7eb;
}

.is-ios .mobile-bottom-nav {
    height: calc(var(--mobile-bottom-nav-height) + var(--safe-area-bottom));
}

[data-theme="dark"] .mobile-bottom-nav {
    background: #1f2937;
    border-top-color: #374151;
}

.mobile-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    padding: 4px 0;
}

.mobile-bottom-nav-item i {
    font-size: 20px;
    transition: transform 0.2s;
}

.mobile-bottom-nav-item.active {
    color: var(--cantara-gold);
}

.mobile-bottom-nav-item.active i {
    transform: scale(1.1);
}

.mobile-bottom-nav-item:active {
    background: rgba(184, 134, 11, 0.08);
}

.mobile-bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--cantara-gold);
    border-radius: 0 0 3px 3px;
}

[data-theme="dark"] .mobile-bottom-nav-item {
    color: #9ca3af;
}

[data-theme="dark"] .mobile-bottom-nav-item.active {
    color: var(--cantara-gold);
}

/* ===================================
   MOBILE DRAWER (SLIDE MENU)
   =================================== */

.mobile-drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.mobile-drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    background: #fff;
    z-index: 10001;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-drawer.open {
    transform: translateX(0);
}

[data-theme="dark"] .mobile-drawer {
    background: #1f2937;
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    padding-top: calc(20px + var(--safe-area-top));
    background: var(--cantara-dark);
    color: #fff;
    flex-shrink: 0;
}

.mobile-drawer-logo {
    height: 40px;
    width: auto;
}

.mobile-drawer-subtitle {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 2px;
}

.mobile-drawer-close {
    margin-left: auto;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-drawer-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-area-bottom));
}

.mobile-drawer-section {
    padding: 4px 0;
}

.mobile-drawer-section-title {
    padding: 12px 16px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--cantara-gold);
}

.mobile-drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #374151;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-drawer-item:active {
    background: rgba(184, 134, 11, 0.1);
}

.mobile-drawer-item i {
    width: 24px;
    text-align: center;
    font-size: 16px;
    color: #6b7280;
}

[data-theme="dark"] .mobile-drawer-item {
    color: #d1d5db;
}

[data-theme="dark"] .mobile-drawer-item i {
    color: #9ca3af;
}

/* ===================================
   MOBILE BODY ADJUSTMENTS
   =================================== */

body.is-mobile-app {
    padding-top: calc(var(--mobile-header-height) + var(--safe-area-top));
    padding-bottom: calc(var(--mobile-bottom-nav-height) + var(--safe-area-bottom));
}

body.is-mobile-app .mobile-main-content {
    min-height: calc(100vh - var(--mobile-header-height) - var(--mobile-bottom-nav-height) - var(--safe-area-top) - var(--safe-area-bottom));
}

body.is-mobile-app .hidden-mobile {
    display: none !important;
}

body.keyboard-visible {
    padding-bottom: 0;
}

/* ===================================
   PULL TO REFRESH
   =================================== */

.mobile-pull-indicator {
    height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    transition: opacity 0.2s;
}

.mobile-pull-spinner {
    color: var(--cantara-gold);
    font-size: 24px;
}

/* ===================================
   IN-APP NOTIFICATION
   =================================== */

.mobile-in-app-notif {
    position: fixed;
    top: calc(var(--mobile-header-height) + var(--safe-area-top) + 8px);
    left: 12px;
    right: 12px;
    z-index: 10010;
    transform: translateY(-120%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-in-app-notif.show {
    transform: translateY(0);
}

.mobile-in-app-notif-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    border-left: 4px solid var(--cantara-gold);
    cursor: pointer;
}

[data-theme="dark"] .mobile-in-app-notif-content {
    background: #1f2937;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.mobile-in-app-notif-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(184, 134, 11, 0.12);
    color: var(--cantara-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.mobile-in-app-notif-text {
    flex: 1;
    min-width: 0;
}

.mobile-in-app-notif-text strong {
    display: block;
    font-size: 14px;
    color: #111827;
    margin-bottom: 2px;
}

[data-theme="dark"] .mobile-in-app-notif-text strong {
    color: #f3f4f6;
}

.mobile-in-app-notif-text p {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-in-app-notif-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-in-app-notif-close:active {
    background: rgba(0,0,0,0.05);
}

/* ===================================
   NETWORK TOAST
   =================================== */

.mobile-network-toast {
    position: fixed;
    bottom: calc(var(--mobile-bottom-nav-height) + var(--safe-area-bottom) + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    z-index: 10020;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.mobile-network-toast.show {
    transform: translateX(-50%) translateY(0);
}

.mobile-toast-success {
    background: #059669;
    color: #fff;
}

.mobile-toast-warning {
    background: #d97706;
    color: #fff;
}

.mobile-toast-error {
    background: #dc2626;
    color: #fff;
}

/* ===================================
   TOUCH OPTIMIZATIONS
   =================================== */

@media (max-width: 768px) {
    /* Minimum touch target 44x44 */
    button, a, input[type="submit"], input[type="button"],
    .btn, [role="button"], select {
        min-height: 44px;
        min-width: 44px;
    }

    /* Prevent text zoom on input focus (iOS) */
    input, textarea, select {
        font-size: 16px !important;
    }

    /* Better input padding */
    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="tel"], input[type="url"],
    input[type="search"], textarea, select {
        padding: 12px 14px;
        border-radius: 10px;
    }

    /* Better table scroll */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    thead, tbody, tr {
        max-width: 100%;
    }

    /* Cards full width */
    .card, .bg-white.rounded-lg, .bg-white.rounded-xl {
        border-radius: 12px;
        margin-left: -4px;
        margin-right: -4px;
    }

    /* Modals full screen on mobile */
    .modal > div {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    /* Better spacing */
    .section-content {
        padding: 12px !important;
    }

    /* Stat cards in grid */
    .grid-cols-4, .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    /* Hide desktop elements */
    body.is-mobile-app #topNavbar,
    body.is-mobile-app .sidebar {
        display: none !important;
    }

    /* Fix main layout */
    body.is-mobile-app #main-content,
    body.is-mobile-app main,
    body.is-mobile-app .flex-1 {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Scrollable containers */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Better form layout */
    .grid.grid-cols-2.gap-4 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .grid.grid-cols-3.gap-4 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Action buttons stack */
    .flex.gap-2 > button,
    .flex.gap-3 > button {
        flex: 1;
        text-align: center;
    }

    /* Better search */
    .search-container, [class*="search"] {
        width: 100% !important;
    }
}

/* ===================================
   SMALL PHONES (<375px)
   =================================== */

@media (max-width: 375px) {
    .mobile-header-title {
        font-size: 14px;
    }

    .mobile-bottom-nav-item span {
        font-size: 9px;
    }

    .mobile-drawer {
        width: 280px;
    }
}

/* ===================================
   LANDSCAPE MODE
   =================================== */

@media (max-height: 500px) and (orientation: landscape) {
    .mobile-header {
        height: 44px;
    }

    .mobile-bottom-nav {
        height: 48px;
    }

    .mobile-bottom-nav-item span {
        display: none;
    }

    .mobile-bottom-nav-item i {
        font-size: 22px;
    }
}

/* ===================================
   TABLET (768px - 1024px)
   =================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .mobile-drawer {
        width: 350px;
    }

    .mobile-bottom-nav-item {
        gap: 4px;
    }

    .mobile-bottom-nav-item span {
        font-size: 11px;
    }
}

/* ===================================
   DESKTOP - HIDE MOBILE ELEMENTS
   =================================== */

@media (min-width: 769px) {
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-drawer,
    .mobile-drawer-overlay,
    .mobile-pull-indicator {
        display: none !important;
    }

    body.is-mobile-app {
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* ===================================
   ANIMATIONS
   =================================== */

@keyframes mobileSlideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes mobilePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.mobile-bottom-nav-item.active i {
    animation: mobilePulse 0.3s ease;
}

/* ===================================
   STANDALONE MODE (PWA installed)
   =================================== */

@media (display-mode: standalone) {
    body {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Allow text selection only in inputs and content areas */
    input, textarea, [contenteditable],
    .section-content p, .section-content td,
    .section-content li {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* ===================================
   PRINT - HIDE MOBILE ELEMENTS
   =================================== */

@media print {
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-drawer,
    .mobile-drawer-overlay,
    .mobile-in-app-notif,
    .mobile-network-toast,
    .mobile-pull-indicator {
        display: none !important;
    }

    body.is-mobile-app {
        padding: 0 !important;
    }
}
