/* ==================== RESET & BASE ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f6fa;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ==================== HEADER & NAVIGATION ==================== */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

.logo {
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 5px;
}

.nav-menu a {
    color: white;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 5px;
    transition: background 0.3s;
    display: block;
}

.nav-menu a:hover {
    background: rgba(255,255,255,0.2);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* ==================== BUTTONS ==================== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-add-patient {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    margin-bottom: 20px;
}

.btn-add-patient:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-add-patient:active {
    transform: translateY(0);
}

.btn-icon {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px 8px;
    margin: 0 3px;
    border-radius: 5px;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: #f3f4f6;
    transform: scale(1.1);
}

.btn-icon:active {
    transform: scale(0.95);
}

/* ==================== CARDS ==================== */
.card {
    background: white;
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.card-title {
    font-size: 24px;
    color: #333;
    font-weight: 600;
}

/* Patient Header - Base */
.patient-header-mobile {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.patient-header-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.patient-action-buttons {
    display: flex;
    gap: 8px;
}

/* ==================== FORMS ==================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #555;
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.form-field {
    display: grid;
    grid-template-columns: 180px 1fr;
    align-items: center;
    gap: 15px;
    margin-bottom: 18px;
}

.form-field label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #555;
    margin: 0;
}

.inline-form-group {
    display: grid;
    grid-template-columns: 150px 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.inline-form-group:last-child {
    margin-bottom: 0;
}

.input-with-unit {
    position: relative;
}

.input-with-unit input {
    padding-right: 45px;
}

.input-with-unit .unit-label {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    font-size: 14px;
    pointer-events: none;
}

/* ==================== TABLES ==================== */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: #f8f9fa;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #e9ecef;
}

td {
    padding: 12px 15px;
    border-bottom: 1px solid #e9ecef;
}

tbody tr {
    position: relative;
    transition: background 0.2s;
}

tbody tr:hover {
    background: #f8f9fa;
}

.row-lab-test {
    border-left: 4px solid #dc2626;
    background: #fef2f2;
}

.row-shipping {
    border-left: 4px solid #2563eb;
    background: #eff6ff;
}

.presc-icon {
    font-size: 14px;
    margin-left: 4px;
}

/* ==================== SEARCH & AUTOCOMPLETE ==================== */
.search-box {
    position: relative;
    margin-bottom: 20px;
}

.search-box input {
    width: 100%;
    padding: 12px 45px 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.search-box::after {
    content: '🔍';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

.autocomplete-items {
    position: absolute;
    border: 1px solid #ddd;
    border-top: none;
    z-index: 99;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.autocomplete-items div {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.autocomplete-items div:hover {
    background: #f0f0f0;
}

/* ==================== MODALS ==================== */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}

.modal-content {
    background: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideDown 0.3s;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header-new {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 25px;
    margin: -30px -30px 20px -30px;
    border-radius: 10px 10px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header-new h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.modal-title-responsive {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
}

.modal-title-responsive .title-line,
.modal-title-responsive .patient-line {
    color: white;
    font-size: 20px;
    font-weight: 700;
}

.modal-close-btn,
.close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.modal-close-btn:hover,
.close:hover {
    background: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin-top: 25px;
}

.modal-footer .btn-danger {
    margin-right: auto;
}

/* ==================== PRESCRIPTION SECTIONS ==================== */
.patient-info-section {
    background: #fff9e6;
    border: 1px solid #ffd966;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
}

.patient-info-section h4 {
    margin: 0 0 10px 0;
    color: #856404;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.diagnosis-notes-section {
    margin-bottom: 20px;
    padding: 15px;
    background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
    border: 2px solid #ff6b6b;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.2);
}

.diagnosis-label {
    color: #dc2626 !important;
    font-weight: 700 !important;
    font-size: 15px !important;
}

.label-icon {
    font-size: 18px;
    margin-right: 5px;
}

.lab-test-section {
    margin: 25px 0;
    padding: 20px;
    background: #f0f9ff;
    border-radius: 10px;
    border: 2px solid #0ea5e9;
}

.lab-test-section h4 {
    margin: 0 0 15px 0;
    color: #0369a1;
    font-size: 16px;
    font-weight: 700;
}

.lab-test-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.lab-test-option {
    position: relative;
    cursor: pointer;
}

.lab-test-option input[type="radio"] {
    position: absolute;
    opacity: 0;
}

.lab-test-card {
    padding: 15px;
    background: white;
    border: 2px solid #bae6fd;
    border-radius: 10px;
    text-align: center;
    transition: all 0.3s;
}

.lab-test-option input[type="radio"]:checked ~ .lab-test-card {
    border-color: #0284c7;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.15) 0%, rgba(3, 105, 161, 0.15) 100%);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.lab-test-card:hover {
    border-color: #0284c7;
    transform: translateY(-2px);
}

.lab-test-title {
    font-weight: 600;
    font-size: 14px;
    color: #0369a1;
}

/* ===== Giữ nguyên style base ===== */
.service-fee-section {
    margin: 25px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.service-fee-section h4 {
    margin: 0 0 15px 0;
    color: #3b82f6;
    font-size: 16px;
}

/* ===== Style riêng cho "Giao hàng" (màu xanh) ===== */
.lab-and-shipping-container .service-fee-section {
    background: #f0f9ff;
    border: 2px solid #0ea5e9;
}

.lab-and-shipping-container .service-fee-section h4 {
    color: #0369a1;
    font-weight: 700;
}

/* ✅ THÊM MỚI: Style riêng cho "Công khám" (màu tím) */
.service-fee-section:not(.lab-and-shipping-container .service-fee-section) {
    background: #faf5ff;           /* Tím nhạt */
    border: 2px solid #a855f7;     /* Border tím */
}

.service-fee-section:not(.lab-and-shipping-container .service-fee-section) h4 {
    color: #7e22ce;                /* Chữ tím đậm */
    font-weight: 700;
}

.fee-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.fee-option {
    position: relative;
    cursor: pointer;
}

.fee-option input[type="radio"] {
    position: absolute;
    opacity: 0;
}

.fee-option-card {
    padding: 15px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    text-align: center;
    transition: all 0.3s;
}

.fee-option input[type="radio"]:checked ~ .fee-option-card {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.fee-option-card:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.fee-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    color: #333;
}

/* ==================== MEDICINE ==================== */
.medicine-item {
    border: 2px solid #667eea;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    background: white;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.15);
}

.medicine-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

/* Chỉ đổi màu nền button Clear, giữ nguyên layout */
.medicine-item-header .btn-warning {
    background: #10b981 !important;
}

.medicine-item-header .btn-warning:hover {
    background: #059669 !important;
}

.medicine-row-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 3fr;
    gap: 10px;
    margin-bottom: 10px;
}

.medicine-row-grid .form-group {
    margin: 0;
}

.medicine-row-grid label {
    font-size: 13px;
    margin-bottom: 5px;
}

.dosage-suggestions {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    width: 100%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-radius: 0 0 5px 5px;
}

.dosage-suggestions div {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    transition: background-color 0.2s;
}

.dosage-suggestions div:hover {
    background: #f0f7ff;
    color: #667eea;
}

.dosage-suggestions div:last-child {
    border-bottom: none;
}

.dosage-suggestions::-webkit-scrollbar {
    width: 6px;
}

.dosage-suggestions::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.dosage-suggestions::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 3px;
}

.compact-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.compact-info div {
    font-size: 14px;
}

.medicine-list-compact {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-wrap: break-word;
    font-size: 13px;
    line-height: 1.4;
    -webkit-line-clamp: 2;
}

/* Thêm hoặc cập nhật class này */
.medicine-suggestions {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    max-height: 300px;  /* ✅ Giới hạn chiều cao */
    overflow-y: auto;   /* ✅ Cho phép cuộn dọc */
    z-index: 1000;
    width: 100%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-radius: 0 0 5px 5px;
}

.medicine-suggestions div {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    transition: background-color 0.2s;
}

.medicine-suggestions div:hover {
    background: #f0f7ff;
    color: #667eea;
}

.medicine-suggestions div:last-child {
    border-bottom: none;
}

/* ✅ Tùy chỉnh scrollbar cho đẹp */
.medicine-suggestions::-webkit-scrollbar {
    width: 6px;
}

.medicine-suggestions::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.medicine-suggestions::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 3px;
}

.medicine-suggestions::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* ==================== PAGINATION ==================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding: 15px 0;
}

.pagination button {
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}

.pagination button:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #667eea;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination button.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.pagination-info {
    color: #666;
    font-size: 14px;
}

/* ==================== ALERTS & BADGES ==================== */
.alert {
    padding: 15px 20px;
    border-radius: 5px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid #10b981;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border-left: 4px solid #3b82f6;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

/* ==================== LOGIN PAGE ==================== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h1 {
    color: #333;
    margin-bottom: 10px;
}

/* ==================== ANIMATIONS ==================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

/* ==================== UTILITY CLASSES ==================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.hidden { display: none; }
.flex { display: flex; }
.gap-10 { gap: 10px; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }

/* ==================== iOS FIX ==================== */
@supports (-webkit-touch-callout: none) {
    .modal-content {
        height: -webkit-fill-available !important;
        max-height: -webkit-fill-available !important;
    }
}

/* ==================== RESPONSIVE - MOBILE iPHONE ==================== */
@media (max-width: 430px) {
    .container {
        padding: 12px;
    }
    
    .card {
        padding: 15px;
        margin-bottom: 15px;
        border-radius: 8px;
    }
    
    /* Navigation */
    .nav-container {
        flex-direction: column;
        gap: 12px;
        padding: 12px 15px;
    }
    
    .nav-menu {
        flex-direction: column;
        width: 100%;
    }
    
    .nav-menu a {
        text-align: center;
        padding: 12px;
    }
    
    /* Buttons */
    .btn-add-patient {
        width: 100%;
        justify-content: center;
        padding: 12px 20px;
        font-size: 15px;
    }
    
    /* Patient Header Mobile */
    .patient-header-mobile {
        display: flex;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px;
        padding-bottom: 12px;
        border-bottom: 2px solid #f0f0f0;
    }
    
    .patient-header-row {
        display: flex;
        flex-direction: row !important;
        align-items: center;
        justify-content: flex-start !important;
        gap: 8px;
        width: 100%;
    }
    
    #patientNameDisplay {
        font-size: 15px !important;
        padding: 5px 10px !important;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .patient-action-buttons {
        display: flex;
        flex-direction: row !important;
        align-items: center;
        gap: 8px;
        margin-left: 0 !important;
        width: 100%;
        justify-content: flex-start !important;
    }
    
    .patient-action-buttons .btn {
        padding: 6px 10px;
        font-size: 12px;
        white-space: nowrap;
    }
    
    /* Patient Info */
    .compact-info {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 10px 12px;
    }
    
    .compact-info > div {
        display: flex;
        padding: 8px 0;
        border-bottom: 1px solid #e9ecef;
        gap: 8px;
    }
    
    .compact-info > div:last-child {
        border-bottom: none;
    }
    
    .compact-info strong {
        min-width: 80px;
        flex-shrink: 0;
    }
    
    /* Tables */
    table {
        font-size: 13px;
    }
    
    th, td {
        padding: 10px 8px;
    }
    
    .card-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .form-field {
        grid-template-columns: 95px 1fr;
        gap: 10px;
        align-items: center;
        margin-bottom: 10px;
    }
    
    .form-field label {
        font-size: 13px;
        margin: 0;
        white-space: nowrap;
    }
    
    .form-field label span:first-child {
        font-size: 14px;
        margin-right: 4px;
    }
    
    .form-control {
        font-size: 14px;
        padding: 10px;
    }
    
    /* Patient Info Section */
    .patient-info-section {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .patient-info-section h4 {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    /* Diagnosis Section */
    .diagnosis-notes-section {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .diagnosis-notes-section .inline-form-group {
        grid-template-columns: 95px 1fr;
        gap: 10px;
        align-items: center;
        margin-bottom: 10px;
    }
    
    .diagnosis-notes-section .inline-form-group label {
        font-size: 13px;
        margin: 0;
    }
    
    .diagnosis-label {
        font-size: 13px !important;
    }
    
    /* Lab Test & Fee Options */
    .lab-test-section,
    .service-fee-section {
        padding: 12px;
        margin: 15px 0;
    }
    
    .lab-test-section h4,
    .service-fee-section h4 {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    .lab-test-options {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
    
    .fee-options {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    
    .lab-test-card,
    .fee-option-card {
        padding: 8px 4px;
    }
    
    .lab-test-title,
    .fee-title {
        font-size: 11px;
        margin-bottom: 0;
    }
    
	/* Medicine Items - Kẻ khung phân biệt */
	.medicine-item {
		border: 2px solid #667eea;
		border-radius: 8px;
		padding: 12px;
		margin-bottom: 15px;
		background: white;
		box-shadow: 0 2px 6px rgba(102, 126, 234, 0.15);
	}

	/* Tên thuốc và Số lượng trên 1 hàng */
	.medicine-row-grid {
		display: grid;
		grid-template-columns: 1fr 100px;
		gap: 8px;
		align-items: start;
	}

	.medicine-row-grid > div:nth-child(3) {
		grid-column: 1 / -1;
		margin-top: 2px;
	}

	.medicine-row-grid .form-group {
		margin: 0;
	}

	.medicine-row-grid label {
		font-size: 12px;
		margin-bottom: 4px;
		display: block;
	}
    
    .medicine-list-compact {
        -webkit-line-clamp: 3;
        font-size: 14px;
        line-height: 1.5;
    }
    
    /* Modal */
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 20px;
        max-height: 90vh;
    }
    
    .modal-header-new {
        padding: 15px 18px;
        margin: -20px -20px 15px -20px;
    }
    
    .modal-header-new h3 {
        font-size: 17px;
    }
    
    .modal-title-responsive {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    
    .modal-title-responsive .title-line {
        font-size: 17px;
    }
    
    .modal-title-responsive .patient-line {
        font-size: 15px;
    }
    
    /* Modal Footer - Buttons trên 1 hàng */
    .modal-footer {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 6px;
        justify-content: space-between;
    }
    
    .modal-footer button {
        flex: 1;
        min-width: 0;
        padding: 10px 8px;
        font-size: 12px;
        white-space: nowrap;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        gap: 6px;
        padding: 12px 0;
    }
    
    .pagination button {
        padding: 8px 10px;
        font-size: 13px;
        min-width: 36px;
    }
    
    .pagination-info {
        font-size: 12px;
        width: 100%;
        text-align: center;
        order: -1;
        margin-bottom: 8px;
    }
    
    /* History Modals - Mobile Table với border tách biệt */
    #patientHistoryModal .table-container table,
    #prescriptionHistoryListModal .table-container table {
        display: block;
        width: 100%;
    }
    
    #patientHistoryModal .table-container thead,
    #prescriptionHistoryListModal .table-container thead {
        display: none;
    }
    
    #patientHistoryModal .table-container tbody,
    #prescriptionHistoryListModal .table-container tbody {
        display: block;
    }
    
    #patientHistoryModal .table-container tr,
    #prescriptionHistoryListModal .table-container tr {
        display: block;
        margin-bottom: 15px;
        padding: 12px;
        border-radius: 8px;
        background: white;
        position: relative;
    }
    
    /* Border riêng cho từng loại toa */
    #patientHistoryModal .table-container tr {
        border: 2px solid #667eea;
        box-shadow: 0 2px 4px rgba(102, 126, 234, 0.15);
    }
    
    #prescriptionHistoryListModal .table-container tr {
        border: 2px solid #10b981;
        box-shadow: 0 2px 4px rgba(16, 185, 129, 0.15);
    }
    
    #prescriptionHistoryListModal .table-container tr.row-lab-test {
        border: 2px solid #dc2626;
        background: #fef2f2;
        box-shadow: 0 2px 4px rgba(220, 38, 38, 0.15);
    }
    
    #prescriptionHistoryListModal .table-container tr.row-shipping {
        border: 2px solid #2563eb;
        background: #eff6ff;
        box-shadow: 0 2px 4px rgba(37, 99, 235, 0.15);
    }
    
    #patientHistoryModal .table-container td,
    #prescriptionHistoryListModal .table-container td {
        display: block;
        text-align: left !important;
        padding: 6px 0 !important;
        border: none;
        position: relative;
        padding-left: 100px !important;
    }
    
    #patientHistoryModal .table-container td::before,
    #prescriptionHistoryListModal .table-container td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        font-weight: 600;
        color: #667eea;
        font-size: 12px;
        min-width: 90px;
    }
    
    /* STT Badge */
    #patientHistoryModal .table-container td:first-child,
    #prescriptionHistoryListModal .table-container td:first-child {
        position: absolute;
        top: 8px;
        right: 8px;
        padding: 4px 10px !important;
        background: #667eea;
        color: white;
        border-radius: 12px;
        font-size: 11px;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    #patientHistoryModal .table-container td:first-child::before,
    #prescriptionHistoryListModal .table-container td:first-child::before {
        content: none;
    }
    
    /* Show mobile indicator icons in STT badge */
    #prescriptionHistoryListModal .table-container td:first-child .presc-icon {
        display: inline;
        font-size: 12px;
        margin-left: 2px;
    }
    
    /* Ngày khám canh trái */
    #prescriptionHistoryListModal .table-container td[data-label="Ngày khám"] {
        text-align: left !important;
    }
    
    /* Special styling for diagnosis and medicine columns */
    #prescriptionHistoryListModal .table-container td[data-label="Chẩn đoán"],
    #prescriptionHistoryListModal .table-container td[data-label="Thuốc"] {
        padding-left: 0 !important;
        margin-top: 8px;
        display: flex;
        align-items: flex-start;
        gap: 8px;
    }
    
    #prescriptionHistoryListModal .table-container td[data-label="Chẩn đoán"]::before,
    #prescriptionHistoryListModal .table-container td[data-label="Thuốc"]::before {
        position: static;
        display: inline-block;
        margin-right: 0;
        min-width: 85px;
        flex-shrink: 0;
    }
    
	/* Print Options Modal - Fullscreen trên mobile */
    #printOptionsModal .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        margin: 0;
        padding: 0;
        border-radius: 0;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    #printOptionsModal .modal-header-new {
        margin: 0;
        border-radius: 0;
        padding: 15px 18px;
        flex-shrink: 0;
    }
    
    #printOptionsModal .modal-body-scroll {
        flex: 1;
        overflow-y: auto;
        padding: 20px 15px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Buttons trong Print Options Modal */
    #printOptionsModal .modal-body-scroll > div:first-child {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }
    
    #printOptionsModal .modal-body-scroll .btn {
        padding: 14px 20px;
        font-size: 15px;
        width: 100%;
    }

    /* Search box */
    .search-box input {
        font-size: 16px;
        padding: 14px 45px 14px 15px;
    }
    
    /* Autocomplete */
    .autocomplete-items {
        max-height: 250px;
    }
    
    .autocomplete-items div {
        padding: 12px;
        font-size: 14px;
    }
    
    /* Dosage suggestions */
    .dosage-suggestions {
        max-height: 200px;
    }
    
    .dosage-suggestions div {
        padding: 12px;
        font-size: 14px;
    }
    
    /* Login page */
    .login-card {
        padding: 25px;
        width: 95%;
    }
    
    .login-header h1 {
        font-size: 22px;
    }

	/* History Modal - Ẩn cột Action và fix tiêu đề */
	#patientHistoryModal .col-action-history {
    display: none !important;
	}

	#patientHistoryModal .table-container table {
		display: block;
		width: 100%;
	}

	#patientHistoryModal .table-container thead {
		display: none;
	}

	#patientHistoryModal .table-container tbody {
		display: block;
	}

	#patientHistoryModal .table-container tr {
		display: block;
		margin-bottom: 15px;
		padding: 12px;
		border-radius: 8px;
		background: white;
		position: relative;
		border: 2px solid #667eea;
		box-shadow: 0 2px 4px rgba(102, 126, 234, 0.15);
	}

	#patientHistoryModal .table-container td {
		display: block;
		text-align: left !important;
		padding: 6px 0 !important;
		border: none;
		position: relative;
		padding-left: 100px !important;
	}

	#patientHistoryModal .table-container td::before {
		content: attr(data-label);
		position: absolute;
		left: 0;
		font-weight: 600;
		color: #667eea;
		font-size: 12px;
		min-width: 90px;
	}

	/* STT Badge */
	#patientHistoryModal .table-container td:first-child {
		position: absolute;
		top: 8px;
		right: 8px;
		padding: 4px 10px !important;
		background: #667eea;
		color: white;
		border-radius: 12px;
		font-size: 11px;
		font-weight: 600;
		display: flex;
		align-items: center;
		gap: 4px;
	}

	#patientHistoryModal .table-container td:first-child::before {
		content: none;
	}

	/* Modal title responsive cho history modal */
	#patientHistoryModal .modal-title-responsive {
		flex-direction: row !important;
		gap: 8px;
	}

	#patientHistoryModal .modal-title-responsive .title-line,
	#patientHistoryModal .modal-title-responsive .patient-line {
		font-size: 16px !important;
	}

}

/* ========== TABLET iPAD (768px - 1024px) ========== */
@media (min-width: 431px) and (max-width: 1024px) {
    .container {
        padding: 15px;
    }
    
    .card {
        padding: 20px;
    }
    
    .fee-options {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }
    
    .lab-test-options {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
    
    .medicine-row-grid {
        grid-template-columns: 2fr 1fr 3fr;
    }
    
    .form-field {
        grid-template-columns: 150px 1fr;
    }
    
    .modal-content {
        width: 90%;
        max-width: 700px;
    }
    
    /* ✅ FIX MODAL CHO iPAD - Quan trọng */
    #prescriptionModal .modal-content,
    #quickAddPatientModal .modal-content {
        width: 90%;
        max-width: 700px;
        height: 90vh !important;
        max-height: 90vh !important;
        margin: 5vh auto !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding: 0 !important;
    }
    
    #prescriptionModal .modal-header-new,
    #quickAddPatientModal .modal-header-new {
        flex: 0 0 auto !important;
        padding: 15px 20px !important;
        margin: 0 !important;
        border-radius: 10px 10px 0 0 !important;
    }
    
    #prescriptionModal .modal-body-scroll,
    #quickAddPatientModal .modal-body-scroll {
        flex: 1 1 0% !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 20px 25px 100px 25px !important;
        min-height: 0 !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    #prescriptionModal .modal-footer,
    #quickAddPatientModal .modal-footer {
        flex: 0 0 auto !important;
        position: sticky !important;
        bottom: 0 !important;
        margin: 0 !important;
        padding: 15px 25px !important;
        border-top: 2px solid #e0e0e0 !important;
        background: white !important;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.08) !important;
        z-index: 100 !important;
        border-radius: 0 0 10px 10px !important;
    }
    
    #prescriptionModal form,
    #quickAddPatientModal form {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
        min-height: 0 !important;
    }
}

/* ==================== DESKTOP (PC) ==================== */
@media (min-width: 769px) {
    /* Header bệnh nhân - PC canh lề */
    .patient-header-mobile {
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
    }
    
    .patient-header-row {
        flex: 0 0 auto;
    }
    
    .patient-action-buttons {
        margin-left: auto;
    }
    
    .col-lab-test {
        display: table-cell !important;
    }
    
    .modal-title-responsive .title-line::after {
        content: ' - ';
        margin: 0 4px;
    }
    
    .modal-title-responsive .patient-line {
        display: inline;
    }
    
    .diagnosis-notes-section .inline-form-group {
        display: grid;
        grid-template-columns: 150px 1fr;
        align-items: center;
        gap: 10px;
        margin-bottom: 12px;
    }

    /* Patient Info Section - 2 hàng gọn gàng */
    .patient-info-section {
        background: #fff9e6;
        border: 1px solid #ffd966;
        border-radius: 8px;
        padding: 15px;
        margin-bottom: 20px;
    }
    
    .patient-info-section h4 {
        margin: 0 0 10px 0;
        color: #856404;
        font-size: 15px;
    }
    
    /* Grid 2 hàng cho PC */
    .patient-vital-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        margin-bottom: 0;
    }
    
    .patient-vital-grid .form-field {
        display: grid;
        grid-template-columns: 90px 1fr;
        align-items: center;
        gap: 8px;
        margin-bottom: 0;
    }
    
    .patient-vital-grid .form-field label {
        font-size: 13px;
        margin: 0;
    }
    
    .patient-vital-grid .form-control {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    /* BMI Display */
    .bmi-display {
        grid-column: 3;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: white;
        border: 1px solid #ffd966;
        border-radius: 5px;
        font-weight: 600;
        font-size: 14px;
        color: #856404;
    }
    
    .bmi-value {
        color: #dc2626;
        font-size: 16px;
    }
    
    .bmi-status {
        font-size: 12px;
        padding: 2px 8px;
        border-radius: 12px;
        background: #10b981;
        color: white;
    }
    
    /* PC: Xét nghiệm - 1 hàng ngang */
    .lab-test-section .lab-test-options {
        display: flex !important;
        flex-direction: row !important;
        gap: 10px !important;
        grid-template-columns: unset !important;
    }
    
    .lab-test-section .lab-test-option {
        flex: 1 !important;
    }
    
    /* PC: Công khám - 1 hàng ngang */
    .service-fee-section .fee-options {
        display: flex !important;
        flex-direction: row !important;
        gap: 10px !important;
        grid-template-columns: unset !important;
    }
    
    .service-fee-section .fee-option {
        flex: 1 !important;
    }

	    /* ✅ THÊM: Print Preview Modal - Full Screen cho PC */
    #printPreviewModal {
        display: block !important;
        position: fixed !important;
        z-index: 10000 !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        background-color: rgba(0,0,0,0.9) !important;
        overflow: hidden !important;
    }
    
    #printPreviewModal > div {
        width: 100% !important;
        height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    
    #printPreviewModal .preview-header {
        flex: 0 0 auto !important;
        padding: 15px 25px !important;
    }
    
    #printPreviewModal .preview-body {
        flex: 1 1 auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 20px !important;
        overflow: hidden !important;
        background: #2a2a2a !important;
    }
    
    #printPreviewModal #previewFrame {
        width: 148mm !important;
        height: 210mm !important;
        max-width: 148mm !important;
        max-height: 210mm !important;
        margin: 0 auto !important;
        border: none !important;
        background: white !important;
        box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important;
        display: block !important;
        overflow: hidden !important;
    }
    
    #printPreviewModal .preview-footer {
        flex: 0 0 auto !important;
        padding: 15px 25px !important;
        background: white !important;
        border-top: 2px solid #e0e0e0 !important;
        display: flex !important;
        gap: 15px !important;
        justify-content: center !important;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.1) !important;
    }
    
    #printPreviewModal .preview-footer button {
        padding: 12px 30px !important;
        font-size: 16px !important;
        min-width: 150px !important;
    }
}


/* ==================== MODAL BEHAVIOR ENHANCEMENT ==================== */
/* Animation khi user click outside modal đang "locked" */
@keyframes modalShake {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    10%, 30%, 50%, 70%, 90% { transform: translate(-50%, -50%) scale(1.02); }
    20%, 40%, 60%, 80% { transform: translate(-50%, -50%) scale(0.98); }
}

/* Visual feedback cho các modal không thể đóng khi click outside */
#prescriptionModal.modal,
#quickAddPatientModal.modal {
    cursor: not-allowed;
}

#prescriptionModal .modal-content,
#quickAddPatientModal .modal-content {
    cursor: default;
}

/* Print Options Modal - có thể đóng */
#printOptionsModal.modal {
    cursor: pointer;
}

#printOptionsModal .modal-content {
    cursor: default;
}

/* Mobile: Tối ưu cursor cho touch devices */
@media (max-width: 768px) {
    #prescriptionModal.modal,
    #quickAddPatientModal.modal,
    #printOptionsModal.modal {
        cursor: default;
    }
}

/* ==================== MODAL STRUCTURE - ALL MODALS (PC & MOBILE) ==================== */
/* ========== 💻 PC (Desktop >= 769px) ========== */
@media (min-width: 769px) {
    /* ===== PHẦN 1: LAYOUT CƠ BẢN ===== */
    /* Header bệnh nhân - PC canh lề */
    .patient-header-mobile {
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
    }
    
    .patient-header-row {
        flex: 0 0 auto;
    }
    
    .patient-action-buttons {
        margin-left: auto;
    }
    
    .col-lab-test {
        display: table-cell !important;
    }
    
    .modal-title-responsive .title-line::after {
        content: ' - ';
        margin: 0 4px;
    }
    
    .modal-title-responsive .patient-line {
        display: inline;
    }
    
    .diagnosis-notes-section .inline-form-group {
        display: grid;
        grid-template-columns: 150px 1fr;
        align-items: center;
        gap: 10px;
        margin-bottom: 12px;
    }

    /* ===== PHẦN 2: PATIENT INFO & BMI ===== */
    .patient-info-section {
        background: #fff9e6;
        border: 1px solid #ffd966;
        border-radius: 8px;
        padding: 15px;
        margin-bottom: 20px;
    }
    
    .patient-info-section h4 {
        margin: 0 0 10px 0;
        color: #856404;
        font-size: 15px;
    }
    
    /* Grid 2 hàng cho PC */
    .patient-vital-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        margin-bottom: 0;
    }
    
    .patient-vital-grid .form-field {
        display: grid;
        grid-template-columns: 90px 1fr;
        align-items: center;
        gap: 8px;
        margin-bottom: 0;
    }
    
    .patient-vital-grid .form-field label {
        font-size: 13px;
        margin: 0;
    }
    
    .patient-vital-grid .form-control {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    /* BMI Display */
    .bmi-display {
        grid-column: 3;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: white;
        border: 1px solid #ffd966;
        border-radius: 5px;
        font-weight: 600;
        font-size: 14px;
        color: #856404;
    }
    
    .bmi-value {
        color: #dc2626;
        font-size: 16px;
    }
    
    .bmi-status {
        font-size: 12px;
        padding: 2px 8px;
        border-radius: 12px;
        background: #10b981;
        color: white;
    }

   /* ===== PHần 3: XÉT NGHIỆM & PHÍ (1 HÀNG NGANG) ===== */
    /* Xét nghiệm */
    .lab-test-section {
        display: flex;
        align-items: center;
        gap: 20px;
        margin: 15px 0;  /* ✅ THAY ĐỔI: giảm từ 25px xuống 15px */
        padding: 15px;   /* ✅ THAY ĐỔI: giảm từ 20px xuống 15px */
    }
    
    .lab-test-section h4 {
        margin: 0;
        min-width: 120px;
        flex-shrink: 0;
    }
    
    .lab-test-options {
        flex: 1;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }

    /* Thu nhỏ chiều cao card xét nghiệm */
    .lab-test-card {
        padding: 10px 12px;
    }
    
    .lab-test-title {
        font-size: 13px;
    }
    
    /* Công khám */
    .service-fee-section {
        display: flex;
        align-items: center;
        gap: 20px;
        margin: 15px 0;  /* ✅ THAY ĐỔI: giảm từ 25px xuống 15px */
        padding: 15px;   /* ✅ THAY ĐỔI: giảm từ 20px xuống 15px */
    }
    
    .service-fee-section h4 {
        margin: 0;
        min-width: 120px;
        flex-shrink: 0;
    }
    
    .fee-options {
        flex: 1;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 15px;
    }

    /* Thu nhỏ chiều cao card công khám và giao hàng */
    .fee-option-card {
        padding: 10px 12px;
    }
    
    .fee-title {
        font-size: 13px;
        margin-bottom: 0;
    }

    /* ===== PHẦN 4: MODAL STRUCTURE ===== */
    /* Prescription Modal - Full height 95vh */
    #prescriptionModal .modal-content {
        max-width: 1000px;
        width: 95%;
        height: 95vh;
        max-height: 95vh;
        margin: 2.5vh auto;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0;
    }
    
    #prescriptionModal .modal-header-new {
        flex: 0 0 auto;
        position: sticky;
        top: 0;
        z-index: 100;
        padding: 12px 20px;
        margin: 0 0 15px 0;
        border-radius: 10px 10px 0 0;
    }
    
    #prescriptionModal .modal-body-scroll {
        flex: 1 1 0;
        overflow-y: auto !important;
        overflow-x: hidden;
        padding: 0 20px 80px 20px;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }
    
    #prescriptionModal .modal-footer {
        flex: 0 0 auto;
        position: sticky;
        bottom: 0;
        margin: 0;
        padding: 12px 20px;
        border-top: 2px solid #e0e0e0;
        background: white;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
        z-index: 100;
        border-radius: 0 0 10px 10px;
    }
    
    #prescriptionModal form {
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    
    /* Quick Add Patient Modal - 90vh */
    #quickAddPatientModal .modal-content {
        max-width: 600px;
        width: 90%;
        height: 90vh;
        max-height: 90vh;
        margin: 5vh auto;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0;
    }
    
    #quickAddPatientModal .modal-header-new {
        flex: 0 0 auto;
        padding: 15px 20px;
        margin: 0;
        border-radius: 10px 10px 0 0;
    }
    
    #quickAddPatientModal .modal-body-scroll {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 20px 25px;
        padding-bottom: 20px;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }
    
    #quickAddPatientModal .modal-footer {
        flex: 0 0 auto;
        position: sticky;
        bottom: 0;
        margin: 0;
        padding: 15px 25px;
        border-top: 2px solid #e0e0e0;
        background: white;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
        z-index: 100;
        border-radius: 0 0 10px 10px;
    }
    
    #quickAddPatientModal form {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
    }
    
    /* Print Options Modal */
    #printOptionsModal .modal-content {
        padding: 0;
    }
    
    #printOptionsModal .modal-header-new {
        padding: 12px 20px;
        margin: 0 0 15px 0;
        border-radius: 10px 10px 0 0;
    }
    
    #printOptionsModal .modal-body-scroll {
        padding: 0 20px 80px 20px;
    }
    
    #printOptionsModal .modal-footer {
        margin: 0;
        padding: 12px 20px;
        border-radius: 0 0 10px 10px;
    }

	/* ===== THÊM: MEDICINE LIST 2 COLUMNS ===== */
    #medicineList {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
        align-items: start;
    }
    
    .medicine-item {
        break-inside: avoid;
        page-break-inside: avoid;
    }

	/* ===== THÊM: GOM XÉT NGHIỆM VÀ GIAO HÀNG THÀNH 1 HÀNG 2 CỘT ===== */
    .lab-and-shipping-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        margin: 15px 0;
    }
    
    .lab-test-section,
    .service-fee-section {
        margin: 0 !important;
    }
}

/* ========== 📱 MOBILE (<= 768px) ========== */
@media (max-width: 768px) {
    /* Prescription Modal - Full screen */
    #prescriptionModal .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        margin: 0;
        padding: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    #prescriptionModal .modal-header-new {
        flex: 0 0 auto;
        margin: 0;
        border-radius: 0;
        padding: 15px 18px;
    }
    
    #prescriptionModal .modal-body-scroll {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px 15px;
        padding-bottom: 100px;
        min-height: 0;
    }
    
    #prescriptionModal .modal-footer {
        flex: 0 0 auto;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 2px solid #e0e0e0;
        padding: 12px 15px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 100;
        margin: 0;
    }
    
    #prescriptionModal form {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
    }
}

/* ==================== PATIENT MERGE PAGE ==================== */
.merge-container {
    max-width: 1200px;
    margin: 0 auto;
}

.merge-search-section {
    background: white;
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.merge-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.patient-card {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.patient-card:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.patient-card.selected-keep {
    border-color: #10b981;
    background: #f0fdf4;
}

.patient-card.selected-remove {
    border-color: #ef4444;
    background: #fef2f2;
}

.patient-card-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 11px;
    font-weight: 700;
    color: white;
}

.badge-keep {
    background: #10b981;
}

.badge-remove {
    background: #ef4444;
}

.patient-card-name {
    font-size: 16px;
    font-weight: 700;
    color: #333;
    margin-bottom: 8px;
}

.patient-card-info {
    font-size: 13px;
    color: #666;
    margin-bottom: 4px;
}

.patient-card-prescriptions {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: #667eea;
    font-weight: 600;
}

.merge-preview-section {
    background: white;
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.merge-comparison {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;
    align-items: center;
    margin: 20px 0;
}

.merge-arrow {
    font-size: 48px;
    color: #667eea;
}

.merge-patient-box {
    padding: 20px;
    border-radius: 10px;
    border: 2px solid #e5e7eb;
}

.merge-patient-box.keep {
    background: #f0fdf4;
    border-color: #10b981;
}

.merge-patient-box.remove {
    background: #fef2f2;
    border-color: #ef4444;
}

.merge-patient-box h4 {
    margin: 0 0 15px 0;
    font-size: 18px;
}

.merge-patient-box.keep h4 {
    color: #10b981;
}

.merge-patient-box.remove h4 {
    color: #ef4444;
}

.merge-info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}

.merge-info-row:last-child {
    border-bottom: none;
}

.merge-info-label {
    color: #666;
    font-weight: 500;
}

.merge-info-value {
    color: #333;
    font-weight: 600;
}

.merge-warning {
    background: #fef3c7;
    border: 2px solid #f59e0b;
    border-radius: 8px;
    padding: 15px;
    margin: 20px 0;
}

.merge-warning-title {
    color: #92400e;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.merge-warning-content {
    color: #92400e;
    font-size: 14px;
    line-height: 1.6;
}

.merge-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .merge-results {
        grid-template-columns: 1fr;
    }
    
    .merge-comparison {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .merge-arrow {
        transform: rotate(90deg);
        font-size: 36px;
    }
    
    .merge-actions {
        flex-direction: column;
    }
    
    .merge-actions button {
        width: 100%;
    }
}

/* ==================== MEDICINE - DISABLED STATE ==================== */
.medicine-search-input:disabled {
    background-color: #f3f4f6 !important;
    cursor: not-allowed !important;
    color: #6b7280 !important;
    opacity: 1 !important;
}

/* Hiển thị rõ trạng thái locked */
.medicine-search-input:disabled::placeholder {
    color: #9ca3af;
    opacity: 0.7;
}

/* Icon khóa khi hover vào input disabled */
.medicine-search-input:disabled:hover {
    cursor: not-allowed;
}

/* ==================== PRINT PREVIEW MODAL - MOBILE SCROLLABLE ==================== */
@media (max-width: 768px) {
    #printPreviewModal .preview-body {
        overflow: auto !important;
        -webkit-overflow-scrolling: touch !important;
        justify-content: flex-start !important;
        align-items: flex-start !important;
    }
    
    #printPreviewModal #previewFrame {
        width: 148mm !important;
        height: 210mm !important;
        min-width: 148mm !important;
        min-height: 210mm !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
    }
}

/* ==================== MEDICINE INACTIVE STATE ==================== */
.medicine-inactive {
    border-color: #fbbf24 !important;
    background: #fffbeb !important;
}

.medicine-inactive .medicine-item-header {
    background: #fef3c7;
    padding: 8px 12px;
    border-radius: 5px;
    margin-bottom: 10px;
}

.medicine-inactive .medicine-search-input:disabled {
    background-color: #fef3c7 !important;
    color: #92400e !important;
    border-color: #fbbf24 !important;
}

/* iOS Safari: Tạm thời tăng font khi focus để không zoom */
@supports (-webkit-touch-callout: none) {
    input[type="text"],
    input[type="tel"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 14px; /* Font bình thường */
    }
    
    input[type="text"]:focus,
    input[type="tel"]:focus,
    input[type="number"]:focus,
    input[type="email"]:focus,
    input[type="password"]:focus,
    select:focus,
    textarea:focus {
        font-size: 16px; /* Tăng lên khi focus để iOS không zoom */
        transition: font-size 0s; /* Không có animation */
    }
}