/* ============================================
   COMPREHENSIVE MOBILE RESPONSIVE STYLES
   ============================================ */

/* Base Mobile Styles - Apply to all screen sizes first */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* Touch-friendly button sizes */
.btn, button, a.btn {
    min-height: 44px; /* iOS recommended touch target */
    min-width: 44px;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    touch-action: manipulation;
}

.btn-sm {
    min-height: 36px;
    min-width: 36px;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Form elements - touch friendly */
.form-control, .form-select, textarea, input[type="text"], 
input[type="email"], input[type="tel"], input[type="number"],
input[type="date"], input[type="file"] {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.625rem 0.875rem;
    touch-action: manipulation;
}

/* Prevent text size adjustment on iOS */
input, textarea, select {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ============================================
   MOBILE FIRST - SMALL DEVICES (up to 576px)
   ============================================ */
@media (max-width: 575.98px) {
    /* Container adjustments */
    .container, .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Typography */
    h1 { font-size: 1.75rem !important; line-height: 1.3; }
    h2 { font-size: 1.5rem !important; line-height: 1.3; }
    h3 { font-size: 1.25rem !important; line-height: 1.3; }
    h4 { font-size: 1.125rem !important; }
    h5 { font-size: 1rem !important; }
    h6 { font-size: 0.875rem !important; }
    
    /* Page headers */
    .page-header {
        flex-direction: column !important;
        gap: 1rem !important;
        padding: 1rem !important;
        text-align: center;
    }
    
    .page-title {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem;
    }
    
    .header-actions {
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }
    
    .header-actions .btn {
        width: 100%;
    }
    
    /* Cards */
    .card, .content-card {
        margin-bottom: 1rem;
        border-radius: 8px;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    /* Tables - Make scrollable */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }
    
    .table {
        min-width: 600px; /* Ensure table doesn't get too compressed */
        font-size: 0.875rem;
    }
    
    .table thead th {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
        white-space: nowrap;
    }
    
    .table tbody td {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
    
    /* Forms */
    .form-row {
        flex-direction: column;
    }
    
    .form-group, .mb-3 {
        margin-bottom: 1rem !important;
    }
    
    .form-label {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }
    
    /* Filter sections */
    .filter-form {
        padding: 1rem;
    }
    
    .filter-row {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .filter-field {
        width: 100%;
        min-width: 100%;
    }
    
    .filter-button {
        width: 100%;
    }
    
    .filter-btn {
        width: 100%;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 8px;
    }
    
    .modal-header {
        padding: 1rem;
        flex-wrap: wrap;
    }
    
    .modal-title {
        font-size: 1.125rem;
        flex: 1;
        min-width: 0;
    }
    
    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0 !important;
    }
    
    /* Navigation */
    .navbar-nav {
        padding: 1rem 0;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
    
    /* Hero sections */
    .hero-content {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .hero-text h1 {
        font-size: 1.75rem !important;
        line-height: 1.3;
    }
    
    /* Grid layouts */
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Stats grids */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    /* Action buttons in tables */
    .table .btn-group {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .table .btn-sm {
        width: 100%;
        margin: 0.125rem 0;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        padding: 1rem 0.5rem;
    }
    
    .page-link {
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        text-align: center;
    }
    
    /* Badges */
    .badge {
        font-size: 0.75rem;
        padding: 0.375rem 0.625rem;
    }
    
    /* Alerts */
    .alert {
        padding: 1rem;
        font-size: 0.9375rem;
    }
    
    /* Sidebar widgets */
    .sidebar-widget {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Footer */
    .footer {
        text-align: center;
        padding: 2rem 1rem;
    }
    
    .footer .row > div {
        margin-bottom: 1.5rem;
    }
    
    /* Chat widgets */
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
        width: calc(100% - 2rem);
        max-width: 100%;
    }
    
    .chat-message {
        max-width: 85%;
    }
    
    /* Announcement banners */
    .announcement-banner {
        padding: 1.5rem 1rem !important;
    }
    
    .announcement-banner h3 {
        font-size: 1.25rem !important;
    }
    
    /* Content sections */
    .section-title h2 {
        font-size: 1.5rem;
    }
    
    /* Service/condition cards */
    .service-card, .condition-card {
        margin-bottom: 1rem;
    }
}

/* ============================================
   TABLET - MEDIUM DEVICES (576px to 768px)
   ============================================ */
@media (min-width: 576px) and (max-width: 767.98px) {
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    h1 { font-size: 2rem; }
    h2 { font-size: 1.75rem; }
    h3 { font-size: 1.5rem; }
    
    .page-header {
        padding: 1.25rem !important;
    }
    
    .header-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .table {
        font-size: 0.875rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .filter-row {
        flex-wrap: wrap;
    }
    
    .filter-field {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: calc(50% - 0.5rem);
    }
    
    .modal-dialog {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }
    
    .chat-widget {
        width: 350px;
        max-width: calc(100% - 2rem);
    }
}

/* ============================================
   ADMIN PANEL MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 991.98px) {
    /* Admin sidebar - hide on mobile, show toggle */
    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1050;
        width: 280px; /* Slightly wider on mobile for better usability */
    }
    
    .admin-sidebar.sidebar-open {
        transform: translateX(0);
    }
    
    .admin-main {
        margin-left: 0 !important;
        padding: 1rem;
    }
    
    .sidebar-toggle {
        display: block !important;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1051;
        background: white;
        border: 1px solid var(--border-color, #E1E4E8);
        padding: 0.75rem;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        min-width: 44px;
        min-height: 44px;
        cursor: pointer;
    }
    
    .sidebar-toggle:active {
        background: #F8F9FC;
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1049;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    /* Admin page header */
    .page-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem !important;
    }
    
    .page-title {
        font-size: 1.25rem !important;
        text-align: center;
    }
    
    .header-actions {
        width: 100%;
        flex-direction: column;
    }
    
    .header-actions .btn {
        width: 100%;
    }
    
    /* Admin tables */
    .admin-main .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .admin-main .table {
        min-width: 800px;
        font-size: 0.8125rem;
    }
    
    /* Admin cards */
    .content-card {
        margin-bottom: 1rem;
    }
    
    .card-header {
        padding: 0.875rem 1rem !important;
    }
    
    /* Admin forms */
    .admin-main .form-row {
        flex-direction: column;
    }
    
    .admin-main .form-group {
        margin-bottom: 1rem;
    }
    
    /* Admin filter sections */
    .admin-main .filter-form {
        padding: 1rem;
    }
    
    .admin-main .filter-row {
        flex-direction: column;
    }
    
    .admin-main .filter-field {
        width: 100%;
    }
    
    .admin-main .filter-button {
        width: 100%;
    }
}

/* ============================================
   SMALL MOBILE - EXTRA SMALL (up to 480px)
   ============================================ */
@media (max-width: 479.98px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.125rem !important; }
    
    .btn {
        font-size: 0.9375rem;
        padding: 0.5rem 0.875rem;
    }
    
    .btn-sm {
        font-size: 0.8125rem;
        padding: 0.375rem 0.625rem;
    }
    
    .table {
        font-size: 0.75rem;
        min-width: 500px;
    }
    
    .table thead th,
    .table tbody td {
        padding: 0.375rem 0.5rem;
    }
    
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }
    
    .modal-body {
        padding: 0.75rem;
    }
    
    .page-header {
        padding: 0.875rem !important;
    }
    
    .card-body {
        padding: 0.875rem !important;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */
@media (max-width: 991.98px) and (orientation: landscape) {
    .hero-content {
        min-height: auto;
        padding: 1.5rem 1rem;
    }
    
    .modal-body {
        max-height: calc(100vh - 150px);
    }
    
    .admin-sidebar {
        width: 200px;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn, button, a.btn {
        min-height: 48px;
        min-width: 48px;
    }
    
    .nav-link {
        padding: 0.875rem 1rem;
        min-height: 48px;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
    
    /* Better spacing for touch */
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    /* Larger checkboxes and radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 0.5rem;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .admin-sidebar,
    .sidebar-toggle,
    .header-actions,
    .btn,
    .pagination,
    .filter-form {
        display: none !important;
    }
    
    .admin-main {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .page-header {
        border: none !important;
        box-shadow: none !important;
    }
    
    .table {
        font-size: 0.75rem;
    }
}

/* ============================================
   ACCESSIBILITY - REDUCE MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   UTILITY CLASSES FOR MOBILE
   ============================================ */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block !important;
}

@media (max-width: 991.98px) {
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-center {
        text-align: center !important;
    }
    
    .mobile-stack {
        flex-direction: column !important;
    }
}

/* ============================================
   ADDITIONAL MOBILE FIXES
   ============================================ */

/* Fix for iOS input zoom */
@media screen and (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
}

/* Better spacing for mobile forms */
@media (max-width: 767px) {
    .contact-form-card,
    .referral-form-card {
        padding: 1.5rem 1rem !important;
    }
    
    .form-header {
        margin-bottom: 1.5rem;
    }
    
    .form-header h3 {
        font-size: 1.25rem;
    }
    
    .form-header p {
        font-size: 0.9375rem;
    }
}

/* Hero carousel mobile */
@media (max-width: 767px) {
    .hero-carousel {
        min-height: 40vh;
    }
    
    .hero-slide {
        padding: 1.5rem 1rem;
    }
    
    .hero-text h1 {
        font-size: 1.5rem !important;
    }
    
    .hero-text p {
        font-size: 0.9375rem;
    }
}

/* Service and condition cards mobile */
@media (max-width: 767px) {
    .service-card,
    .condition-card {
        margin-bottom: 1.5rem;
    }
    
    .service-card .card-body,
    .condition-card .card-body {
        padding: 1rem;
    }
}

/* Search section mobile */
@media (max-width: 767px) {
    .modern-search-card {
        padding: 1.5rem 1rem;
    }
    
    .search-form .form-row {
        flex-direction: column;
    }
    
    .search-form .form-group {
        width: 100%;
        margin-bottom: 1rem;
    }
}

/* Footer mobile */
@media (max-width: 767px) {
    .footer {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .footer .row > div {
        margin-bottom: 2rem;
    }
    
    .footer h5 {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    .footer ul {
        list-style: none;
        padding: 0;
    }
    
    .footer ul li {
        margin-bottom: 0.5rem;
    }
}

/* Announcement notification button mobile */
@media (max-width: 767px) {
    .announcement-notification {
        bottom: 1rem !important;
        right: 1rem !important;
        left: 1rem !important;
        position: fixed;
    }
    
    .announcement-btn {
        width: 100% !important;
        padding: 0.875rem 1.25rem !important;
        font-size: 0.9375rem !important;
        border-radius: 50px !important;
    }
    
    .announcement-btn span:not(.badge) {
        display: inline-block;
    }
    
    .announcement-modal .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .announcement-modal .modal-header {
        padding: 1.25rem !important;
    }
    
    .announcement-modal .modal-title {
        font-size: 1.25rem !important;
    }
    
    .announcement-modal .modal-body {
        padding: 1.5rem !important;
        max-height: 65vh !important;
    }
    
    .announcement-modal .modal-footer {
        padding: 1rem !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .announcement-modal .modal-footer .btn {
        width: 100% !important;
        margin: 0 !important;
    }
    
    .announcement-modal .modal-footer .d-flex {
        flex-direction: column !important;
        width: 100% !important;
    }
}

/* Chat widget mobile */
@media (max-width: 767px) {
    .chat-widget-container {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
        width: auto;
        max-width: 100%;
    }
    
    .chat-widget {
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 120px);
        max-height: 600px;
    }
}

/* Breadcrumbs mobile */
@media (max-width: 767px) {
    .breadcrumb {
        font-size: 0.875rem;
        padding: 0.75rem 0;
        flex-wrap: wrap;
    }
    
    .breadcrumb-item {
        margin-bottom: 0.25rem;
    }
}

/* Stats cards mobile */
@media (max-width: 767px) {
    .stat-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .stat-number {
        font-size: 1.75rem;
    }
    
    .stat-label {
        font-size: 0.875rem;
    }
}

/* Testimonials mobile */
@media (max-width: 767px) {
    .testimonial-card {
        margin-bottom: 1.5rem;
    }
    
    .testimonial-text {
        font-size: 0.9375rem;
    }
}

/* Staff cards mobile */
@media (max-width: 767px) {
    .staff-card {
        margin-bottom: 1.5rem;
    }
    
    .staff-card .card-body {
        padding: 1rem;
    }
}

/* ============================================
   FIX FOR iOS SAFARI VIEWPORT
   ============================================ */
@supports (-webkit-touch-callout: none) {
    .admin-main,
    .modal-body,
    .table-container {
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   FIX FOR ANDROID CHROME
   ============================================ */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
