/**
 * Mobile Responsive Styles for Dr. Flush Scheduling
 * 
 * DETECTION STRATEGY:
 * 1. Screen width (CSS pixels, not physical) - 768px breakpoint
 * 2. Touch capability detection via (pointer: coarse)
 * 3. Hover capability detection via (hover: none)
 * 
 * Note: Modern phones like S25 Ultra (1080x2340 physical) report ~360px CSS width
 * because of device pixel ratio (DPR). The viewport meta tag handles this.
 */

/* ============================================
   TOUCH DEVICE DETECTION (more reliable than width)
   Applies to ANY touch device regardless of screen size
   ============================================ */

/* Touch-friendly tap targets for all touch devices */
@media (pointer: coarse) {
    a, button, .btn, input[type="submit"], input[type="button"], 
    .nav-links a, .calendar-day, .time-slot, .service-card {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Larger form inputs on touch */
    input, select, textarea {
        min-height: 48px;
        font-size: 16px !important; /* Prevents iOS zoom */
    }
    
    /* Remove sticky hover states on touch devices */
    .btn:hover,
    .calendar-day:hover,
    .time-slot:hover,
    .nav-links a:hover {
        transform: none;
    }
}

/* Devices without hover capability (phones, tablets) */
@media (hover: none) {
    /* Disable hover-only effects */
    .btn:hover {
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .card:hover {
        transform: none;
    }
}

/* Combined: Touch device AND narrow screen = definitely mobile phone */
@media (pointer: coarse) and (max-width: 768px) {
    /* Extra mobile-phone specific styles */
    body {
        -webkit-tap-highlight-color: rgba(47, 181, 210, 0.2);
    }
    
    /* Prevent text selection on interactive elements */
    button, .btn, .nav-links a, .calendar-day, .time-slot {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   BODY CLASS TARGETING (set by mobile.js)
   These classes are added dynamically:
   - .touch-device - has touch capability
   - .mobile-width - viewport <= 768px
   - .mobile-phone - both touch AND narrow
   ============================================ */

body.touch-device .hover-only {
    display: none;
}

body.mobile-phone .desktop-only {
    display: none !important;
}

body:not(.mobile-width) .mobile-only {
    display: none !important;
}


/* ============================================
   MOBILE NAVIGATION - HAMBURGER MENU
   ============================================ */

/* Hide hamburger by default (desktop) */
.hamburger-menu {
    display: none;
}

/* Mobile styles */
@media screen and (max-width: 768px) {
    
    /* Hamburger button */
    .hamburger-menu {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: 30px;
        height: 24px;
        cursor: pointer;
        z-index: 1100;
        padding: 0;
        background: none;
        border: none;
    }
    
    .hamburger-menu span {
        display: block;
        width: 100%;
        height: 3px;
        background: #2fb5d2;
        border-radius: 2px;
        transition: all 0.3s ease;
    }
    
    .hamburger-menu.active span:nth-child(1) {
        transform: rotate(45deg) translate(6px, 6px);
    }
    
    .hamburger-menu.active span:nth-child(2) {
        opacity: 0;
    }
    
    .hamburger-menu.active span:nth-child(3) {
        transform: rotate(-45deg) translate(6px, -6px);
    }
    
    /* Hide desktop nav links */
    .nav-links {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.98);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 0;
        z-index: 1050;
        padding-top: 60px;
    }
    
    .nav-links.mobile-open {
        display: flex;
    }
    
    .nav-links a,
    .nav-links .btn {
        font-size: 1.2rem;
        padding: 15px 30px;
        width: 100%;
        text-align: center;
        border-bottom: 1px solid #eee;
    }
    
    .nav-links .btn {
        margin: 10px 20px;
        width: calc(100% - 40px);
    }
    
    /* Navbar adjustments */
    .navbar .container {
        position: relative;
    }
    
    .nav-brand {
        font-size: 1.3rem;
    }
    
    .nav-brand .logo {
        height: 32px;
    }
}


/* ============================================
   GENERAL MOBILE LAYOUT
   ============================================ */

@media screen and (max-width: 768px) {
    
    body {
        font-size: 15px;
    }
    
    .container {
        padding: 0 8px;
    }
    
    /* Page headers */
    .page-header {
        padding: 20px 15px !important;
    }
    
    .page-header h1 {
        font-size: 1.4rem !important;
    }
    
    .page-header p {
        font-size: 0.9rem !important;
    }
    
    /* Cards */
    .card {
        margin: 8px 0;
        padding: 10px;
    }
    
    /* Buttons - touch friendly */
    .btn {
        padding: 14px 20px;
        font-size: 15px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-sm {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 40px;
    }
    
    /* Form inputs - touch friendly */
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 12px !important;
        min-height: 48px;
    }
    
    /* Tables - horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
    
    .data-table {
        font-size: 13px;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
    }
}


/* ============================================
   CALENDAR AVAILABILITY PAGE
   ============================================ */

@media screen and (max-width: 768px) {
    
    .calendar-container {
        padding: 10px !important;
    }
    
    .calendar-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .calendar-header h2 {
        font-size: 1.2rem;
    }
    
    .calendar-header button,
    .calendar-header .btn {
        width: 100%;
    }
    
    /* Calendar grid in availability page */
    #calendarContainer.calendar-grid {
        gap: 4px !important;
    }
    
    #calendarContainer .calendar-day {
        min-height: 70px !important;
        padding: 5px !important;
        font-size: 10px !important;
    }
    
    #calendarContainer .day-number {
        font-size: 14px !important;
    }
    
    #calendarContainer .day-hours,
    #calendarContainer .day-blocked,
    #calendarContainer .day-status {
        font-size: 8px !important;
        padding: 1px 2px !important;
    }
    
    /* Day detail modal */
    .day-detail,
    .day-modal,
    .modal-content {
        width: 95% !important;
        max-width: none !important;
        margin: 10px auto !important;
        padding: 15px !important;
    }
    
    .time-block-list {
        max-height: 200px;
        overflow-y: auto;
    }
    
    /* Weekly schedule */
    .weekly-schedule {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .weekly-schedule table {
        min-width: 400px;
    }
}


/* ============================================
   BOOKING PAGE - CALENDAR
   ============================================ */

@media screen and (max-width: 768px) {
    
    /* Make booking steps stack */
    .booking-step {
        margin: 8px 0;
        padding: 0;
    }
    
    .booking-step .card {
        padding: 10px 6px !important;
    }
    
    .booking-step h2 {
        font-size: 1rem;
        margin-bottom: 8px;
    }
    
    /* Service grid - single column */
    .service-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
    
    .service-card {
        padding: 12px;
    }
    
    /* Calendar - no overflow, contained within card */
    .calendar-container {
        overflow: hidden;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    .calendar-wrapper {
        min-width: 0;
        width: 100% !important;
    }
    
    /* Calendar grid - contained within card, all 7 days must fit */
    .calendar-grid,
    #calendarContainer {
        display: grid !important;
        grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
        gap: 1px !important;
        padding: 0 !important;
        margin: 5px 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    
    .calendar-day-header {
        font-size: 8px !important;
        padding: 4px 0 !important;
        font-weight: bold !important;
        text-align: center !important;
        min-width: 0 !important;
    }
    
    /* Show abbreviated text on mobile, hide full text */
    /* Supports both naming conventions: .day-full/.day-abbr and .full/.abbr */
    .day-full, .status-full, 
    .calendar-day-header .full, .day-status .full {
        display: none !important;
    }
    .day-abbr, .status-abbr,
    .calendar-day-header .abbr, .day-status .abbr {
        display: inline !important;
    }
    
    .calendar-day {
        padding: 1px !important;
        font-size: 10px !important;
        min-height: 38px !important;
        min-width: 0 !important;
        border-width: 1px !important;
        border-radius: 2px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        visibility: visible !important;
        opacity: 1 !important;
        background: #fff !important;
        border-color: #e5e5e5 !important;
        border-style: solid !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    
    .calendar-day.available {
        background: #e8f7fa !important;
        border-color: #2fb5d2 !important;
    }
    
    .calendar-day.unavailable {
        background: #f5f5f5 !important;
        opacity: 0.7 !important;
    }
    
    .calendar-day.other-month {
        opacity: 0.3 !important;
        background: #fafafa !important;
    }
    
    .calendar-day.past {
        opacity: 0.4 !important;
        background: #f9f9f9 !important;
    }
    
    .day-number {
        font-size: 12px !important;
        font-weight: bold !important;
        margin-bottom: 0 !important;
        line-height: 1 !important;
    }
    
    .day-status {
        font-size: 9px !important;
        margin-top: 0 !important;
        line-height: 1 !important;
    }
    
    /* Style the checkmark/X icons */
    .calendar-day.available .status-abbr,
    .calendar-day.available .day-status .abbr {
        color: #00a650;
        font-weight: bold;
    }
    
    .calendar-day.unavailable .status-abbr,
    .calendar-day.unavailable .day-status .abbr {
        color: #999;
        font-size: 12px !important;
    }
    
    .calendar-day.selected .status-abbr,
    .calendar-day.selected .day-status .abbr {
        color: white !important;
    }
    
    /* Calendar navigation */
    .calendar-nav,
    .month-nav {
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center !important;
    }
    
    .calendar-nav button,
    .month-nav button,
    .month-nav .btn {
        padding: 10px 15px;
        font-size: 13px;
        flex: 1;
        min-width: 100px;
    }
    
    .calendar-nav h3,
    .current-month {
        font-size: 1.1rem !important;
        order: -1;
        width: 100%;
        text-align: center;
        margin-bottom: 10px;
    }
    
    /* Time slots - 2 columns on mobile */
    .time-slots-grid,
    .time-slots {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    .time-slot {
        padding: 12px 8px !important;
        font-size: 14px !important;
    }
    
    /* Duration options */
    .duration-options,
    .duration-selector {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    .duration-btn,
    .duration-option {
        padding: 12px 10px !important;
        font-size: 13px !important;
    }
    
    /* Guest/Login form */
    .guest-form,
    .login-section {
        padding: 15px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .form-row > div {
        width: 100%;
    }
    
    /* Payment section */
    .payment-section {
        padding: 15px;
    }
    
    #card-container {
        min-height: 100px;
    }
    
    /* Price summary */
    .price-summary {
        font-size: 1.1rem;
    }
}


/* ============================================
   ADMIN PANEL
   ============================================ */

@media screen and (max-width: 768px) {
    
    /* Admin nav bar */
    .admin-nav {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .admin-nav h1 {
        font-size: 1.1rem;
        width: 100%;
        text-align: center;
    }
    
    .admin-nav a.btn {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    /* Admin sidebar - horizontal tabs on mobile */
    .admin-sidebar {
        width: 100% !important;
        position: relative !important;
        height: auto !important;
        padding: 10px !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .admin-sidebar ul {
        display: flex !important;
        flex-direction: row !important;
        gap: 5px;
        white-space: nowrap;
        padding-bottom: 5px;
    }
    
    .admin-sidebar li {
        flex-shrink: 0;
    }
    
    .admin-sidebar li a {
        padding: 10px 15px !important;
        font-size: 13px !important;
        border-radius: 20px !important;
        background: #f5f5f5;
    }
    
    .admin-sidebar li a.active,
    .admin-sidebar li a:hover {
        background: #2fb5d2 !important;
        color: white !important;
    }
    
    /* Admin main content */
    .admin-main {
        margin-left: 0 !important;
        padding: 15px !important;
    }
    
    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    .stat-card {
        padding: 15px !important;
    }
    
    .stat-card h3 {
        font-size: 1.5rem !important;
    }
    
    .stat-card p {
        font-size: 12px !important;
    }
    
    /* Section headers */
    .section-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch !important;
    }
    
    .section-header h2 {
        font-size: 1.1rem;
    }
    
    .section-header .btn {
        width: 100%;
    }
    
    /* Availability calendar in admin */
    .availability-grid {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .week-grid {
        min-width: 500px;
    }
    
    /* Forms in admin */
    .form-row {
        grid-template-columns: 1fr !important;
    }
    
    /* Modals */
    .modal-content,
    [style*="max-width: 500px"],
    [style*="max-width: 600px"] {
        width: 95% !important;
        max-width: none !important;
        margin: 10px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
    
    /* ==========================================
       ADMIN TABLES - MOBILE RESPONSIVE
       ========================================== */
    
    /* All admin tables - make horizontally scrollable */
    .admin-content table,
    .admin-main table,
    .data-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        font-size: 12px !important;
        white-space: nowrap;
    }
    
    .admin-content table thead,
    .admin-content table tbody,
    .data-table thead,
    .data-table tbody {
        display: table;
        width: 100%;
    }
    
    .admin-content th,
    .admin-content td,
    .data-table th,
    .data-table td {
        padding: 8px 10px !important;
        font-size: 11px !important;
    }
    
    /* Smaller buttons in tables */
    .action-buttons .btn,
    .data-table .btn {
        font-size: 10px !important;
        padding: 5px 8px !important;
    }
    
    /* Status badges smaller */
    .status-confirmed,
    .status-pending,
    .status-cancelled,
    .status-completed,
    .badge {
        font-size: 9px !important;
        padding: 3px 6px !important;
    }
}


/* ============================================
   INDEX / HOMEPAGE
   ============================================ */

@media screen and (max-width: 768px) {
    
    /* Hero section */
    .hero {
        padding: 40px 15px !important;
    }
    
    .hero h1 {
        font-size: 1.5rem !important;
    }
    
    .hero p {
        font-size: 1rem !important;
    }
    
    .hero .btn {
        padding: 15px 25px;
        font-size: 1rem;
    }
    
    /* Features grid */
    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    .feature-card {
        padding: 20px !important;
    }
    
    .feature-icon {
        font-size: 2rem !important;
    }
    
    /* Services preview */
    .services-grid {
        grid-template-columns: 1fr !important;
    }
    
    .service-card {
        margin: 0 0 15px 0;
    }
    
    /* CTA section */
    .cta-section {
        padding: 30px 15px !important;
    }
    
    .cta-section h2 {
        font-size: 1.3rem !important;
    }
}


/* ============================================
   DASHBOARD / ACCOUNT PAGES
   ============================================ */

@media screen and (max-width: 768px) {
    
    .dashboard-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .appointment-card {
        padding: 15px;
    }
    
    .appointment-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .appointment-actions .btn {
        width: 100%;
    }
    
    /* Account forms */
    .account-section {
        padding: 15px;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
}


/* ============================================
   CONFIRMATION & LOOKUP PAGES
   ============================================ */

@media screen and (max-width: 768px) {
    
    .confirmation-card {
        padding: 20px 15px;
        margin: 15px;
    }
    
    .detail-row {
        flex-direction: column;
        gap: 5px;
        padding: 10px 0;
    }
    
    .detail-label {
        font-weight: 600;
    }
    
    .calendar-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .calendar-actions .btn {
        width: 100%;
    }
    
    /* Lookup page */
    .lookup-form {
        padding: 20px 15px;
    }
    
    .appointment-list {
        padding: 0;
    }
}


/* ============================================
   SETTINGS PAGE
   ============================================ */

@media screen and (max-width: 768px) {
    
    .settings-container {
        padding: 10px !important;
    }
    
    .settings-section {
        padding: 15px !important;
        margin-bottom: 15px !important;
    }
    
    .settings-section h2 {
        font-size: 1.1rem !important;
    }
    
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    /* Feature card settings */
    [style*="background: #f9f9f9"] {
        padding: 15px !important;
    }
}


/* ============================================
   LOGIN / REGISTER PAGES
   ============================================ */

@media screen and (max-width: 768px) {
    
    .auth-container,
    .login-container,
    .register-container {
        padding: 20px 15px !important;
        margin: 15px !important;
        max-width: none !important;
    }
    
    .auth-container h1,
    .login-container h1,
    .register-container h1 {
        font-size: 1.4rem !important;
    }
}


/* ============================================
   FOOTER
   ============================================ */

@media screen and (max-width: 768px) {
    
    footer {
        padding: 20px 15px;
        text-align: center;
    }
    
    footer .container {
        flex-direction: column;
        gap: 10px;
    }
}


/* ============================================
   UTILITY CLASSES FOR MOBILE
   ============================================ */

@media screen and (max-width: 768px) {
    
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
    
    .text-center-mobile {
        text-align: center !important;
    }
    
    .full-width-mobile {
        width: 100% !important;
    }
    
    /* Scrollable containers */
    .scroll-x-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Stack flex items */
    .stack-mobile {
        flex-direction: column !important;
    }
    
    /* Padding adjustments */
    .p-mobile-sm {
        padding: 10px !important;
    }
    
    .p-mobile-md {
        padding: 15px !important;
    }
}


/* ============================================
   TOUCH IMPROVEMENTS
   ============================================ */

@media screen and (max-width: 768px) {
    
    /* Better tap targets */
    a, button, .btn, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover states on touch (they can be sticky) */
    @media (hover: none) {
        .btn:hover {
            transform: none;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        
        .nav-links a:hover {
            color: inherit;
        }
    }
    
    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
    }
    
    /* Prevent text selection on buttons */
    button, .btn {
        -webkit-user-select: none;
        user-select: none;
    }
}


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

@media screen and (max-width: 375px) {
    
    body {
        font-size: 14px;
    }
    
    .nav-brand {
        font-size: 1.1rem;
    }
    
    .btn {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    .calendar-day {
        padding: 6px 2px !important;
        font-size: 12px !important;
    }
    
    .calendar-day-header {
        font-size: 10px !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
}
