/* HMIS System - Common Styles */
html {
    font-size: 93.75%; /* Base 15px (was 16px) — ~6% global scale-down; all rem values cascade */
}

/* Professional Color Palette — matches [data-dashboard-theme="default"] in header.php */
:root {
    --primary-color: #0d9488;        /* Teal — default theme primary */
    --secondary-color: #0f766e;      /* Teal dark */
    --accent-color: #14b8a6;         /* Teal light */

    /* Page container */
    --page-container-max-width: 100%;
    --page-container-padding: 16px;

    /* Modal sizes */
    --modal-default: 448px;
    --modal-lg: 576px;
    --modal-xl: 1140px;
    --modal-border-radius: 10px;
    --modal-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);

    --success-color: #059669;
    --warning-color: #d97706;
    --danger-color: #dc2626;
    --info-color: #0891b2;

    --text-color: #1e293b;
    --border-color: #eaecf0;
    --background-color: #f4f6f9;
    --light-color: #f3f4f6;
    --dark-color: #1e2532;

    --gradient-primary: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    --gradient-secondary: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
    --gradient-accent: linear-gradient(135deg, #0891b2 0%, #0f92cf 100%);

    --primary-hover-color: #0f766e;
    --secondary-hover-color: #115e59;
    --success-hover-color: #15803d;
    --warning-hover-color: #b45309;
    --danger-hover-color: #b91c1c;
    --info-hover-color: #0e7490;

    /* ── Design tokens ── */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 20px;

    --shadow-sm: 0 1px 4px rgba(0,0,0,.05);
    --shadow-md: 0 2px 10px rgba(0,0,0,.07);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.09);
    --shadow-card-hover: 0 8px 24px rgba(0,0,0,.09);

    --font-xs: 0.72rem;
    --font-sm: 0.82rem;
    --font-md: 0.88rem;
    --font-base: 1rem;

    /* Module header sizing */
    --module-h1: 1.3rem;
    --module-stat-val: 1.4rem;
    --module-card-label: 0.88rem;
    --module-meta-label: 0.76rem;
    --module-card-radius: var(--radius-lg);
    --module-card-shadow: var(--shadow-sm);
    --module-card-hover-shadow: var(--shadow-card-hover);
    --module-card-border: 1px solid #e8edf3;

    /* Table header */
    --table-head-bg: #f8fafc;
    --table-head-color: #64748b;
}

/* ── Reusable module components ── */
.hmis-module-wrap { max-width: 1400px; margin: 0 auto; padding: 24px; }
.hmis-module-header {
    background: #fff; padding: 16px 20px; border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); margin-bottom: 20px;
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
    border-left: 5px solid var(--primary-color);
}
.hmis-module-header h1 {
    color: var(--primary-color); font-size: var(--module-h1);
    margin: 0; font-weight: 800; display: flex; align-items: center; gap: 10px;
}
.hmis-stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.hmis-stat {
    background: #fff; border-radius: var(--module-card-radius); padding: 20px;
    box-shadow: var(--module-card-shadow); border: var(--module-card-border);
    display: flex; align-items: center; gap: 14px; transition: all .2s;
}
.hmis-stat:hover { box-shadow: var(--module-card-hover-shadow); transform: translateY(-2px); }
.hmis-stat .stat-icon {
    width: 44px; height: 44px; border-radius: var(--radius-md); display: flex;
    align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0;
}
.hmis-stat .stat-val { font-size: var(--module-stat-val); font-weight: 800; color: #1e293b; }
.hmis-stat .stat-label { font-size: var(--module-meta-label); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }
.hmis-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.hmis-nav-card {
    display: flex; align-items: center; gap: 14px; padding: 18px; background: #fff;
    border-radius: var(--module-card-radius); box-shadow: var(--module-card-shadow);
    border: var(--module-card-border); text-decoration: none; color: #1e293b;
    transition: all .2s;
}
.hmis-nav-card:hover { box-shadow: var(--module-card-hover-shadow); transform: translateY(-2px); text-decoration: none; color: #1e293b; }
.hmis-nav-card .card-icon {
    width: 44px; height: 44px; border-radius: var(--radius-md); display: flex;
    align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0;
}
.hmis-nav-card .card-label { font-size: var(--module-card-label); font-weight: 700; }
.hmis-nav-card .card-sub { font-size: var(--font-xs); color: #64748b; }
.hmis-nav-card .card-arrow { margin-left: auto; color: #cbd5e1; font-size: 0.8rem; }

/* ── Icon color palette ── */
.icon-teal    { background: #ccfbf1; color: #0d9488; }
.icon-blue    { background: #dbeafe; color: #1d4ed8; }
.icon-green   { background: #dcfce7; color: #16a34a; }
.icon-amber   { background: #fef3c7; color: #d97706; }
.icon-red     { background: #fee2e2; color: #dc2626; }
.icon-purple  { background: #f3e8ff; color: #7c3aed; }
.icon-indigo  { background: #e0e7ff; color: #4f46e5; }
.icon-cyan    { background: #cffafe; color: #0891b2; }
.icon-emerald { background: #d1fae5; color: #059669; }
.icon-slate   { background: #f1f5f9; color: #475569; }

/* ── Table header standardization ── */
.table thead th, .hmis-table thead th {
    background: var(--table-head-bg) !important;
    color: var(--table-head-color);
    font-size: var(--font-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}




.rx {
    font-family: "Satisfy", cursive;
    font-size: 28px;
    color: #1d6fa5;
    margin-left: 8px;
    font-weight: 600;
}

/* Enhanced Checkbox Styling - Add this to your CSS */

/* Native checkbox with better visibility */
input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    vertical-align: middle;
    margin-right: 8px;
}

/* Hover state */
input[type="checkbox"]:hover {
    border-color: var(--primary-color, #0d9488);
    box-shadow: 0 0 0 3px rgba(13,148,136, 0.12);
}

/* Checked state */
input[type="checkbox"]:checked {
    background-color: var(--primary-color, #0d9488);
    border-color: var(--primary-color, #0d9488);
}

/* Checkmark (tick) */
input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Focus state for accessibility */
input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--primary-color, #0d9488);
    outline-offset: 2px;
}

/* Disabled state */
input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Touch-friendly sizing for mobile */
@media (max-width: 768px) {
    input[type="checkbox"] {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }
    
    input[type="checkbox"]:checked::after {
        left: 7px;
        top: 3px;
        width: 6px;
        height: 12px;
    }
}

/* Extra large checkboxes for forms that need emphasis */
input[type="checkbox"].checkbox-lg {
    width: 28px;
    height: 28px;
}

input[type="checkbox"].checkbox-lg:checked::after {
    left: 8px;
    top: 4px;
    width: 7px;
    height: 14px;
}

/* Label styling for better UX */
label:has(input[type="checkbox"]) {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

/* Table checkbox alignment */
.table input[type="checkbox"] {
    margin: 0 auto;
    display: block;
}

/* Form group checkbox layout */
.form-group.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-group.checkbox-group label {
    margin-bottom: 0;
}

.form-group.checkbox-group input[type="checkbox"] {
    margin-right: 0;
}



/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 87.5%; /* ~14px base — overridden by _ui_overrides.css with !important */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Heading sizes — overridden by _ui_overrides.css with !important */
h1 { font-size: 1.75rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }
h5 { font-size: .9rem; }
h6 { font-size: .82rem; }

/* Reduce padding and margins globally for more compact layout */
.container, .container-fluid {
    padding-left: calc(1em * 0.93);
    padding-right: calc(1em * 0.93);
}

.card {
    padding: calc(1em * 0.93);
}

.card-body, .card-header {
    padding: calc(1em * 0.93);
}

.btn {
    padding: calc(12px * 0.93) calc(24px * 0.93);
    font-size: calc(1rem * 0.93);
}

.form-control, input:not([type="checkbox"]):not([type="radio"]), select, textarea {
    padding: calc(0.75em * 0.93) calc(1em * 0.93);
    font-size: calc(1rem * 0.93);
}

.table th, .table td {
    padding: calc(0.75em * 0.93) calc(1em * 0.93);
    font-size: calc(1rem * 0.93);
}

h1#previewDoctorName {
    text-align: left;
}
h1#clinicName {
    text-align: left;
}
/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

/* Typography sizes are now defined above in global reduction */

p {
    margin-bottom: 1rem;
}

/* Links */
a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--primary-color);
}

/* Buttons - Touch-friendly (minimum 44x44px for mobile) */
.btn {
    padding: 12px 24px;
    min-height: 44px; /* Minimum touch target size */
    min-width: 44px;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    text-align: center;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    touch-action: manipulation; /* Optimize touch response */
}

.btn-primary {
    background: var(--primary-color, #0d9488);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover-color, #0f766e);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(13, 148, 136, 0.35);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: var(--success-hover-color, #047857);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(5, 150, 105, 0.4);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover-color, #b91c1c);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 38, 38, 0.4);
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    background: var(--warning-hover-color, #b45309);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(217, 119, 6, 0.4);
}

.btn-info {
    background: var(--info-color);
    color: white;
}

.btn-info:hover {
    background: var(--info-hover-color, #0e7490);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(8, 145, 178, 0.4);
}

.btn-sm {
    padding: 8px 16px;
    min-height: 36px; /* Still touch-friendly but smaller */
    min-width: 36px;
    font-size: 0.9rem;
}

.btn-lg {
    padding: 15px 30px;
    font-size: 1.1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #374151;
    font-size: 0.85rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    min-height: 44px; /* Touch-friendly input height */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm, 6px);
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    -webkit-appearance: none; /* Remove iOS styling */
    -moz-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color, #0d9488);
    box-shadow: 0 0 0 3px rgba(13,148,136, 0.12);
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius-md, 10px);
    box-shadow: var(--shadow-md, 0 2px 10px rgba(0,0,0,0.07));
    margin-bottom: 20px;
    overflow: hidden;
    border: none;
}

.card-header {
    background: var(--table-head-bg, #f8fafc);
    color: var(--text-color, #1e293b);
    padding: 13px 17px;
    border-bottom: 1px solid var(--border-color, #eaecf0);
}

.card-header h3,
.card-header h5 {
    margin: 0;
    color: var(--text-color, #1e293b);
}

.card-body {
    padding: 20px;
}

/* Tables — _ui_overrides.css provides the final styles with !important */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.table th,
.table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: #f6f8fb;
    color: #6b7280;
    font-weight: 600;
}

.table tbody tr:hover {
    background-color: var(--light-color);
}

/* Navigation — uses theme's --dark-color, _ui_overrides.css adds gradient */
.navbar {
    background: var(--dark-color, #1e2532);
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    padding: .5rem 0;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    min-height: 44px; /* Touch-friendly */
}

.navbar-toggler {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 8px 12px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
}

.navbar-toggler-icon {
    width: 1.5em;
    height: 1.5em;
}

.navbar-nav {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
}

.navbar-nav .nav-item {
    margin-right: 1rem;
}

.navbar-nav .nav-link {
    color: white;
    text-decoration: none;
    padding: 0.75rem 1rem;
    border-radius: 5px;
    transition: background-color 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px; /* Touch-friendly */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link.active {
    background-color: rgba(255, 255, 255, 0.2);
}

.navbar-nav .nav-link:active {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Dropdown menu touch-friendly */
.dropdown-menu {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 0.5rem 0;
}

.dropdown-item {
    padding: 12px 20px;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background-color 0.2s;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: #f8f9fa;
}

.dropdown-item:active {
    background-color: #e9ecef;
}


/* Containers */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
}

/* Unified page container - consistent width across all app pages (overrides inline styles) */
.patient-management-container,
.billing-container,
.user-container,
.appointment-container,
.inventory-container,
.lab-results-container,
.medicine-container,
.drug-type-container,
.category-container,
.frequency-container,
.duration-container,
.instruction-container,
.template-container,
.diagnosis-container,
.investigation-container,
.departments-container,
.roles-container,
.settings-container,
.settings-manager,
.summary-container,
.integrations-container,
.reports-container,
.cp-container,
.rates-container,
.drawing-pad-container,
.advanced-search-container {
    max-width: var(--page-container-max-width) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    width: 100%;
}

/* Main content area - full width for dashboard and all pages */
.main-content {
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: var(--page-container-padding);
}

.container-fluid {
    width: 100%;
    padding: 0 15px;
}

/* Grid System */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.col {
    flex: 1;
    padding: 0 15px;
}

.col-md-3 { flex: 0 0 25%; }
.col-md-6 { flex: 0 0 50%; }
.col-md-9 { flex: 0 0 75%; }
.col-md-12 { flex: 0 0 100%; }

/* Utilities */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--primary-color); }
.text-secondary { color: var(--secondary-color); }
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }
.text-info { color: var(--info-color); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mb-5 { margin-bottom: 3rem; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mt-5 { margin-top: 3rem; }

.p-0 { padding: 0; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.5rem; }
.p-5 { padding: 3rem; }

/* Alerts */
.alert {
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid transparent;
    border-radius: 5px;
}

.alert-success {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
}

.alert-danger {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
}

.alert-warning {
    color: #856404;
    background-color: #fff3cd;
    border-color: #ffeaa7;
}

.alert-info {
    color: #0c5460;
    background-color: #d1ecf1;
    border-color: #bee5eb;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25em 0.4em;
    font-size: 75%;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
}

.badge-primary { background-color: var(--primary-color); color: white; }
.badge-secondary { background-color: var(--secondary-color); color: white; }
.badge-success { background-color: var(--success-color); color: white; }
.badge-danger { background-color: var(--danger-color); color: white; }
.badge-warning { background-color: var(--warning-color); color: white; }
.badge-info { background-color: var(--info-color); color: white; }

/* ============================================================================
   MODALS - Consistent design across all pages
   Use: .modal-content (default 560px), .modal-lg (720px), .modal-xl (960px)
   ============================================================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 1rem 0;
}

/* Standalone modal-content (no modal-dialog wrapper) */
.modal-content {
    position: relative;
    background: #fff;
    margin: auto;
    padding: 0;
    width: 90%;
    max-width: var(--modal-default);
    border-radius: var(--modal-border-radius);
    box-shadow: var(--modal-shadow);
    max-height: 88vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-lg {
    max-width: var(--modal-lg);
}

.modal-content.modal-xl {
    max-width: var(--modal-xl);
}

/* Bootstrap-style modal-dialog wrapper */
.modal-dialog {
    margin: auto;
    max-width: var(--modal-default);
    width: 90%;
}

.modal-dialog.modal-lg {
    max-width: var(--modal-lg);
}

.modal-dialog.modal-xl {
    max-width: var(--modal-xl);
}

.modal-dialog .modal-content {
    width: 100%;
    max-width: 100%;
}

.modal-dialog-scrollable .modal-body {
    overflow-y: auto;
    max-height: 70vh;
}

/* Modal Header */
.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%) !important;
    color: #fff !important;
    padding: 18px 24px;
    border-radius: var(--modal-border-radius) var(--modal-border-radius) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h1,
.modal-header h2,
.modal-header h3,
.modal-header h4,
.modal-header h5,
.modal-header h6 {
    color: #fff !important;
    margin: 0;
    font-weight: 600;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header i {
    color: #fff !important;
    opacity: 0.95;
}

/* Bootstrap btn-close in modal header - ensure visible on dark background */
.modal-header .btn-close {
    filter: brightness(0) invert(1);
    opacity: 0.9;
}
.modal-header .btn-close:hover {
    opacity: 1;
}
.modal-header .modal-title {
    color: #fff !important;
}

/* Modal Body */
.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1 1 auto;
    background: #f9fafb;
}

/* Modal Footer */
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    background: #fff;
    border-radius: 0 0 var(--modal-border-radius) var(--modal-border-radius);
}

.close-modal {
    color: #fff !important;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    opacity: 0.9;
    transition: opacity 0.2s;
    line-height: 1;
    padding: 4px;
}

.close-modal:hover {
    opacity: 1;
    color: #fff !important;
}

/* Table Header - Ensure proper contrast (same as modal headers) */
.table-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%) !important;
    color: #ffffff !important;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h1,
.table-header h2,
.table-header h3,
.table-header h4,
.table-header h5,
.table-header h6 {
    color: #ffffff !important;
    margin: 0;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.table-header i {
    color: #ffffff !important;
    margin-right: 8px;
}

.table-header button,
.table-header .btn {
    color: #ffffff !important;
}

/* Table header — light neutral style consistent across all modules */
.table th {
    background: var(--table-head-bg, #f8fafc);
    color: var(--table-head-color, #64748b);
    font-weight: 600;
}
/* Dark header variant for specific tables */
.table-dark-head th {
    background: var(--primary-color) !important;
    color: #ffffff !important;
    font-weight: 600;
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 10px;
    font-size: 24px;
    cursor: pointer;
    color: var(--accent-color);
}

/* Loading States */
.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   COMPREHENSIVE MOBILE RESPONSIVENESS
   ============================================ */

/* Tablet and below (768px) */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .container-fluid {
        padding: 0 10px;
    }
    
    .row {
        flex-direction: column;
        margin: 0 -10px;
    }
    
    .col-md-3,
    .col-md-6,
    .col-md-9,
    .col-md-12 {
        flex: 0 0 100%;
        padding: 0 10px;
    }
    
    /* Typography adjustments */
    h1 { 
        font-size: 2rem;
        padding: 10px;
    }
    h2 { font-size: 1.75rem; }
    h3 { font-size: 1.5rem; }
    h4 { font-size: 1.25rem; }
    
    /* Navigation improvements */
    .navbar {
        padding: 0.75rem 0;
    }
    
    .navbar-brand {
        font-size: 1.25rem;
        padding: 0.5rem 0.75rem;
    }
    
    .navbar-toggler {
        padding: 10px 14px;
        min-width: 48px;
        min-height: 48px;
    }
    
    .navbar-nav {
        flex-direction: column;
        width: 100%;
        margin-top: 1rem;
    }
    
    .navbar-nav .nav-item {
        margin-right: 0;
        margin-bottom: 0.25rem;
        width: 100%;
    }
    
    .navbar-nav .nav-link {
        padding: 14px 16px;
        min-height: 48px;
        display: flex;
        align-items: center;
        width: 100%;
        font-size: 1rem;
    }
    
    .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin-top: 0;
        border: none;
        box-shadow: none;
        background-color: rgba(255, 255, 255, 0.1);
    }
    
    .dropdown-item {
        padding: 14px 24px;
        min-height: 48px;
        color: white;
        font-size: 0.95rem;
    }
    
    .dropdown-item:hover,
    .dropdown-item:focus,
    .dropdown-item:active {
        background-color: rgba(255, 255, 255, 0.2);
        color: white;
    }
    
    /* Cards */
    .card {
        margin-bottom: 15px;
        border-radius: 8px;
    }
    
    .card-header {
        padding: 15px;
    }
    
    .card-body {
        padding: 15px;
    }
    
    /* Tables - make scrollable */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }
    
    .table {
        min-width: 600px; /* Force horizontal scroll on small screens */
    }
    
    .table th,
    .table td {
        padding: 10px 8px;
        font-size: 0.9rem;
    }
    
    /* Modals */
    .modal-content,
    .modal-dialog {
        width: 95%;
        max-width: 95%;
        margin: 10px auto;
        max-height: 90vh;
    }
    
    .close-modal {
        right: 15px;
        top: 15px;
        font-size: 28px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Stat cards */
    .stat-card {
        padding: 20px;
    }
    
    .stat-number {
        font-size: 2rem;
    }
    
    .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    /* Forms */
    .form-group {
        margin-bottom: 1rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Buttons - ensure touch-friendly */
    .btn {
        padding: 14px 20px;
        min-height: 48px; /* Larger on mobile for easier tapping */
        font-size: 1rem;
    }
    
    /* Full width buttons in action groups, but not inline */
    .action-buttons .btn,
    .btn-group .btn,
    .quick-actions .btn,
    form .btn[type="submit"],
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .btn:last-child,
    .action-buttons .btn:last-child,
    .btn-group .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Inline buttons in tables/cards should remain inline */
    .table .btn,
    .card-body .btn:not([type="submit"]):not(.action-buttons .btn),
    .btn-inline {
        width: auto;
        display: inline-flex;
        margin-bottom: 0;
    }
    
    /* Alerts */
    .alert {
        padding: 12px;
        font-size: 0.95rem;
    }
    
    /* Main content */
    .main-content {
        padding: 10px;
    }
}

/* Mobile phones (480px and below) */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    .container-fluid {
        padding: 0 8px;
    }
    
    /* Typography */
    h1 { 
        font-size: 1.75rem;
        padding: 8px;
    }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    
    /* Buttons */
    .btn {
        padding: 12px 16px;
        min-height: 48px;
        font-size: 0.95rem;
    }
    
    /* Inline buttons should remain inline on small screens too */
    .table .btn,
    .card-body .btn:not([type="submit"]):not(.action-buttons .btn),
    .btn-inline {
        width: auto;
        min-width: 44px;
        padding: 10px 14px;
    }
    
    .btn-sm {
        padding: 10px 14px;
        min-height: 44px;
        font-size: 0.9rem;
    }
    
    /* Modals */
    .modal-content {
        margin: 5px auto;
        width: 98%;
        padding: 15px;
        max-height: 95vh;
    }
    
    /* Cards */
    .card-header {
        padding: 12px;
    }
    
    .card-body {
        padding: 12px;
    }
    
    /* Tables */
    .table th,
    .table td {
        padding: 8px 6px;
        font-size: 0.85rem;
    }
    
    /* Stat cards */
    .stat-card {
        padding: 15px;
    }
    
    .stat-number {
        font-size: 1.75rem;
    }
    
    .stat-icon {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    /* Forms */
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 14px; /* Larger padding for easier tapping */
        min-height: 48px;
    }
    
    /* Navigation */
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    /* Alerts */
    .alert {
        padding: 10px;
        font-size: 0.9rem;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: 85vh;
    }
    
    .split-container {
        height: auto;
        min-height: calc(100vh - 100px);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
    
    .stat-card:hover {
        transform: none;
    }
    
    /* Increase tap targets */
    a, button, input[type="button"], input[type="submit"], 
    input[type="checkbox"], input[type="radio"], select {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better touch feedback */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* Prevent text selection on buttons */
    .btn, .nav-link, .quick-action-btn {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
}

/* Print Styles */
@media print {
    .navbar,
    .btn,
    .modal {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .table th {
        background: #f5f5f5 !important;
        color: black !important;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* Urdu Text Support */
.urdu {
    direction: rtl;
    font-family: 'Noto Nastaliq Urdu', 'Arial', sans-serif;
    text-align: right;
}

/* Specialized Components */
.stat-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.stat-card-link:hover {
    text-decoration: none;
    color: inherit;
}

.stat-card {
    background: white;
    border-radius: 10px;
    padding: 16px 18px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    border: 1px solid #e5e7eb;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient-primary);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    margin-bottom: 15px;
}

/* Professional stat icon gradients */
.stat-icon.patients { background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%); }
.stat-icon.appointments { background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%); }
.stat-icon.revenue { background: linear-gradient(135deg, #059669 0%, #047857 100%); }
.stat-icon.pending { background: linear-gradient(135deg, #d97706 0%, #b45309 100%); }

.stat-number {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--dark-color);
    margin-bottom: 5px;
}

.stat-label {
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
}

/* Quick Actions Styling */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 30px 0;
    padding: 20px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
}

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 25px 20px;
    background: var(--gradient-secondary);
    color: white;
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.25);
    position: relative;
    overflow: hidden;
    min-height: 120px;
}

.quick-action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.quick-action-btn:hover::before {
    left: 100%;
}

.quick-action-btn i {
    font-size: 2.5rem;
    transition: transform 0.3s ease;
    position: relative;
    z-index: 1;
}

.quick-action-btn span {
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    position: relative;
    z-index: 1;
}

.quick-action-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.4);
    text-decoration: none;
    color: white;
    background: var(--gradient-secondary, linear-gradient(135deg, #1e40af 0%, #2563eb 100%));
}

.quick-action-btn:hover i {
    transform: scale(1.2) rotate(5deg);
}

/* All quick-action buttons use the same theme color - removed individual variations */

/* Responsive adjustments for quick actions */
@media (max-width: 768px) {
    .quick-actions {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 15px;
        padding: 15px;
    }
    
    .quick-action-btn {
        padding: 20px 15px;
        min-height: 100px;
    }
    
    .quick-action-btn i {
        font-size: 2rem;
    }
    
    .quick-action-btn span {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }
    
    .quick-action-btn {
        padding: 15px 10px;
        min-height: 90px;
    }
    
    .quick-action-btn i {
        font-size: 1.75rem;
    }
    
    .quick-action-btn span {
        font-size: 0.75rem;
    }
}



    /* Split-screen layout */
    .split-container {
        display: flex;
        height: calc(100vh - 120px);
        gap: 20px;
        padding: 20px;
        background: #f5f5f5;
    }

    .form-panel {
        flex: 0 0 75%; /* 9/12 = 75% */
        background: white;
        border-radius: 10px;
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
        overflow-y: auto;
        padding: 20px;
        display: flex;
        flex-direction: column;
    }

    .preview-panel {
        flex: 0 0 25%; /* 3/12 = 25% */
        background: white;
        border-radius: 10px;
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
        padding: 12px;
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        overflow-x: hidden;
        overflow-y: auto;
    }

    /* Responsive Design - Mobile Layout */
    @media (max-width: 768px) {
        .split-container {
            flex-direction: column;
            height: auto;
            min-height: auto;
            gap: 15px;
            padding: 15px;
        }

        .form-panel {
            flex: 1;
            width: 100%;
            order: 1;
            padding: 15px;
            max-height: none;
        }

        .preview-panel {
            flex: 1;
            width: 100%;
            order: 2;
            min-height: 400px;
            padding: 15px;
        }

        .print-preview {
            /* JS handles scale dynamically */
            width: 794px;
        }
    }

    @media (max-width: 480px) {
        .split-container {
            padding: 10px;
            gap: 10px;
        }

        .form-panel,
        .preview-panel {
            padding: 10px;
        }

        .print-preview {
            width: 794px;
        }
    }

    /* Prescription-specific styles */
    .prescription-container {
        max-width: 100%;
        margin: 0;
        background: transparent;
        padding: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .prescription-header {
        display: flex;
        align-items: flex-start;
        border-bottom: 2px solid var(--primary-color);
        padding-bottom: 20px;
        margin-bottom: 30px;
        gap: 20px;
    }

    .prescription-logo {
        width: 82px;
        height: 82px;
        /* margin-right: 30px; */
    }

    .clinic-info {
        flex-grow: 1;
    }

    .clinic-info h1 {
        margin: 0;
        font-size: 2.2rem;
        color: var(--primary-color);
    }

    .clinic-info p {
        margin: 5px 0;
        color: #666;
    }

    .clinic-info i {
        margin-right: 8px;
        color: var(--secondary-color);
    }

    /* ---------------------------------------------------------------------- */
    /* Prescription v2 layout helpers                                         */
    /* ---------------------------------------------------------------------- */
    .prescription-form-v2 {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    .patient-info-fixed {
        position: sticky;
        top: -20px;
        z-index: 100;
        background: #fff;
        padding: 15px 18px;
        border: 1px solid var(--border-color);
        border-radius: 10px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    }

    .patient-info-compact {
        display: flex;
        flex-direction: column;
        gap: 10px;
        font-size: 0.9rem;
    }

    .patient-info-row {
        display: flex;
        flex-wrap: wrap;
        gap: 18px;
        align-items: center;
    }

    .patient-info-item {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        color: var(--text-color);
        white-space: nowrap;
    }

    .patient-info-item strong {
        color: var(--secondary-color);
        font-weight: 600;
        font-size: 0.85rem;
    }

    .patient-info-item-full {
        flex: 1;
        min-width: 220px;
    }

    .patient-info-compact .prescription-input,
    .patient-info-compact select.prescription-input {
        padding: 6px 12px;
        min-height: 34px;
        font-size: 0.9rem;
    }

    /* Tabs layout */
    .tab-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        margin-top: 12px;
    }

    .tab-button {
        flex: 1;
        min-width: 140px;
        padding: 10px 12px;
        border: 1px solid var(--border-color);
        border-radius: 6px;
        background: #fff;
        color: var(--secondary-color);
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        transition: all 0.2s ease;
    }

    .tab-button i {
        font-size: 0.9rem;
    }

    .tab-button:hover,
    .tab-button:focus-visible {
        border-color: var(--secondary-color);
        color: var(--primary-color);
        outline: none;
    }

    .tab-button.active {
        background: var(--secondary-color);
        color: #fff;
        border-color: var(--secondary-color);
        box-shadow: 0 6px 15px rgba(14, 35, 98, 0.2);
    }

    .tabs-content-wrapper {
        flex: 1;
        overflow-y: auto;
        padding-right: 4px;
    }

    .prescription-tabs {
        display: flex;
        flex-direction: column;
        gap: 18px;
    }

    .prescription-tabs .tab-content {
        display: none;
        animation: fadeIn 0.25s ease-in;
    }

    .prescription-tabs .tab-content.active {
        display: block;
    }

    .action-buttons-fixed {
        position: sticky;
        bottom: -20px;
        background: #fff;
        padding: 15px 20px;
        border: 1px solid var(--border-color);
        border-radius: 10px;
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.05);
        margin-top: 10px;
        z-index: 80;
    }

    .action-buttons-fixed .action-buttons {
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .tabs-content-wrapper::-webkit-scrollbar {
        width: 6px;
    }

    .tabs-content-wrapper::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.15);
        border-radius: 3px;
    }

    @media (max-width: 1024px) {
        .patient-info-fixed {
            top: 0;
        }

        .tab-button {
            flex: 1 1 45%;
        }
    }

    @media (max-width: 768px) {
        .patient-info-fixed {
            padding: 12px 14px;
        }

        .patient-info-row {
            flex-direction: column;
            align-items: flex-start;
        }

        .patient-info-item,
        .patient-info-item-full {
            width: 100%;
            white-space: normal;
        }

        .tab-button {
            flex: 1 1 100%;
        }

        .action-buttons-fixed {
            position: static;
            box-shadow: none;
            border-radius: 8px;
        }

        .action-buttons-fixed .action-buttons {
            flex-direction: column;
            align-items: stretch;
        }
    }

    @media (max-width: 480px) {
        .patient-info-compact {
            font-size: 0.8rem;
        }

        .patient-info-item strong {
            font-size: 0.78rem;
        }

        .tab-button {
            font-size: 0.85rem;
        }
    }

    .prescription-section {
        margin-bottom: 30px;
        background: white;
        padding: 20px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
    }

    .prescription-section h2 {
        color: var(--primary-color);
        font-size: 1.4rem;
        margin-bottom: 15px;
        padding-bottom: 8px;
        border-bottom: 2px solid var(--secondary-color);
    }

    .prescription-section.has-manager h2 {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .manage-btn {
        font-size: 0.8rem;
        padding: 4px 8px;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        background: transparent;
        color: var(--secondary-color);
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        transition: all 0.2s ease;
    }

    .manage-btn:hover {
        background: var(--secondary-color);
        color: white;
        border-color: var(--secondary-color);
    }

    .manage-btn i {
        font-size: 0.8rem;
    }

    @media print {
        .manage-btn {
            display: none;
        }
    }

    .form-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        align-items: end;
    }

    .form-group {
        margin-bottom: 0;
    }

    .form-group label {
        display: block;
        margin-bottom: 4px;
        color: #666;
        font-weight: 500;
        font-size: 0.85rem;
    }

    .prescription-input, .prescription-textarea {
        width: 100%;
        padding: 10px;
        min-height: 44px; /* Touch-friendly height */
        border: 1px solid var(--border-color);
        border-radius: 4px;
        font-size: 16px; /* Prevent zoom on iOS */
        transition: border-color 0.3s;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    .form-group.full-width {
        grid-column: 1 / -1;
    }

    @media (max-width: 768px) {
        .form-grid {
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
        }
        
        .prescription-input, .prescription-textarea {
            padding: 12px;
            min-height: 48px;
            font-size: 16px;
        }
        
        .form-group label {
            font-size: 0.9rem;
            margin-bottom: 6px;
        }
    }

    @media (max-width: 480px) {
        .form-grid {
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
        }
        
        .prescription-input, .prescription-textarea {
            padding: 14px;
            min-height: 48px;
        }
        
        .form-group.full-width {
            grid-column: 1 / -1;
        }
    }

    .prescription-input:focus, .prescription-textarea:focus {
        outline: none;
        border-color: var(--secondary-color);
        box-shadow: 0 0 5px rgba(37, 99, 235, 0.2);
    }

    .med-table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 10px;
        background: white;
        overflow-x: auto;
        display: table;
        -webkit-overflow-scrolling: touch;
    }

    .med-table thead,
    .med-table tbody,
    .med-table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    .med-table thead {
        display: table-header-group;
    }

    .med-table tbody {
        display: table-row-group;
    }

    .med-table th {
        background: var(--primary-color);
        color: white;
        padding: 12px;
        text-align: left;
        font-size: 0.9rem;
        font-weight: 600;
        white-space: nowrap;
    }

    .med-table td {
        padding: 12px;
        border: 1px solid var(--border-color);
        text-align: left;
        vertical-align: middle;
        word-break: break-word;
    }

    .med-table tr {
        cursor: move;
        background: white;
        transition: background-color 0.2s;
        display: table-row;
    }

    .med-table tr:hover {
        background-color: #f8f9fa;
    }

    .med-table tr.dragging {
        opacity: 0.5;
        background-color: #e9ecef;
    }

    .med-table tr.drag-over {
        border-top: 2px solid var(--secondary-color);
    }

    .med-table input {
        border: none;
        padding: 8px;
        width: 100%;
        min-height: 40px;
        font-size: 16px; /* Prevent zoom on iOS */
        background: transparent;
        box-sizing: border-box;
    }
    
    .med-table input:focus {
        outline: 2px solid var(--secondary-color);
        outline-offset: -2px;
        border-radius: 3px;
    }

    .med-table select {
        width: 100%;
        padding: 8px;
        min-height: 40px;
        font-size: 16px;
        border: none;
        background: transparent;
        box-sizing: border-box;
    }

    .med-table select:focus {
        outline: 2px solid var(--secondary-color);
        outline-offset: -2px;
        border-radius: 3px;
    }
    
    /* Mobile-first responsive design */
    @media (max-width: 768px) {
        .med-table {
            display: block;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            border: 1px solid var(--border-color);
            border-radius: 8px;
        }

        .med-table thead {
            display: none; /* Hide header on mobile */
        }

        .med-table tbody {
            display: block;
        }

        .med-table tr {
            display: block;
            margin-bottom: 15px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 12px;
            background: #f8f9fa;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .med-table tr:last-child {
            margin-bottom: 0;
        }

        .med-table td {
            display: block;
            padding: 10px 0;
            border: none;
            border-bottom: 1px solid #e0e0e0;
            text-align: left;
            position: relative;
            padding-left: 40%;
        }

        .med-table td:last-child {
            border-bottom: none;
        }

        .med-table td:before {
            content: attr(data-label);
            position: absolute;
            left: 0;
            width: 35%;
            padding-right: 10px;
            white-space: nowrap;
            font-weight: 600;
            color: var(--primary-color);
            font-size: 0.85rem;
        }

        .med-table td:last-child:before {
            display: none;
        }

        .med-table input,
        .med-table select {
            width: 100%;
            padding: 10px;
            min-height: 44px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background: white;
        }

        .med-table input:focus,
        .med-table select:focus {
            border-color: var(--secondary-color);
            outline: none;
            box-shadow: 0 0 5px rgba(37, 99, 235, 0.2);
        }

        /* Action column styling */
        .med-table td:last-child {
            text-align: center;
            padding: 10px 0;
        }

        .med-table td:last-child:before {
            display: block;
            content: "Action";
            position: static;
            width: 100%;
            margin-bottom: 8px;
        }
    }
    
    @media (max-width: 480px) {
        .med-table tr {
            padding: 10px;
            margin-bottom: 12px;
        }

        .med-table td {
            padding: 8px 0;
            padding-left: 35%;
            font-size: 0.9rem;
        }

        .med-table td:before {
            font-size: 0.8rem;
            width: 32%;
        }

        .med-table input,
        .med-table select {
            padding: 12px;
            min-height: 48px;
            font-size: 16px;
        }

        /* Make delete button more touch-friendly */
        .med-table .delete-row {
            padding: 12px;
            min-width: 48px;
            min-height: 48px;
            font-size: 1.2rem;
        }
    }

    /* Very small screens - stack everything */
    @media (max-width: 360px) {
        .med-table td {
            padding-left: 0;
            padding-top: 35px;
        }

        .med-table td:before {
            position: absolute;
            top: 8px;
            left: 0;
            width: 100%;
            padding-right: 0;
            margin-bottom: 5px;
        }
    }

    .urdu {
        direction: rtl;
        font-family: 'Noto Nastaliq Urdu', serif;
        font-size: 1.3rem;
        text-align: right;
    }

    .prescription-btn {
        padding: 12px 24px;
        min-height: 44px; /* Touch-friendly minimum */
        min-width: 44px;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 1rem;
        font-weight: 500;
        transition: all 0.3s;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .prescription-btn-primary {
        background: var(--secondary-color);
        color: white;
    }

    .prescription-btn-primary:hover {
        background: #2980b9;
    }

    .prescription-btn-primary:disabled {
        background: #95a5a6;
        color: white;
        cursor: not-allowed;
        opacity: 0.6;
    }

    .prescription-btn-primary:disabled:hover {
        background: #95a5a6;
    }

    .prescription-btn-danger {
        background: var(--accent-color);
        color: white;
    }

    .prescription-btn-danger:hover {
        background: #c0392b;
    }

    .action-buttons {
        display: flex;
        gap: 15px;
        margin-top: 20px;
    }

    /* Responsive Action Buttons */
    @media (max-width: 768px) {
        .action-buttons {
            flex-direction: column;
            gap: 12px;
            margin-top: 20px;
        }

        .action-buttons .prescription-btn {
            width: 100%;
            min-height: 48px; /* Larger on mobile */
            padding: 14px 20px;
            justify-content: center;
            font-size: 1rem;
        }
    }

    @media (max-width: 480px) {
        .action-buttons {
            gap: 10px;
            margin-top: 15px;
        }
        
        .action-buttons .prescription-btn {
            min-height: 50px;
            padding: 16px 20px;
        }
    }

    .delete-row {
        color: var(--accent-color);
        cursor: pointer;
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .delete-row:hover {
        color: #dc2626;
        background-color: rgba(220, 38, 38, 0.1);
    }
    
    .delete-row:active {
        background-color: rgba(220, 38, 38, 0.2);
        transform: scale(0.95);
    }
    
    @media (max-width: 768px) {
        .delete-row {
            padding: 10px;
            min-width: 48px;
            min-height: 48px;
            font-size: 1.1rem;
        }
    }

    .diagnosis-container {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .diagnosis-container select {
        margin-bottom: 10px;
    }

    .instructions-container {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .instructions-container textarea {
        width: 100%;
        padding: 12px;
        min-height: 100px;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        font-size: 16px; /* Prevent zoom on iOS */
        resize: vertical;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
    
    @media (max-width: 768px) {
        .instructions-container textarea {
            padding: 14px;
            min-height: 120px;
        }
    }

    .instructions-container textarea:focus {
        outline: none;
        border-color: var(--secondary-color);
        box-shadow: 0 0 5px rgba(37, 99, 235, 0.2);
    }

    /* Image Upload Styles */
    .image-upload-section {
        margin-bottom: 30px;
        background: white;
        padding: 20px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
    }

    .image-upload-container {
        border: 2px dashed var(--border-color);
        padding: 20px;
        border-radius: 8px;
        text-align: center;
        background: #f8f9fa;
        transition: all 0.3s;
        cursor: pointer;
    }

    .image-upload-container:hover {
        border-color: var(--secondary-color);
        background: #e3f2fd;
    }

    .image-upload-container.dragover {
        border-color: var(--primary-color);
        background: #e8f5e8;
    }

    .upload-icon {
        font-size: 48px;
        color: var(--secondary-color);
        margin-bottom: 10px;
    }

    .upload-text {
        color: #666;
        margin-bottom: 10px;
    }

    .upload-hint {
        font-size: 12px;
        color: #999;
    }

    .image-preview-container {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 15px;
        margin-top: 20px;
    }

    .image-preview-item {
        position: relative;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        overflow: hidden;
        background: white;
    }

    .image-preview-item img {
        width: 100%;
        height: 120px;
        object-fit: cover;
        display: block;
    }

    .image-preview-item .remove-btn {
        position: absolute;
        top: 5px;
        right: 5px;
        background: rgba(220, 38, 38, 0.8);
        color: white;
        border: none;
        border-radius: 50%;
        min-width: 36px;
        min-height: 36px;
        width: 36px;
        height: 36px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    @media (max-width: 768px) {
        .image-preview-item .remove-btn {
            min-width: 44px;
            min-height: 44px;
            width: 44px;
            height: 44px;
            font-size: 16px;
        }
    }

    .image-preview-item .remove-btn:hover {
        background: #e74c3c;
    }

    .image-preview-item .image-name {
        padding: 8px;
        font-size: 12px;
        color: #666;
        text-align: center;
        word-break: break-all;
    }

    /* Print Preview Image Styles */
    .print-preview .images-section {
        margin-bottom: 20px;
    }

    .print-preview .images-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 8px;
        margin-top: 5px;
    }

    .print-preview .image-item {
        border: 1px solid #ddd;
        border-radius: 4px;
        overflow: hidden;
        text-align: center;
    }

    .print-preview .image-item img {
        width: 100%;
        height: 60px;
        object-fit: cover;
    }

    .print-preview .image-item .image-label {
        font-size: 10px;
        color: #666;
        padding: 2px;
        word-break: break-all;
    }

    /* Print Preview Styles */
    .print-preview {
        transform-origin: top center;
        /* Scale is set dynamically by JS; fallback for no-JS */
        transform: scale(var(--preview-scale, 0.45));
        width: 794px; /* A4 width */
        background: white;
        border: 1px solid #e2e8f0;
        box-shadow: 0 2px 12px rgba(0,0,0,0.1);
        position: relative;
        overflow: visible;
    }

    .print-preview .page {
        width: 794px; /* A4 width: 210mm at 96 DPI (210 * 96 / 25.4) */
        height: 1055px; /* A4 height: 297mm at 96 DPI (297 * 96 / 25.4) */
        margin: 0;
        background: #fff;
        position: relative;
        overflow: hidden;
        border: none;
        box-shadow: none;
    }

    .print-preview header {
        display: flex;
        align-items: center;
        padding: 22px 28px 12px 28px;
        border-bottom: 8px solid #1d6fa5;
        gap: 18px;
    }

    .print-preview .logo {
        width: 82px;
        height: 82px;
        border-radius: 50%;
        background: linear-gradient(180deg, #6fb5db, #1d6fa5);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-weight: 700;
        font-size: 34px;
        flex-shrink: 0;
        overflow: hidden;
    }

    .print-preview .prescription-logo {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .print-preview .doc-info {
        flex: 1;
    }

    .print-preview .doc-info h1 {
        margin: 0;
        font-size: 20px;
        letter-spacing: 0.2px;
        color: #1d6fa5;
        
    }

    .print-preview .doc-info p {
        margin: 4px 0;
        color: #6b6b6b;
        font-size: 13px;
    }


    .print-preview .doc-info-urdu {
        flex: 1;
    }

    .print-preview .doc-info-urdu h1 {
        margin: 0;
        font-size: 20px;
        letter-spacing: 0.2px;
        color: #1d6fa5;
        direction: rtl;
        text-align: right;
    }

    .print-preview .doc-info-urdu p {
        margin: 4px 0;
        color: #6b6b6b;
        font-size: 13px;
    }

    .print-preview .patient-line {
        display: flex;
        justify-content: space-between;
        padding: 12px 28px;
        border-bottom: 1px solid #eee;
        font-size: 14px;
        color: #6b6b6b;
    }

    .print-preview .patient-line .field {
        flex: none;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .print-preview .content-area {
    display: flex;
    padding: 26px 40px;
    height: 760px;  /* Increased to use available space */
    position: relative;
    gap: 10px;
}

    .print-preview .left-col {
        width: 24%;
        border-right: 1px solid #999;
        padding-right: 10px;
    }

    .print-preview .right-col {
        flex: 1;
        padding-left: 10px;
    }

    .print-preview textarea {
        width: 100%;
        height: 100%;
        border: none;
        outline: none;
        resize: none;
        font-size: 16px;
        color: #111;
        line-height: 1.6;
        background: transparent;
    }

    .print-preview footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 40px;  /* Slightly increased */
    border-top: 2px solid #1d6fa5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 28px;  /* Match header padding */
    background: #fff;
}

    .print-preview .contact {
        font-size: 13px;
        color: #6b6b6b;
    }


    /* Print styles */
    @media print {
        .split-container {
            display: none;
        }
        
        .print-preview {
            transform: none !important;
            width: 100% !important;
            height: auto !important;
            margin: 0 !important;
            border: none;
            box-shadow: none;
        }
        
        .print-preview .page {
            width: 100%;
            height: auto;
            margin: 0;
        }
    }

    .preview-panel .urdu, .print-preview [dir="rtl"], 
    .preview-panel-v2 .urdu.print-preview [dir="rtl"], 
    .preview-panel-v3 .urdu.print-preview [dir="rtl"],
    .urdu, .urdu-text{
        font-family: 'Noto Nastaliq Urdu', serif !important;
        direction: rtl;
        text-align: right;
    }

/* ============================================================
   IPD STANDALONE FORM PRINT STYLES (A4)
   ============================================================ */
@media print {
    /* Hide all chrome */
    .navbar, nav.navbar, footer, footer.bg-dark { display: none \!important; }
    .alert, .flash-notification, #ipd-notify { display: none \!important; }
    .pf-banner, .pf-tabs .nav-tabs { display: none \!important; }
    .pf-tabs .tab-pane:not(.show.active) { display: none \!important; }
    .ipd-readonly-banner { display: none \!important; }
    .main-content { padding: 0 \!important; }
    .container-fluid > .row > .col-12 > .main-content { padding: 0 \!important; }

    /* A4 page */
    @page { size: A4 portrait; margin: 12mm 14mm; }
    html, body { background: #fff \!important; font-size: 10.5pt; }

    /* Text inputs: remove box, keep underline */
    input[type="text"], input[type="email"], input[type="tel"], input[type="number"] {
        border: none \!important;
        border-bottom: 1px solid #333 \!important;
        background: transparent \!important;
        box-shadow: none \!important;
        padding: 0 2px \!important;
        font-size: inherit \!important;
    }
    input[type="date"], input[type="time"] {
        border: none \!important;
        border-bottom: 1px solid #333 \!important;
        background: transparent \!important;
        box-shadow: none \!important;
        font-size: inherit \!important;
    }
    textarea {
        border: 1px solid #bbb \!important;
        background: transparent \!important;
        box-shadow: none \!important;
        resize: none \!important;
        overflow: hidden \!important;
        font-size: inherit \!important;
    }
    select {
        border: none \!important;
        border-bottom: 1px solid #333 \!important;
        background: transparent \!important;
        box-shadow: none \!important;
        -webkit-appearance: none;
        appearance: none;
    }
    input[type="checkbox"], input[type="radio"] {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color-adjust: exact;
    }

    /* Hide all action buttons */
    button[type="submit"], button[onclick*="print"], .ipd-save-bar,
    .mt-3 > button, a.btn.btn-outline-secondary.back-link,
    a.btn.btn-outline-secondary.mb-3, a.back-link { display: none \!important; }

    /* Card clean */
    .card { box-shadow: none \!important; border: 1px solid #ddd \!important; }

    /* Table sizes */
    .table { font-size: 9pt; }
    .table th, .table td { padding: 3px 5px \!important; }

    /* Section page-break hints */
    .form-section { break-inside: avoid; page-break-inside: avoid; }
    .soap-block   { break-inside: avoid; page-break-inside: avoid; }
    .note-block   { break-inside: avoid; page-break-inside: avoid; }
}

/* IPD form signature row — always single line */
.ipd-form-signature {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 1rem;
    align-items: flex-end;
    margin-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 1rem;
}
.ipd-form-signature > div {
    flex: 1;
    min-width: 0;
}