/*
 * RDV Maroc — App Mode Styles
 * Only active when running as TWA/PWA (standalone display mode)
 * Zero impact on the desktop website
 */

@media (display-mode: standalone) {

    /* ========================================
       1. GLOBAL / BODY
       ======================================== */
    html {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        overscroll-behavior-y: contain;
    }

    body {
        padding-bottom: 74px !important;
        padding-top: 0 !important;
        -webkit-tap-highlight-color: transparent;
        -webkit-user-select: none;
        user-select: text;
    }

    body.app-mode {
        padding-top: env(safe-area-inset-top) !important;
    }

    /* ========================================
       2. HIDE WEBSITE-ONLY ELEMENTS
       ======================================== */
    .top-bar {
        display: none !important;
    }

    .footer-section {
        display: none !important;
    }

    footer {
        display: none !important;
    }

    .back-to-top {
        display: none !important;
    }

    /* ========================================
       3. SLIM APP HEADER (Public Pages)
       ======================================== */
    #mainNavbar,
    .navbar {
        background: #ffffff !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-bottom: 1px solid #e2e8f0 !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
        padding: 0 16px !important;
        height: 56px !important;
        min-height: 56px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1030 !important;
    }

    .navbar::before,
    .navbar::after {
        display: none !important;
    }

    .navbar .container {
        padding: 0 !important;
        max-width: 100% !important;
        height: 56px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Hide hamburger and nav menu */
    .navbar-toggler {
        display: none !important;
    }

    .navbar-collapse {
        display: none !important;
    }

    /* Center brand as app title */
    .navbar-brand {
        position: absolute !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        font-size: 18px !important;
        font-weight: 700 !important;
        color: #7c3aed !important;
        white-space: nowrap !important;
    }

    .navbar-brand i {
        display: none !important;
    }

    .navbar-brand::before {
        content: "\2605" !important;
        margin-right: 6px !important;
        font-style: normal !important;
    }

    /* App back button (injected by JS) */
    .app-back-btn {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        color: #7c3aed;
        font-size: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        cursor: pointer;
        z-index: 10;
        transition: background 0.2s;
    }

    .app-back-btn:active {
        background: rgba(124, 58, 237, 0.1);
    }

    /* ========================================
       4. BOTTOM NAVIGATION
       ======================================== */
    .app-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: #ffffff;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 9999;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-nav-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        text-decoration: none !important;
        color: #94a3b8;
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 0.2px;
        transition: color 0.2s ease;
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }

    .app-nav-tab i {
        font-size: 22px;
        margin-bottom: 3px;
        transition: transform 0.2s ease;
    }

    .app-nav-tab.active {
        color: #7c3aed;
    }

    .app-nav-tab.active i {
        transform: scale(1.1);
    }

    .app-nav-tab.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background: #7c3aed;
        border-radius: 0 0 3px 3px;
    }

    .app-nav-tab:active {
        color: #7c3aed;
        opacity: 0.7;
    }

    .app-nav-tab span {
        font-size: 10px;
        line-height: 1;
    }

    /* ========================================
       5. LAYOUT — FULL WIDTH
       ======================================== */
    .container {
        max-width: 100% !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* ========================================
       6. HERO SECTION — COMPACT
       ======================================== */
    .hero-section {
        min-height: auto !important;
        padding: 30px 0 20px !important;
        margin-top: 0 !important;
    }

    .hero-section .hero-badge {
        display: none !important;
    }

    .hero-section h1 {
        font-size: 24px !important;
        line-height: 1.3 !important;
        margin-bottom: 10px !important;
    }

    .hero-section p {
        font-size: 14px !important;
        margin-bottom: 16px !important;
    }

    /* Hide floating decorations */
    .hero-float,
    .hero-blob,
    .hero-shape,
    .hero-section::before,
    .hero-section::after,
    .hero-section .position-absolute {
        display: none !important;
    }

    /* Hero search form — vertical stack */
    .hero-section .search-box {
        border-radius: 16px !important;
        padding: 16px !important;
    }

    .hero-section .search-box .row {
        flex-direction: column !important;
    }

    .hero-section .search-box .row > [class*="col"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        margin-bottom: 8px !important;
    }

    /* Hero stats */
    .hero-stats {
        display: none !important;
    }

    /* ========================================
       7. CARDS — MODERN APP STYLE
       ======================================== */
    .card {
        border-radius: 16px !important;
        border: none !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
        overflow: hidden !important;
        margin-bottom: 12px !important;
    }

    .card-body {
        padding: 16px !important;
    }

    .provider-card {
        border-radius: 16px !important;
        border: none !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
        margin-bottom: 12px !important;
    }

    .provider-card .card-header {
        border-radius: 16px 16px 0 0 !important;
    }

    .category-card {
        border-radius: 16px !important;
        border: none !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
        margin-bottom: 12px !important;
    }

    /* Category grid — 2 columns */
    .categories-section .row > [class*="col-lg"],
    .categories-section .row > [class*="col-md"] {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    /* Provider grid — single column */
    .featured-section .row > [class*="col-lg"],
    .featured-section .row > [class*="col-md"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* ========================================
       8. BUTTONS — TOUCH FRIENDLY
       ======================================== */
    .btn {
        min-height: 48px !important;
        border-radius: 12px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 10px 20px !important;
    }

    .btn-sm {
        min-height: 40px !important;
        border-radius: 10px !important;
        font-size: 13px !important;
        padding: 8px 16px !important;
    }

    .btn-moroccan,
    .btn-primary {
        box-shadow: 0 4px 14px rgba(124, 58, 237, 0.3) !important;
    }

    /* ========================================
       9. FORMS — MOBILE OPTIMIZED
       ======================================== */
    .form-control,
    .form-select {
        min-height: 48px !important;
        border-radius: 12px !important;
        font-size: 16px !important;
        padding: 10px 16px !important;
        border-color: #e2e8f0 !important;
    }

    .form-control:focus,
    .form-select:focus {
        border-color: #7c3aed !important;
        box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15) !important;
    }

    .input-group .form-control {
        border-radius: 12px 0 0 12px !important;
    }

    .input-group .btn {
        border-radius: 0 12px 12px 0 !important;
    }

    /* ========================================
       10. SECTIONS — TIGHTER SPACING
       ======================================== */
    section {
        padding: 24px 0 !important;
    }

    .section-title {
        font-size: 20px !important;
        margin-bottom: 16px !important;
    }

    .section-subtitle {
        font-size: 13px !important;
    }

    /* ========================================
       11. DASHBOARD PAGES (Pro/Client/Admin)
       ======================================== */
    .dash-sidebar {
        display: none !important;
    }

    .dash-main {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .dash-topbar {
        background: #ffffff !important;
        border-bottom: 1px solid #e2e8f0 !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
        padding: 0 16px !important;
        height: 56px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1030 !important;
    }

    .dash-topbar .dash-toggle {
        display: none !important;
    }

    .dash-topbar h4,
    .dash-topbar .h4 {
        font-size: 18px !important;
        font-weight: 700 !important;
        color: #1e293b !important;
        margin: 0 !important;
    }

    .dash-content {
        padding: 16px !important;
    }

    /* Dashboard stat cards */
    .dash-card {
        border-radius: 16px !important;
        border: none !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
    }

    /* Dashboard appointment items */
    .appointment-item {
        border-radius: 12px !important;
        padding: 12px !important;
    }

    /* Admin dashboard (uses different class names) */
    .admin-sidebar {
        display: none !important;
    }

    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .admin-topbar {
        background: #ffffff !important;
        border-bottom: 1px solid #e2e8f0 !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
        padding: 0 16px !important;
        height: 56px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1030 !important;
    }

    .admin-topbar .sidebar-toggle {
        display: none !important;
    }

    .admin-content {
        padding: 16px !important;
    }

    /* ========================================
       12. AUTH PAGES — FULLSCREEN CARD
       ======================================== */
    .auth-wrapper {
        min-height: calc(100vh - 130px) !important;
        padding: 16px !important;
    }

    .auth-card {
        border-radius: 20px !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
        max-width: 100% !important;
    }

    /* ========================================
       13. MISC OVERRIDES
       ======================================== */

    /* Remove AOS animations in app (faster feel) */
    [data-aos] {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    /* Badge styles */
    .badge {
        border-radius: 8px !important;
        padding: 4px 10px !important;
        font-size: 11px !important;
    }

    /* Alerts */
    .alert {
        border-radius: 12px !important;
        border: none !important;
    }

    /* Modal */
    .modal-content {
        border-radius: 20px !important;
        border: none !important;
    }

    .modal-header {
        border-radius: 20px 20px 0 0 !important;
    }

    /* Tables */
    .table {
        font-size: 13px !important;
    }

    /* Pagination */
    .page-link {
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px !important;
    }

    /* Scrollbar hide for cleaner look */
    ::-webkit-scrollbar {
        width: 0;
        display: none;
    }

    /* Language toggle */
    .lang-switch {
        position: fixed !important;
        top: 64px !important;
        right: 8px !important;
        z-index: 1025 !important;
        background: white !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
        padding: 4px !important;
    }

} /* end @media (display-mode: standalone) */

/*
 * FALLBACK: Same rules scoped under body.app-mode
 * JS adds this class when TWA is detected but display-mode: standalone
 * doesn't fire (e.g. unverified DAL, Custom Tab fallback).
 */

/* 1. GLOBAL */
body.app-mode {
    padding-bottom: 74px !important;
    padding-top: 0 !important;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: text;
    padding-top: env(safe-area-inset-top) !important;
}

/* 2. HIDE WEBSITE-ONLY ELEMENTS */
body.app-mode .top-bar { display: none !important; }
body.app-mode .footer-section { display: none !important; }
body.app-mode footer { display: none !important; }
body.app-mode .back-to-top { display: none !important; }

/* 3. SLIM APP HEADER */
body.app-mode #mainNavbar,
body.app-mode .navbar {
    background: #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-bottom: 1px solid #e2e8f0 !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
    padding: 0 16px !important;
    height: 56px !important;
    min-height: 56px !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 1030 !important;
}
body.app-mode .navbar::before,
body.app-mode .navbar::after { display: none !important; }

body.app-mode .navbar .container {
    padding: 0 !important;
    max-width: 100% !important;
    height: 56px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
body.app-mode .navbar-toggler { display: none !important; }
body.app-mode .navbar-collapse { display: none !important; }

body.app-mode .navbar-brand {
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin: 0 !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    color: #7c3aed !important;
    white-space: nowrap !important;
}
body.app-mode .navbar-brand i { display: none !important; }

/* 4. BOTTOM NAV (already injected by JS, just needs basic styles outside media query) */
body.app-mode .app-bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 64px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom);
}
body.app-mode .app-nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    text-decoration: none !important;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.2px;
    transition: color 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}
body.app-mode .app-nav-tab i {
    font-size: 22px;
    margin-bottom: 3px;
    transition: transform 0.2s ease;
}
body.app-mode .app-nav-tab.active { color: #7c3aed; }
body.app-mode .app-nav-tab.active i { transform: scale(1.1); }
body.app-mode .app-nav-tab.active::before {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 32px; height: 3px;
    background: #7c3aed;
    border-radius: 0 0 3px 3px;
}
body.app-mode .app-nav-tab:active { color: #7c3aed; opacity: 0.7; }
body.app-mode .app-nav-tab span { font-size: 10px; line-height: 1; }

/* 5. LAYOUT */
body.app-mode .container {
    max-width: 100% !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
}

/* 6. HERO */
body.app-mode .hero-section {
    min-height: auto !important;
    padding: 30px 0 20px !important;
    margin-top: 0 !important;
}
body.app-mode .hero-section .hero-badge { display: none !important; }
body.app-mode .hero-section h1 { font-size: 24px !important; line-height: 1.3 !important; margin-bottom: 10px !important; }
body.app-mode .hero-section p { font-size: 14px !important; margin-bottom: 16px !important; }
body.app-mode .hero-float,
body.app-mode .hero-blob,
body.app-mode .hero-shape,
body.app-mode .hero-section::before,
body.app-mode .hero-section::after,
body.app-mode .hero-section .position-absolute { display: none !important; }
body.app-mode .hero-section .search-box { border-radius: 16px !important; padding: 16px !important; }
body.app-mode .hero-section .search-box .row { flex-direction: column !important; }
body.app-mode .hero-section .search-box .row > [class*="col"] {
    width: 100% !important; max-width: 100% !important; flex: none !important; margin-bottom: 8px !important;
}
body.app-mode .hero-stats { display: none !important; }

/* 7. CARDS */
body.app-mode .card {
    border-radius: 16px !important; border: none !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
    overflow: hidden !important; margin-bottom: 12px !important;
}
body.app-mode .card-body { padding: 16px !important; }
body.app-mode .provider-card {
    border-radius: 16px !important; border: none !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important; margin-bottom: 12px !important;
}
body.app-mode .provider-card .card-header { border-radius: 16px 16px 0 0 !important; }
body.app-mode .category-card {
    border-radius: 16px !important; border: none !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important; margin-bottom: 12px !important;
}
body.app-mode .categories-section .row > [class*="col-lg"],
body.app-mode .categories-section .row > [class*="col-md"] { flex: 0 0 50% !important; max-width: 50% !important; }
body.app-mode .featured-section .row > [class*="col-lg"],
body.app-mode .featured-section .row > [class*="col-md"] { flex: 0 0 100% !important; max-width: 100% !important; }

/* 8. BUTTONS */
body.app-mode .btn {
    min-height: 48px !important; border-radius: 12px !important;
    font-size: 15px !important; font-weight: 600 !important;
    display: inline-flex !important; align-items: center !important;
    justify-content: center !important; padding: 10px 20px !important;
}
body.app-mode .btn-sm {
    min-height: 40px !important; border-radius: 10px !important;
    font-size: 13px !important; padding: 8px 16px !important;
}
body.app-mode .btn-moroccan,
body.app-mode .btn-primary { box-shadow: 0 4px 14px rgba(124, 58, 237, 0.3) !important; }

/* 9. FORMS */
body.app-mode .form-control,
body.app-mode .form-select {
    min-height: 48px !important; border-radius: 12px !important;
    font-size: 16px !important; padding: 10px 16px !important; border-color: #e2e8f0 !important;
}
body.app-mode .form-control:focus,
body.app-mode .form-select:focus {
    border-color: #7c3aed !important; box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15) !important;
}
body.app-mode .input-group .form-control { border-radius: 12px 0 0 12px !important; }
body.app-mode .input-group .btn { border-radius: 0 12px 12px 0 !important; }

/* 10. SECTIONS */
body.app-mode section { padding: 24px 0 !important; }
body.app-mode .section-title { font-size: 20px !important; margin-bottom: 16px !important; }
body.app-mode .section-subtitle { font-size: 13px !important; }

/* 11. DASHBOARD */
body.app-mode .dash-sidebar { display: none !important; }
body.app-mode .dash-main { margin-left: 0 !important; width: 100% !important; }
body.app-mode .dash-topbar {
    background: #ffffff !important; border-bottom: 1px solid #e2e8f0 !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important; padding: 0 16px !important;
    height: 56px !important; display: flex !important; align-items: center !important;
    justify-content: center !important; position: sticky !important; top: 0 !important; z-index: 1030 !important;
}
body.app-mode .dash-topbar .dash-toggle { display: none !important; }
body.app-mode .dash-content { padding: 16px !important; }

/* Admin dashboard */
body.app-mode .admin-sidebar { display: none !important; }
body.app-mode .admin-main { margin-left: 0 !important; width: 100% !important; }
body.app-mode .admin-topbar {
    background: #ffffff !important; border-bottom: 1px solid #e2e8f0 !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important; padding: 0 16px !important;
    height: 56px !important; display: flex !important; align-items: center !important;
    justify-content: center !important; position: sticky !important; top: 0 !important; z-index: 1030 !important;
}
body.app-mode .admin-topbar .sidebar-toggle { display: none !important; }
body.app-mode .admin-content { padding: 16px !important; }

/* 12. AUTH */
body.app-mode .auth-wrapper { min-height: calc(100vh - 130px) !important; padding: 16px !important; }
body.app-mode .auth-card { border-radius: 20px !important; box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important; max-width: 100% !important; }

/* 13. MISC */
body.app-mode [data-aos] { opacity: 1 !important; transform: none !important; transition: none !important; }
body.app-mode .badge { border-radius: 8px !important; padding: 4px 10px !important; font-size: 11px !important; }
body.app-mode .alert { border-radius: 12px !important; border: none !important; }
body.app-mode .modal-content { border-radius: 20px !important; border: none !important; }
body.app-mode .modal-header { border-radius: 20px 20px 0 0 !important; }
body.app-mode .table { font-size: 13px !important; }
body.app-mode .page-link {
    min-width: 44px !important; min-height: 44px !important;
    display: flex !important; align-items: center !important;
    justify-content: center !important; border-radius: 10px !important;
}

/* App back button (works outside media query too) */
body.app-mode .app-back-btn {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%);
    width: 40px; height: 40px; border: none;
    background: transparent; color: #7c3aed;
    font-size: 20px; display: flex; align-items: center;
    justify-content: center; border-radius: 50%;
    cursor: pointer; z-index: 10; transition: background 0.2s;
}
body.app-mode .app-back-btn:active { background: rgba(124, 58, 237, 0.1); }
