/* ============================================================
   Mobile-Responsive Design - Task 10
   Hotel Reservation Management System
   Mobile-first approach using Bootstrap 5 breakpoints
   ============================================================ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
    --mobile-bottom-nav-h: 60px;
    --touch-target-min: 44px;
    --fab-size: 56px;
    --bottom-sheet-radius: 1.25rem;
    --swipe-indicator-h: 4px;
}

/* ============================================================
   10.2 – RESPONSIVE NAVIGATION
   ============================================================ */

/* ── Bottom Navigation Bar ──────────────────────────────────── */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-bottom-nav-h);
    background: #fff;
    border-top: 1px solid #dee2e6;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
    z-index: 1030;
    /* Safe area for notched phones */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-bottom-nav .nav-item {
    flex: 1;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    text-decoration: none;
    transition: color 0.2s ease, background-color 0.2s ease;
    border-radius: 0.5rem;
    margin: 4px 2px;
    padding: 4px 8px;
    position: relative;
}

.mobile-bottom-nav .nav-item:hover,
.mobile-bottom-nav .nav-item:focus {
    color: #0d6efd;
    background-color: rgba(13, 110, 253, 0.08);
    outline: none;
}

.mobile-bottom-nav .nav-item.active {
    color: #0d6efd;
}

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

.mobile-bottom-nav .nav-item i {
    font-size: 1.25rem;
    line-height: 1;
    margin-bottom: 2px;
}

.mobile-bottom-nav .nav-item small {
    font-size: 0.65rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

/* ── Body padding for bottom nav ────────────────────────────── */
@media (max-width: 991.98px) {
    body {
        padding-bottom: calc(var(--mobile-bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    }

    /* Ensure main content doesn't hide behind bottom nav */
    #main-content {
        padding-bottom: 1rem;
    }
}

/* ── Hamburger / Navbar Toggler ─────────────────────────────── */
.navbar-toggler {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    padding: 0.5rem;
    border: none;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
}

.navbar-toggler:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ── Collapsible Mobile Nav ─────────────────────────────────── */
@media (max-width: 991.98px) {
    .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #0d6efd;
        border-radius: 0 0 0.75rem 0.75rem;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        padding: 0.75rem 1rem;
        z-index: 1040;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }

    .navbar-collapse .nav-link {
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.625rem 0.75rem;
        border-radius: 0.5rem;
        color: rgba(255, 255, 255, 0.9) !important;
        font-weight: 500;
        transition: background-color 0.2s, transform 0.15s;
    }

    .navbar-collapse .nav-link:hover,
    .navbar-collapse .nav-link:focus {
        background-color: rgba(255, 255, 255, 0.15);
        color: #fff !important;
        transform: translateX(4px);
    }

    .navbar-collapse .nav-link.active {
        background-color: rgba(255, 255, 255, 0.2);
        color: #fff !important;
    }

    /* Dropdown in mobile nav */
    .navbar-collapse .dropdown-menu {
        background: rgba(255, 255, 255, 0.1);
        border: none;
        border-radius: 0.5rem;
        padding: 0.25rem;
        margin-top: 0.25rem;
    }

    .navbar-collapse .dropdown-item {
        color: rgba(255, 255, 255, 0.9);
        border-radius: 0.375rem;
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
    }

    .navbar-collapse .dropdown-item:hover {
        background-color: rgba(255, 255, 255, 0.15);
        color: #fff;
    }

    .navbar-collapse .dropdown-divider {
        border-color: rgba(255, 255, 255, 0.2);
    }

    .navbar-collapse .dropdown-header {
        background: transparent;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        color: rgba(255, 255, 255, 0.7);
    }
}

/* ── Touch Targets – all interactive elements ───────────────── */
.btn,
.nav-link,
.dropdown-item,
.form-check-input,
.form-check-label {
    min-height: var(--touch-target-min);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Small buttons still need adequate touch area via padding */
.btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.75rem;
}

/* ============================================================
   10.3 – MOBILE FORM OPTIMIZATIONS
   ============================================================ */

/* ── Prevent iOS zoom on focus (font-size >= 16px) ─────────── */
@media (max-width: 767.98px) {
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="search"],
    input[type="password"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ── Mobile-friendly date inputs ────────────────────────────── */
input[type="date"],
input[type="time"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: var(--touch-target-min);
    cursor: pointer;
}

/* ── Form layout on small screens ───────────────────────────── */
@media (max-width: 575.98px) {
    .row.g-3 > [class*="col-md-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-dialog.modal-lg {
        max-width: calc(100vw - 1rem);
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* ── Floating Action Button (FAB) ───────────────────────────── */
.fab {
    position: fixed;
    bottom: calc(var(--mobile-bottom-nav-h) + 1rem + env(safe-area-inset-bottom, 0px));
    right: 1rem;
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: 50%;
    background: #0d6efd;
    color: #fff;
    border: none;
    box-shadow: 0 4px 16px rgba(13, 110, 253, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1020;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    /* Only show on mobile */
}

.fab:hover,
.fab:focus {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.5);
    background: #0b5ed7;
    outline: none;
}

.fab:active {
    transform: scale(0.96);
}

/* FAB label tooltip */
.fab[aria-label]::after {
    content: attr(aria-label);
    position: absolute;
    right: calc(100% + 0.5rem);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.fab:hover::after,
.fab:focus::after {
    opacity: 1;
}

/* Hide FAB on desktop */
@media (min-width: 992px) {
    .fab {
        display: none;
    }
}

/* ── Autocomplete / Datalist styling ────────────────────────── */
input[list] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%236c757d' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

/* ============================================================
   10.4 – MOBILE CALENDAR OPTIMIZATIONS
   ============================================================ */

/* ── Calendar wrapper on mobile ─────────────────────────────── */
@media (max-width: 767.98px) {
    .calendar-wrapper {
        padding: 0.5rem;
        border-radius: 0.5rem;
        /* Allow horizontal scroll for timeline on mobile */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .calendar-page-header {
        margin-bottom: 0.75rem;
    }

    .calendar-page-header h1 {
        font-size: 1.25rem;
    }

    .calendar-quick-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
        flex-wrap: nowrap;
    }

    .calendar-quick-nav .btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .calendar-filter-bar {
        padding: 0.75rem;
    }

    /* FullCalendar toolbar on mobile */
    .fc-toolbar.fc-header-toolbar {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .fc-toolbar-chunk {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .fc-toolbar-title {
        font-size: 1rem !important;
        text-align: center;
    }

    .fc-button-primary {
        font-size: 0.75rem !important;
        padding: 0.3rem 0.6rem !important;
        min-height: 36px;
    }
}

/* ── Bottom Sheet for event details ─────────────────────────── */
.bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.bottom-sheet-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: var(--bottom-sheet-radius) var(--bottom-sheet-radius) 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    z-index: 1051;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Safe area for notched phones */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: var(--swipe-indicator-h);
    background: #dee2e6;
    border-radius: 2px;
    margin: 0.75rem auto 0;
    cursor: grab;
    flex-shrink: 0;
}

.bottom-sheet-handle:active {
    cursor: grabbing;
}

.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem 0.5rem;
    border-bottom: 1px solid #dee2e6;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}

.bottom-sheet-title {
    font-weight: 700;
    font-size: 1rem;
    color: #212529;
    margin: 0;
}

.bottom-sheet-close {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #6c757d;
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 50%;
    transition: background-color 0.2s;
    padding: 0;
}

.bottom-sheet-close:hover {
    background-color: #f8f9fa;
    color: #212529;
}

.bottom-sheet-body {
    padding: 1rem;
}

/* ── Swipe hint animation ───────────────────────────────────── */
@keyframes swipeHint {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.swipe-hint {
    animation: swipeHint 1.5s ease-in-out 1s 2;
}

/* ── Calendar swipe container ───────────────────────────────── */
.calendar-swipe-container {
    touch-action: pan-y pinch-zoom;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Mobile calendar list view enhancements ─────────────────── */
@media (max-width: 575.98px) {
    /* List view event styling */
    .fc-list-event {
        cursor: pointer;
    }

    .fc-list-event:hover td {
        background-color: rgba(13, 110, 253, 0.05);
    }

    .fc-list-event-title a {
        font-size: 0.875rem;
        font-weight: 600;
    }

    .fc-list-day-cushion {
        background-color: #f8f9fa;
        font-size: 0.8125rem;
        font-weight: 700;
        padding: 0.5rem 0.75rem;
    }

    /* Hide tooltip on touch devices */
    .cal-tooltip {
        display: none !important;
    }
}

/* ============================================================
   10.5 – PWA FEATURES
   ============================================================ */

/* ── Install Prompt Banner ──────────────────────────────────── */
.pwa-install-banner {
    position: fixed;
    bottom: calc(var(--mobile-bottom-nav-h) + 0.5rem + env(safe-area-inset-bottom, 0px));
    left: 0.75rem;
    right: 0.75rem;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.75rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    padding: 0.875rem 1rem;
    z-index: 1025;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateY(calc(100% + 1rem));
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.pwa-install-banner.show {
    transform: translateY(0);
}

.pwa-install-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: 0.5rem;
    background: linear-gradient(135deg, #0d6efd, #0a58ca);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.pwa-install-banner-text {
    flex: 1;
    min-width: 0;
}

.pwa-install-banner-text strong {
    display: block;
    font-size: 0.875rem;
    color: #212529;
    margin-bottom: 0.125rem;
}

.pwa-install-banner-text small {
    font-size: 0.75rem;
    color: #6c757d;
}

.pwa-install-banner-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.pwa-install-banner-actions .btn {
    font-size: 0.8125rem;
    padding: 0.375rem 0.75rem;
    min-height: 36px;
}

/* ── Offline indicator ──────────────────────────────────────── */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #dc3545;
    color: #fff;
    text-align: center;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.offline-indicator.show {
    transform: translateY(0);
}

body.offline .offline-indicator {
    transform: translateY(0);
}

/* ── Push notification permission prompt ────────────────────── */
.push-permission-prompt {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.push-permission-prompt i {
    font-size: 1.5rem;
    color: #0d6efd;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

/* ============================================================
   GENERAL RESPONSIVE IMPROVEMENTS
   ============================================================ */

/* ── Tables on mobile ───────────────────────────────────────── */
@media (max-width: 767.98px) {
    .table-responsive-stack thead {
        display: none;
    }

    .table-responsive-stack tr {
        display: block;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        margin-bottom: 0.75rem;
        padding: 0.5rem;
        background: #fff;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    }

    .table-responsive-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.375rem 0.5rem;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        font-size: 0.875rem;
    }

    .table-responsive-stack td:last-child {
        border-bottom: none;
    }

    .table-responsive-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6c757d;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        flex-shrink: 0;
        margin-right: 0.5rem;
    }
}

/* ── Cards on mobile ────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .card {
        border-radius: 0.5rem;
    }

    .card-body {
        padding: 0.875rem;
    }

    .dashboard-card .card-body {
        padding: 1.25rem;
    }

    .dashboard-stat {
        font-size: 2rem;
    }
}

/* ── Modals on mobile ───────────────────────────────────────── */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100%;
        display: flex;
        align-items: flex-end;
    }

    .modal-content {
        border-radius: var(--bottom-sheet-radius) var(--bottom-sheet-radius) 0 0;
        border: none;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-dialog.modal-dialog-centered {
        align-items: center;
        margin: 0.5rem;
        min-height: auto;
    }

    .modal-dialog.modal-dialog-centered .modal-content {
        border-radius: 0.75rem;
        max-height: 95vh;
    }
}

/* ── Alerts on mobile ───────────────────────────────────────── */
@media (max-width: 575.98px) {
    #errorAlert,
    #successAlert {
        margin: 0 0 0.75rem;
        font-size: 0.875rem;
    }
}

/* ── Utility: safe area padding ─────────────────────────────── */
.pb-safe {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ── Smooth scrolling ───────────────────────────────────────── */
html {
    scroll-behavior: smooth;
}

/* ── Prevent content shift when scrollbar appears ───────────── */
html {
    scrollbar-gutter: stable;
}

/* ── Improved tap highlight ─────────────────────────────────── */
* {
    -webkit-tap-highlight-color: rgba(13, 110, 253, 0.1);
}

/* ── Prevent text selection during swipe ───────────────────── */
.no-select {
    user-select: none;
    -webkit-user-select: none;
}
