/* ===== MOBILE ENHANCEMENTS ===== */
/* Global responsive improvements for all screens */

:root {
    --touch-target: 44px;
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 20px;
    --border-radius-sm: 6px;
    --border-radius-md: 12px;
    --border-radius-lg: 16px;
}

/* ===== TOUCH-FRIENDLY TARGETS ===== */
/* Ensure all interactive elements are at least 44x44px on mobile */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn,
    input[type="checkbox"],
    input[type="radio"],
    .form-check-input {
        min-height: var(--touch-target);
        min-width: var(--touch-target);
    }

    .btn {
        padding: 10px 14px;
    }

    .btn-sm {
        padding: 8px 12px;
        min-height: 36px;
    }

    .form-check-input {
        width: 20px;
        height: 20px;
        margin-top: 2px;
    }

    .form-check {
        padding: 8px 0;
        margin-bottom: 12px;
    }

    /* Better spacing around links */
    a {
        padding: 4px;
        display: inline-block;
    }
}

/* ===== RESPONSIVE TEXT ===== */
@media (max-width: 768px) {
    /* Readability improvements */
    body {
        font-size: 15px;
        line-height: 1.6;
    }

    h1 { font-size: 20px; line-height: 1.3; }
    h2 { font-size: 18px; line-height: 1.3; }
    h3 { font-size: 16px; line-height: 1.4; }
    h4 { font-size: 15px; line-height: 1.4; }
    h5 { font-size: 14px; line-height: 1.4; }
    h6 { font-size: 13px; line-height: 1.5; }

    p { font-size: 14px; line-height: 1.6; }
    small { font-size: 12px; }
    .text-muted { font-size: 13px; }
}

@media (max-width: 480px) {
    h1 { font-size: 18px; }
    h2 { font-size: 16px; }
    h3 { font-size: 15px; }
    h4 { font-size: 14px; }
    body { font-size: 14px; }
}

/* ===== RESPONSIVE SPACING ===== */
@media (max-width: 768px) {
    .container,
    .container-fluid {
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }

    .row {
        --bs-gutter-x: var(--spacing-sm);
        --bs-gutter-y: var(--spacing-sm);
    }

    .row > * {
        padding-right: calc(var(--spacing-sm) / 2);
        padding-left: calc(var(--spacing-sm) / 2);
    }

    /* Margin adjustments */
    .mb-3 { margin-bottom: var(--spacing-md) !important; }
    .mb-4 { margin-bottom: var(--spacing-lg) !important; }
    .mt-3 { margin-top: var(--spacing-md) !important; }
    .mt-4 { margin-top: var(--spacing-lg) !important; }
}

/* ===== FORM IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .form-group,
    .mb-3 {
        margin-bottom: var(--spacing-md);
    }

    .form-control,
    .form-select {
        padding: 10px 12px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: var(--border-radius-md);
        min-height: var(--touch-target);
    }

    .form-control:focus,
    .form-select:focus {
        border-width: 2px;
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }

    .form-label {
        font-size: 13px;
        font-weight: 600;
        margin-bottom: 6px;
        display: block;
    }

    /* Input groups */
    .input-group-text {
        padding: 10px 12px;
    }

    /* Prevent double tap zoom on inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px;
    }
}

/* ===== CARD IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .card {
        border-radius: var(--border-radius-md);
        margin-bottom: var(--spacing-md);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .card-header {
        padding: var(--spacing-sm);
        border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
    }

    .card-body {
        padding: var(--spacing-sm);
    }

    .card-title {
        font-size: 15px;
        margin-bottom: var(--spacing-sm);
    }
}

/* ===== TABLE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .table-responsive {
        border-radius: var(--border-radius-md);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: var(--spacing-md);
    }

    .table {
        font-size: 13px;
        margin-bottom: 0;
    }

    .table thead th {
        padding: 8px;
        font-size: 11px;
        white-space: nowrap;
    }

    .table tbody td {
        padding: 10px 8px;
        font-size: 12px;
    }

    /* Stack rows on very small screens */
    @media (max-width: 480px) {
        .table-stacked tbody tr {
            display: flex;
            flex-direction: column;
            margin-bottom: var(--spacing-md);
            border: 1px solid #e5e7eb;
            border-radius: var(--border-radius-sm);
        }

        .table-stacked td {
            display: flex;
            justify-content: space-between;
            padding: 8px 12px;
        }

        .table-stacked td::before {
            content: attr(data-label);
            font-weight: 600;
            flex-shrink: 0;
            margin-right: 8px;
        }
    }
}

/* ===== MODAL IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .modal-dialog {
        margin: var(--spacing-md);
        max-width: calc(100% - calc(var(--spacing-md) * 2));
    }

    .modal-content {
        border-radius: var(--border-radius-lg);
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-body {
        padding: var(--spacing-lg);
    }

    .modal-footer {
        gap: var(--spacing-sm);
    }

    .modal-footer .btn {
        flex: 1;
        min-width: auto;
    }
}

/* ===== NAVIGATION IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .navbar {
        padding: var(--spacing-sm);
        gap: var(--spacing-xs);
        flex-wrap: nowrap;
    }

    .navbar-brand {
        font-size: 16px;
        white-space: nowrap;
    }

    .navbar .btn {
        padding: 6px 10px;
        font-size: 12px;
        white-space: nowrap;
    }

    .navbar .btn i {
        margin-right: 2px;
    }

    /* Hide long labels on mobile */
    @media (max-width: 480px) {
        .navbar .btn span {
            display: none;
        }

        .navbar .btn {
            padding: 6px 8px;
        }
    }
}

/* ===== PAGINATION IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .pagination {
        flex-wrap: wrap;
        gap: var(--spacing-xs);
    }

    .page-link {
        padding: 6px 10px;
        font-size: 12px;
        line-height: 1;
    }

    .page-link:focus {
        box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
    }
}

/* ===== GRID IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .row > * {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .col-md-3,
    .col-md-4,
    .col-md-6,
    .col-lg-3,
    .col-lg-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Half width on tablets */
    @media (min-width: 576px) and (max-width: 768px) {
        .col-md-3,
        .col-lg-3 {
            flex: 0 0 calc(50% - var(--spacing-xs));
            max-width: calc(50% - var(--spacing-xs));
        }
    }
}

/* ===== BADGE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .badge {
        padding: 4px 8px;
        font-size: 11px;
        white-space: nowrap;
    }
}

/* ===== ALERT IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .alert {
        padding: var(--spacing-sm);
        font-size: 13px;
        margin-bottom: var(--spacing-md);
        border-radius: var(--border-radius-md);
    }

    .alert-heading {
        font-size: 14px;
        margin-bottom: 6px;
    }
}

/* ===== SCROLLBAR IMPROVEMENTS ===== */
.table-responsive::-webkit-scrollbar,
.notification-list::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.table-responsive::-webkit-scrollbar-track,
.notification-list::-webkit-scrollbar-track {
    background: transparent;
}

.table-responsive::-webkit-scrollbar-thumb,
.notification-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.table-responsive::-webkit-scrollbar-thumb:hover,
.notification-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===== LOADING STATE ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.show {
    display: flex;
}

/* ===== UTILITY CLASSES ===== */
@media (max-width: 768px) {
    .d-none-mobile {
        display: none !important;
    }

    .d-inline-mobile {
        display: inline !important;
    }

    .d-block-mobile {
        display: block !important;
    }

    .d-flex-mobile {
        display: flex !important;
    }

    .full-width-mobile {
        width: 100% !important;
    }

    .flex-column-mobile {
        flex-direction: column !important;
    }

    .gap-sm-mobile {
        gap: var(--spacing-sm) !important;
    }

    .p-sm-mobile {
        padding: var(--spacing-sm) !important;
    }

    .m-sm-mobile {
        margin: var(--spacing-sm) !important;
    }
}

/* ===== LANDSCAPE MODE FIXES ===== */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 8px;
    }

    .navbar {
        padding: 6px 10px;
    }

    .card-body {
        padding: 10px;
    }

    .content-area,
    .main-container {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ===== NOTCH/SAFE AREA SUPPORT ===== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(12px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .navbar {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .navbar,
    .sidebar,
    .btn-print-hide,
    .no-print {
        display: none !important;
    }

    body {
        padding: 0;
        margin: 0;
    }

    .card {
        page-break-inside: avoid;
    }
}
/* ===== ADMIN DASHBOARD MOBILE ===== */
@media (max-width: 1024px) {
    .admin-content {
        padding: 12px;
    }

    .cases-table thead th {
        padding: 12px 8px;
        font-size: 11px;
    }

    .cases-table tbody td {
        padding: 10px 8px;
        font-size: 13px;
    }
}

@media (max-width: 768px) {
    /* Admin table responsiveness */
    .admin-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .cases-table thead th {
        padding: 8px 6px;
        font-size: 10px;
        letter-spacing: 0;
    }

    .cases-table tbody td {
        padding: 8px 6px;
        font-size: 11px;
    }

    .case-id {
        font-size: 11px;
    }

    .patient-name {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Action buttons on mobile */
    .action-btn {
        padding: 4px 6px !important;
        font-size: 10px !important;
    }

    .btn-group .btn {
        padding: 4px 6px;
    }

    /* Status badges */
    .status-badge, 
    .badge {
        padding: 3px 6px;
        font-size: 10px;
    }

    /* Treatment type tags */
    .treatment-type-tag {
        padding: 3px 6px;
        font-size: 10px;
        max-width: 80px;
    }

    /* Admin filters */
    .filters-card .card-body {
        padding: 10px;
    }

    .filters-card .form-select,
    .filters-card .form-control {
        font-size: 12px;
        padding: 6px 10px;
    }

    /* Stats cards */
    .stat-card {
        padding: 12px;
    }

    .stat-card h3 {
        font-size: 20px;
    }

    .stat-card p {
        font-size: 11px;
    }

    /* Mobile-friendly layout for table cells */
    .cases-table .d-flex {
        flex-direction: column;
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .cases-table thead th {
        padding: 6px 4px;
        font-size: 9px;
    }

    .cases-table tbody td {
        padding: 6px 4px;
        font-size: 10px;
    }

    /* Hide less important columns on very small screens */
    .hide-xs {
        display: none !important;
    }

    .action-btn {
        padding: 3px 5px !important;
        font-size: 9px !important;
    }

    /* Stack action buttons */
    .btn-group {
        flex-wrap: wrap;
        gap: 2px;
    }
}

/* ===== MOBILE BOTTOM NAVIGATION ===== */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        display: flex;
        justify-content: space-around;
        padding: 8px 0;
        z-index: 1000;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: #6b7280;
        font-size: 10px;
        padding: 4px 12px;
    }

    .mobile-bottom-nav a.active {
        color: #667eea;
    }

    .mobile-bottom-nav a i {
        font-size: 20px;
        margin-bottom: 2px;
    }

    /* Add padding to body for bottom nav */
    body.has-bottom-nav {
        padding-bottom: 70px;
    }
}

/* ===== SWIPE GESTURES SUPPORT ===== */
@media (max-width: 768px) {
    .swipeable-row {
        position: relative;
        overflow: hidden;
    }

    .swipeable-row .row-content {
        transition: transform 0.2s ease;
    }

    .swipeable-row .row-actions {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        display: flex;
        align-items: center;
        transform: translateX(100%);
        transition: transform 0.2s ease;
    }

    .swipeable-row.swiped .row-content {
        transform: translateX(-100px);
    }

    .swipeable-row.swiped .row-actions {
        transform: translateX(0);
    }
}

/* ===== FLOATING ACTION BUTTON ===== */
@media (max-width: 768px) {
    .fab {
        position: fixed;
        bottom: 80px;
        right: 16px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
        border: none;
        z-index: 999;
        transition: transform 0.2s, box-shadow 0.2s;
    }

    .fab:hover, .fab:active {
        transform: scale(1.1);
        box-shadow: 0 6px 24px rgba(102, 126, 234, 0.5);
    }

    .fab i {
        font-size: 24px;
    }
}

/* ===== PULL TO REFRESH INDICATOR ===== */
@media (max-width: 768px) {
    .pull-to-refresh {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 10px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
        font-size: 13px;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
        z-index: 1001;
    }

    .pull-to-refresh.show {
        transform: translateY(0);
    }

    .pull-to-refresh i {
        margin-right: 8px;
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
}

/* ===== MOBILE CARD LAYOUTS ===== */
@media (max-width: 768px) {
    .mobile-card-view .case-card {
        background: white;
        border-radius: 12px;
        padding: 14px;
        margin-bottom: 10px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .mobile-card-view .case-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 10px;
    }

    .mobile-card-view .case-card-body {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        font-size: 12px;
    }

    .mobile-card-view .case-card-body .label {
        color: #6b7280;
        font-size: 10px;
        text-transform: uppercase;
    }

    .mobile-card-view .case-card-body .value {
        font-weight: 600;
        color: #1f2937;
    }

    .mobile-card-view .case-card-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid #f3f4f6;
    }

    .mobile-card-view .case-card-actions .btn {
        flex: 1;
        font-size: 12px;
        padding: 8px 12px;
    }
}

/* ===== IMPROVED TOUCH FEEDBACK ===== */
@media (max-width: 768px) {
    .btn, button, a.btn, .clickable {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .btn:active, button:active {
        transform: scale(0.98);
    }

    .cases-table tbody tr:active {
        background: #f1f5f9;
    }
}

/* ===== HORIZONTAL SCROLL INDICATORS ===== */
@media (max-width: 768px) {
    .table-responsive::before,
    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        width: 20px;
        pointer-events: none;
        z-index: 5;
    }

    .table-responsive::before {
        left: 0;
        background: linear-gradient(to right, white, transparent);
    }

    .table-responsive::after {
        right: 0;
        background: linear-gradient(to left, white, transparent);
    }

    .table-responsive {
        position: relative;
    }
}