/**
 * MMHC CRM — global mobile / app WebView styles (max-width 767px).
 * Desktop (768px+) is unchanged. No features removed — layout adapts only.
 */

@media (max-width: 767.98px) {
    html.mmhc-mobile {
        -webkit-text-size-adjust: 100%;
    }

    body.mmhc-crm-auth {
        overflow-x: hidden;
    }

    /* Top bar */
    .top-navbar {
        padding-top: env(safe-area-inset-top);
    }

    .top-navbar .navbar-brand .brand-logo--nav {
        max-width: 110px;
    }

    .top-navbar .navbar-collapse {
        max-height: min(70vh, 480px);
        overflow-y: auto;
        margin-top: 0.5rem;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .top-navbar .dropdown-menu {
        max-width: min(100vw - 2rem, 360px);
    }

    /* Main content area */
    .main-content {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-bottom: calc(4.75rem + env(safe-area-inset-bottom)) !important;
        min-height: calc(100vh - 56px);
        overflow-x: hidden;
    }

    .main-content > .border-bottom {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .main-content .h2,
    .main-content h1.h2 {
        font-size: 1.35rem;
        line-height: 1.3;
    }

    .main-content .btn-toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .main-content .btn-toolbar .badge {
        font-size: 0.7rem;
    }

    /* Alerts & OTP banners — keep all actions reachable */
    .main-content .app-alert {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .main-content .app-alert .d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .main-content .app-alert form.d-flex {
        flex-direction: column;
        width: 100%;
    }

    .main-content .app-alert form.d-flex input.form-control {
        width: 100% !important;
        max-width: none !important;
    }

    .main-content .app-alert .btn {
        width: 100%;
        justify-content: center;
    }

    /* Cards & spacing */
    .main-content .card {
        border-radius: 14px;
        margin-bottom: 0.85rem;
    }

    .main-content .card-header,
    .main-content .card-body {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .main-content .row.g-3 > [class*="col-"],
    .main-content .row.g-2 > [class*="col-"] {
        min-width: 0;
    }

    /* Tables — horizontal scroll, no clipping */
    .main-content .table-responsive,
    .mmhc-table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        margin-bottom: 0.75rem;
    }

    .main-content .table {
        font-size: 0.85rem;
        margin-bottom: 0;
    }

    .main-content .table th,
    .main-content .table td {
        white-space: nowrap;
        vertical-align: middle;
    }

    .main-content .table .btn-group {
        flex-wrap: nowrap;
        gap: 0.25rem;
    }

    /* Forms */
    .main-content .form-control,
    .main-content .form-select,
    .main-content textarea {
        font-size: 16px;
        min-height: 44px;
    }

    .main-content textarea {
        min-height: 88px;
    }

    .main-content .btn:not(.btn-sm):not(.btn-link) {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .main-content .btn-sm {
        min-height: 38px;
    }

    /* Modals */
    .modal-dialog {
        margin: 0.75rem;
        max-width: calc(100vw - 1.5rem);
    }

    .modal-fullscreen-sm-down {
        max-width: 100%;
    }

    /* Mobile app shells (patient / staff dashboards) */
    .mobile-app-container {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        padding-bottom: calc(4.75rem + env(safe-area-inset-bottom)) !important;
        min-height: 100vh;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .app-header-mobile {
        margin-bottom: 1rem;
        border-radius: 14px;
    }

    /* FAB — above bottom nav */
    .app-fab {
        bottom: calc(5rem + env(safe-area-inset-bottom)) !important;
        z-index: 1040;
    }

    /* Admin dashboard */
    .admin-header-card {
        border-radius: 14px;
        padding: 1rem !important;
    }

    .admin-name {
        font-size: 1.25rem !important;
    }

    .stat-card-modern {
        min-height: auto;
        padding: 0.85rem !important;
    }

    .stat-card-modern .stat-value {
        font-size: 1.35rem;
    }

    .quick-actions-grid {
        display: flex;
        flex-direction: column;
        gap: 0.65rem;
    }

    .quick-action-btn {
        width: 100%;
        padding: 0.85rem 1rem !important;
    }

    .quick-action-grid .btn {
        width: 100%;
    }

    /* Auth (login / register) — full screen on phone */
    body:has(.auth-page-wrapper) .auth-page-wrapper {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    body:has(.auth-page-wrapper) .login-card,
    body:has(.auth-page-wrapper) .register-card {
        margin: 0.75rem;
        max-width: 100%;
    }

    /* Community */
    .community-page .community-hero h2 {
        font-size: 1.35rem;
    }

    .community-page .post-card .card-body {
        padding: 1rem;
    }

    /* Pagination */
    .main-content .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }

    /* Action rows */
    .main-content .d-flex.gap-2:not(.flex-wrap),
    .main-content .d-flex.gap-3:not(.flex-wrap) {
        flex-wrap: wrap;
    }

    /* ID card / print pages — don't force bottom padding */
    body.mmhc-print-page .main-content {
        padding-bottom: 1rem !important;
    }

    /* Legacy admin CMS pages (resources/views/admin/* standalone Tailwind) */
    body.mmhc-admin-standalone {
        overflow-x: hidden;
    }

    body.mmhc-admin-standalone header .flex,
    body.mmhc-admin-standalone .flex.justify-between.items-center {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    body.mmhc-admin-standalone header h1 {
        font-size: 1.25rem !important;
        line-height: 1.3;
    }

    body.mmhc-admin-standalone main {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        max-width: 100%;
    }

    body.mmhc-admin-standalone .overflow-x-auto,
    body.mmhc-admin-standalone .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    body.mmhc-admin-standalone input,
    body.mmhc-admin-standalone select,
    body.mmhc-admin-standalone textarea,
    body.mmhc-admin-standalone button[type="submit"] {
        font-size: 16px;
        min-height: 44px;
    }

    body.mmhc-admin-standalone .grid {
        grid-template-columns: 1fr !important;
    }
}

/* Public landing (welcome.blade.php) */
@media (max-width: 767.98px) {
    body.mmhc-landing-page {
        overflow-x: hidden;
    }

    body.mmhc-landing-page .max-w-7xl {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Bottom navigation (included globally) */
.app-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    padding: 6px 4px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    z-index: 1045;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
}

.app-nav-item {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: #64748b;
    padding: 6px 4px;
    flex: 1;
    min-width: 0;
    min-height: 52px;
    border: none;
    background: transparent;
    font-size: inherit;
    touch-action: manipulation;
}

.app-nav-item i {
    font-size: 1.15rem;
}

.app-nav-item span {
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.1;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-nav-item.active,
.app-nav-item.active i {
    color: #4f46e5 !important;
}

/* Top navbar: one menu (left) + profile (right) */
.mmhc-navbar-brand {
    flex: 1;
    min-width: 0;
    justify-content: center;
}

@media (max-width: 991.98px) {
    .mmhc-navbar-brand {
        justify-content: flex-start;
    }
}

.mmhc-nav-profile-btn {
    border: none;
    background: transparent;
    padding: 0;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px #e2e8f0;
}

.mmhc-nav-profile-btn::after {
    display: none;
}

.mmhc-nav-profile-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.mmhc-nav-profile-img--sm {
    width: 32px;
    height: 32px;
}

.mmhc-nav-profile-initials {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mmhc-nav-profile-menu {
    min-width: min(280px, 92vw);
    border-radius: 12px;
    padding: 0.25rem 0;
}

.mmhc-nav-profile-menu .dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0.65rem 1rem;
}

.mmhc-nav-bell {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.app-nav-profile-thumb {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.app-nav-item-profile.active .app-nav-profile-thumb {
    box-shadow: 0 0 0 2px #4f46e5;
}

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