/* public/assets/css/mobile.css */

/* We'll use 992px as the breakpoint where the mobile design kicks in */
@media (max-width: 992px) {

    .skeleton-overlay {
        gap: 0.5rem;
        padding: 1rem;
        background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(255,255,255,0.9) 100%);
    }

    .skeleton-mobile-loader {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        border-radius: 12px;
        background: #ffffff;
        box-shadow: 0 10px 30px rgba(17, 17, 17, 0.08);
    }

    .skeleton-mobile-loader .spinner-border {
        width: 1.75rem;
        height: 1.75rem;
        border-width: 0.2rem;
    }

    .skeleton-mobile-loader .skeleton-loader-text {
        font-weight: 600;
        color: #2d2d2d;
        margin-bottom: 0;
    }

    body.is-mobile-app .skeleton-overlay .skeleton-row {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }

    /* --- 1. Main Layout & Off-Canvas Sidebar --- */

    .main-wrapper {
        position: relative;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        width: min(280px, 85vw);
        padding: 1.5rem 1.25rem;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1050;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        background: linear-gradient(180deg, #ffe6cc 0%, #ffb067 32%, #db6600 100%);
        will-change: transform; /* Hint for browser animation performance */
    }

    .sidebar.expanded,
    .sidebar.hover-expanded {
        transform: translateX(0);
        width: min(280px, 85vw);
        align-items: flex-start;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .main-overlay {
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1040;
        /* Added for fade-in/out animation */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease-in-out, visibility 0s 0.3s;
    }

    .main-overlay.active {
        opacity: 1;
        visibility: visible;
        transition: opacity 0.3s ease-in-out;
    }

    body.mobile-nav-open {
        overflow: hidden;
    }

    /* --- 2. Topbar --- */

    .topbar {
        padding: 0.75rem 1rem;
        gap: 0.75rem;
        flex-wrap: wrap;
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
    }

    .topbar-main {
        grid-column: 1 / -1;
        gap: 0.5rem;
        justify-content: flex-start;
    }

    .topbar-context {
        width: 100%;
        flex-wrap: wrap;
    }

    .topbar h5 {
        display: none;
    }

    .topbar .user span {
        display: none;
    }

    .topbar .user-menu {
        display: none;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 0.5rem;
        flex-wrap: nowrap;
        grid-column: 1 / -1;
        margin-left: 0;
        align-items: center;
    }

    .facility-switcher {
        order: 1;
        width: auto;
        margin: 0;
        flex: 0 1 auto;
    }

    .topbar .search-container {
        max-width: none;
        flex-grow: 0;
        order: 2;
        width: auto;
    }

    .topbar .search-container .search-dropdown {
        inset-inline: 0;
        top: calc(100% + 0.5rem);
    }

    .topbar .search-input-wrapper {
        display: none;
        max-width: 0;
        opacity: 0;
        visibility: hidden;
        transition: max-width 0.25s ease, opacity 0.2s ease, visibility 0.2s ease;
    }

    .topbar .search-container.is-mobile-open .search-input-wrapper,
    .topbar.mobile-search-active .search-input-wrapper {
        display: block;
        max-width: 100%;
        opacity: 1;
        visibility: visible;
    }

    .topbar.mobile-search-active > *:not(.topbar-actions) {
        display: none;
    }

    .topbar.mobile-search-active .topbar-actions {
        width: 100%;
        justify-content: stretch;
    }

    .topbar.mobile-search-active .facility-switcher,
    .topbar.mobile-search-active .topbar-icons,
    .topbar.mobile-search-active .search-toggle-btn {
        display: none !important;
    }

    .topbar.mobile-search-active .search-container {
        flex: 1 1 100%;
    }

    .topbar.mobile-search-active .search-input-wrapper input {
        width: 100%;
    }

    .topbar .topbar-icons {
        margin-left: auto;
        gap: 0.5rem;
        order: 3;
        align-items: center;
    }

    .emar-page .topbar {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        gap: 0.75rem;
    }

    .emar-page .topbar .topbar-actions {
        grid-column: 2 / 4;
    }

    .facility-switcher .dropdown-toggle {
        height: 42px;
        padding: 0 0.9rem;
        border-radius: 12px;
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        background: #ffffff;
        border: 1px solid rgba(17, 17, 17, 0.08);
        color: var(--heading-color);
        box-shadow: 0 10px 26px rgba(17, 17, 17, 0.08);
    }

    .facility-switcher .dropdown-toggle:focus,
    .facility-switcher .dropdown-toggle:hover {
        background: #f6f8fb;
        color: var(--heading-color);
        box-shadow: 0 0 0 4px rgba(219, 102, 0, 0.08), 0 14px 30px rgba(17, 17, 17, 0.1);
    }

    .theme-dark .facility-switcher .dropdown-toggle,
    .theme-dark .facility-switcher .dropdown-toggle:focus,
    .theme-dark .facility-switcher .dropdown-toggle:hover {
        background: var(--surface-alt);
        color: var(--text-primary);
        border-color: var(--border-color);
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
    }

    .facility-switcher .text-muted {
        display: inline-flex;
        align-items: center;
        height: 42px;
        padding: 0 0.9rem;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.12);
        color: #fff !important;
        gap: 0.35rem;
    }

    .topbar-icon-btn {
        width: 44px;
        height: 44px;
        border-radius: 14px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #ffffff;
        color: var(--heading-color);
        border: 1px solid rgba(17, 17, 17, 0.07);
        padding: 0;
        box-shadow: 0 12px 30px rgba(17, 17, 17, 0.08);
    }

    .topbar-icon-btn:focus,
    .topbar-icon-btn:hover {
        background: #f6f8fb;
        color: var(--heading-color);
        box-shadow: 0 0 0 4px rgba(219, 102, 0, 0.08), 0 14px 30px rgba(17, 17, 17, 0.1);
    }

    .theme-dark .topbar-icon-btn,
    .theme-dark .topbar-icon-btn:hover,
    .theme-dark .topbar-icon-btn:focus {
        background: var(--surface-alt);
        color: var(--text-primary);
        border-color: var(--border-color);
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
    }

    .topbar .dropdown-menu {
        max-width: min(360px, 90vw);
    }

    .calendar-peek-menu {
        min-width: min(360px, 92vw);
    }

    .notif-menu {
        min-width: min(380px, 94vw);
        max-height: 70vh;
    }

    /* --- 2a. Mobile-friendly controls --- */

    .btn,
    button.btn,
    .modal-footer .btn {
        border-radius: 12px;
        padding: 0.65rem 1rem;
        font-weight: 700;
        min-height: 44px;
        box-shadow: 0 8px 20px rgba(17, 17, 17, 0.08);
        transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
    }

    .btn:active,
    button.btn:active {
        transform: translateY(1px) scale(0.99);
        box-shadow: 0 6px 14px rgba(17, 17, 17, 0.06);
    }

    .btn-primary,
    .btn-primary:focus,
    .btn-primary:hover {
        background-color: var(--primary, #db6600);
        border-color: var(--primary, #db6600);
        box-shadow: 0 10px 24px rgba(219, 102, 0, 0.22);
    }

    .form-control,
    .form-select {
        border-radius: 12px;
        min-height: 44px;
    }

    .card {
        border-radius: 16px;
        box-shadow: 0 10px 26px rgba(17, 17, 17, 0.08);
    }

    .sidebar-user {
        margin-top: auto;
        width: 100%;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.25);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-user .btn-user {
        background: rgba(255, 255, 255, 0.15);
        border: none;
        color: #fff;
    }

    /* --- 3. General Cards & Lists --- */

    .list-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .list-header > * {
        width: 100%;
    }

    .filter-bar .card-body {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .resident-grid {
        grid-template-columns: 1fr;
    }

    .page-hero {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        padding: 1.75rem;
        gap: 1.25rem;
    }

    .page-hero::after {
        inset: auto auto -40% 30%;
        width: 240px;
        height: 240px;
    }

    .hero-avatar {
        width: 96px;
        height: 96px;
    }

    .hero-actions {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .hero-actions .btn {
        flex: 1 1 100%;
        justify-content: center;
    }

    .resident-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .resident-toolbar .toolbar-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .profile-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: flex-start;
    }

    .profile-actions .btn {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 140px;
    }

    /* --- 4. eMAR Page --- */

    .emar-grid-container {
        grid-template-columns: 1fr;
        grid-template-areas: "main" "sidebar";
        padding-inline: 1rem;
    }

    .resident-info-sidebar {
        position: static;
        height: auto;
        border-left: none;
        border-top: 1px solid var(--mobile-divider-color, #dee2e6);
        padding-top: 1rem;
        background-color: var(--surface, #ffffff);
        color: var(--text-primary, #111111);
        display: none;
    }

    .emar-resident-mobile-card {
        width: 100%;
        background: var(--surface, #ffffff);
        color: var(--text-primary, #111111);
        border-radius: 16px;
        padding: 18px 16px;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 6px;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
        margin-bottom: 10px;
        animation: fadeInUp 0.25s ease;
    }

    .emar-resident-mobile-avatar {
        width: 92px;
        height: 92px;
        border-radius: 16px;
        background: var(--orange-main, #f0782f);
        display: grid;
        place-items: center;
        overflow: hidden;
        color: #fff;
        font-size: 34px;
        margin-bottom: 6px;
    }

    .emar-resident-mobile-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .emar-resident-mobile-name {
        font-weight: 700;
        font-size: 20px;
    }

    .emar-resident-mobile-meta {
        font-size: 14px;
        color: var(--text-secondary, #4b5563);
    }

    .emar-page .tabs {
        display: none;
    }

    /* Shared mobile tab dropdown (matches eMAR style) */
    .emar-page .emar-tab-dropdown,
    .mobile-tab-dropdown {
        display: block;
        width: 100%;
        margin: 4px 0 12px;
    }

    .emar-page .emar-tab-dropdown .dropdown-toggle,
    .mobile-tab-dropdown .dropdown-toggle {
        height: 42px;
        padding: 0 0.9rem;
        border-radius: 12px;
        display: inline-flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.35rem;
        background: var(--emar-accent, #db6600);
        border: none;
        color: var(--emar-accent-contrast, #ffffff);
        box-shadow: 0 10px 24px rgba(219, 102, 0, 0.18);
    }

    .emar-page .emar-tab-dropdown .dropdown-toggle:focus,
    .emar-page .emar-tab-dropdown .dropdown-toggle:hover,
    .mobile-tab-dropdown .dropdown-toggle:focus,
    .mobile-tab-dropdown .dropdown-toggle:hover {
        background: var(--emar-accent, #db6600);
        color: var(--emar-accent-contrast, #ffffff);
        filter: brightness(0.95);
    }

    .emar-page .emar-tab-dropdown .dropdown-menu,
    .mobile-tab-dropdown .dropdown-menu {
        width: 100%;
        min-width: 100%;
        animation: fadeScale 0.18s ease;
        transform-origin: top center;
    }

    .mobile-tab-dropdown .dropdown-item.active {
        background: var(--emar-accent-soft, rgba(219, 102, 0, 0.12));
        color: var(--emar-accent, #db6600);
        font-weight: 700;
    }

    /* --- 5. Modals --- */

    .modal-dialog {
        width: 95%;
        margin: 1.75rem auto;
        transition: transform 0.25s ease, opacity 0.25s ease;
    }

    .modal-backdrop.show {
        opacity: 0.45;
    }

    .modal.fade .modal-dialog {
        transform: translateY(16px) scale(0.98);
        opacity: 0;
    }

    .modal.show .modal-dialog {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    .modal-content {
        border-radius: 18px;
        box-shadow: 0 18px 38px rgba(17, 17, 17, 0.18);
        border: none;
    }

    .modal-header,
    .modal-footer {
        padding: 1rem 1.25rem;
        border-color: rgba(0, 0, 0, 0.05);
    }

    .modal-body {
        padding: 0.5rem 1.25rem 1.25rem;
    }

    .modal-xl {
        max-width: 100%;
        width: 100%;
        margin: 0;
    }

    .modal-xl .modal-content {
        min-height: 100vh;
        border-radius: 0;
        border: none;
        background-color: var(--surface, #ffffff);
        color: var(--text-primary, #111111);
    }

    @keyframes fadeInUp {
        from {
            opacity: 0;
            transform: translateY(10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes fadeScale {
        from {
            opacity: 0;
            transform: translateY(6px) scale(0.98);
        }
        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }
}
