:root {
    /* Professional Medical Palette */
    --primary: #0F766E;
    /* Teal 700 */
    --primary-hover: #115E59;
    /* Teal 800 */
    --secondary: #0EA5E9;
    /* Sky 500 */
    --accent: #F43F5E;
    /* Rose 500 */

    /* Neutral / Surface */
    --bg-main: #E8EDF2;
    /* Soft Blue-Gray for a more premium, less 'bright' feel */
    --bg-surface: #FFFFFF;
    --border: #E2E8F0;
    /* Slate 200 */

    /* Typography Colors */
    --text-heading: #0F172A;
    /* Slate 900 */
    --text-body: #334155;
    /* Slate 700 */
    --text-muted: #64748B;
    /* Slate 500 */
    --text-on-primary: #FFFFFF;

    /* Spacing & Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows - Subtle */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Animation */
    --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Reset */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection for inputs and specific elements */
input, textarea, select, [contenteditable] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-main);
    font-family: 'Cairo', 'Inter', sans-serif;
    /* Priority to Cairo for Arabic */
    color: var(--text-body);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    direction: rtl;
    /* Ensure RTL default */
    /* iOS Safari fixes */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
    overflow-x: hidden;
    /* Prevent bounce scroll on iOS */
    position: fixed;
    width: 100%;
    height: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-heading);
    margin: 0;
    font-weight: 700;
}

/* Base Screen Container */
.screen {
    width: 100%;
    height: 100dvh;
    /* Fallback for older browsers */
    height: 100vh;
    background-color: var(--bg-main);
    display: none;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    /* iOS Safari smooth scrolling */
    -webkit-overflow-scrolling: touch;
    /* Prevent pull-to-refresh */
    overscroll-behavior: contain;
    /* Hardware acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.screen.active {
    display: flex !important;
    opacity: 1;
    animation: screenSlideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes screenSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Desktop Handling (Mobile Container) */
@media (min-width: 768px) {
    body {
        background: #0f172a;
        /* Dark Slate 900 for premium contrast */
        align-items: center;
        position: relative;
        /* Allow body positioning on desktop */
    }

    .screen {
        width: 100%;
        max-width: 420px;
        /* Slightly narrower for realistic mobile feel */
        height: min(850px, 90vh);
        border-radius: 32px;
        box-shadow:
            0 0 0 8px #1e293b,
            0 20px 25px -5px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        margin: auto;
        position: relative;
        /* Reset position for desktop */
    }
}

/* --- Components --- */

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
    padding: 16px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    /* Touch-friendly improvements */
    -webkit-tap-highlight-color: rgba(15, 118, 110, 0.1);
    touch-action: manipulation;
    min-height: 44px;
    /* iOS minimum touch target */
    min-width: 44px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: scale(0.96);
    filter: brightness(0.9);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 14px;
    border-radius: var(--radius-md);
    font-weight: 600;
    width: 100%;
    cursor: pointer;
    transition: var(--transition);
}

.btn-outline:hover {
    background: rgba(15, 118, 110, 0.05);
}

/* Inputs */
input:not([type="radio"]):not([type="checkbox"]),
select {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 15px;
    color: var(--text-heading);
    background: var(--bg-surface);
    transition: var(--transition);
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

/* Input with Icon Wrapper */
.input-with-icon {
    position: relative;
    width: 100%;
}

.input-with-icon i {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 16px;
    pointer-events: none;
    opacity: 0.7;
}

.input-with-icon input,
.input-with-icon select {
    padding-right: 48px;
    /* Space for the icon on the right (RTL) */
    padding-left: 16px;
}

/* --- App Header & Tabs --- */
.app-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 16px 20px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.03);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

.user-profile-pill {
    background: rgba(15, 118, 110, 0.08);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(15, 118, 110, 0.1);
}

/* Segmented Control Tabs */
.tabs-container {
    display: flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 14px;
    position: relative;
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 8px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    transition: var(--transition-fast);
    position: relative;
    z-index: 1;
    /* Touch-friendly improvements */
    -webkit-tap-highlight-color: rgba(15, 118, 110, 0.1);
    touch-action: manipulation;
    min-height: 44px;
    /* iOS minimum touch target */
    min-width: 44px;
}

.tab-btn span {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}

.tab-btn small {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.7;
}

.tab-btn.active {
    background: var(--bg-surface);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: scale(1.02);
}

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

/* --- Content Area --- */
.content-list {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: min-content;
    gap: 12px;
    background: var(--bg-main);
    min-height: 100%;
}

/* Force nurse cards to take full width in the grid */
.nurse-card {
    grid-column: span 2;
}

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid rgba(226, 232, 240, 0.4);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition-fast);
    cursor: pointer;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    /* Slightly stronger shadow */
    /* Touch-friendly improvements */
    -webkit-tap-highlight-color: rgba(15, 118, 110, 0.1);
    touch-action: manipulation;
    /* Prevent layout shift on touch */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 20px rgba(15, 118, 110, 0.08);
    transform: translateY(-4px);
}

.card:active {
    transform: scale(0.98) translateY(-2px);
    /* Prevent layout shift on iOS */
    -webkit-transform: scale(0.98) translateY(-2px);
}

.card-image {
    height: 100px;
    background: var(--bg-main);
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.card:hover .card-image img {
    transform: scale(1.1);
}

.card-content {
    padding: 12px;
}

.card-title h4 {
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-title p {
    font-size: 11px;
    color: var(--text-muted);
}

.card-price {
    margin-top: 8px;
    font-size: 15px;
    font-weight: 800;
    color: var(--primary);
    display: block;
}

/* Nurse Cards specific */
.nurse-card {
    display: flex !important;
    padding: 18px;
    gap: 18px;
    align-items: flex-start;
    /* Better for variable content */
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(226, 232, 240, 0.6);
}

.nurse-avatar {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    /* Modern squircle */
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.nurse-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nurse-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nurse-name {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.nurse-name h4 {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-heading);
    margin: 0;
    line-height: 1.2;
}

.nurse-specialty {
    color: #059669;
    font-size: 14px;
    font-weight: 700;
    margin: 0;
}

.nurse-region {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.distance-tag {
    font-size: 11px;
    font-weight: 700;
    color: #059669;
    background: #ecfdf5;
    padding: 2px 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- Welcome / Onboarding Screen --- */
#splash-screen {
    justify-content: flex-start;
    align-items: center;
    background: var(--bg-surface);
    padding: 60px 24px 40px;
}

.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    text-align: center;
}

.logo-card {
    background: white;
    width: 180px;
    height: 180px;
    border-radius: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    margin-bottom: 50px;
}

.welcome-logo {
    width: 120px;
    height: auto;
    object-fit: contain;
}

.welcome-title {
    font-size: 32px;
    font-weight: 800;
    color: #059669;
    /* Dynamic Emerald Green */
    margin-bottom: 20px;
}

.welcome-subtitle {
    font-size: 16px;
    color: #64748B;
    line-height: 1.6;
    margin-bottom: 30px;
}

.phone-pill {
    background: #ecfdf5;
    color: #059669;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 18px;
    border: 1px solid #d1fae5;
    margin-bottom: 30px;
}

.disclaimer-box {
    background: #fffbeb;
    border: 1px solid #fef3c7;
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: right;
    margin-bottom: 40px;
}

.disclaimer-box i {
    color: #f59e0b;
    font-size: 20px;
}

.disclaimer-box p {
    font-size: 13px;
    color: #92400e;
    margin: 0;
    line-height: 1.4;
}

.btn-welcome {
    background: #059669;
    color: white;
    width: 100%;
    padding: 18px;
    border-radius: 20px;
    border: none;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    margin-top: auto;
    transition: var(--transition-fast);
    box-shadow: 0 10px 20px rgba(5, 150, 105, 0.2);
}

.btn-welcome:active {
    transform: scale(0.96);
    filter: brightness(0.9);
}

/* --- Login Screen --- */
#login-screen {
    padding: 32px 20px;
    justify-content: center;
}

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

.header h2 {
    font-size: 28px;
    color: var(--primary);
    margin-bottom: 8px;
}

.header-icon {
    width: 80px;
    height: 80px;
    background: rgba(15, 118, 110, 0.1);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 20px;
    font-size: 32px;
}

/* --- Registration Form --- */
.registration-form {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg-main);
    flex: 1;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    margin: 10px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Floating Action Button for Nurses Tab */
.btn-float {
    position: fixed;
    bottom: 30px;
    left: 30px;
    /* Left side for RTL */
    background: #059669;
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: none;
    /* Hidden by default */
    justify-content: center;
    align-items: center;
    font-size: 24px;
    box-shadow: 0 10px 25px rgba(5, 150, 105, 0.4);
    border: none;
    cursor: pointer;
    z-index: 100;
    transition: var(--transition-fast);
    /* Touch-friendly improvements */
    -webkit-tap-highlight-color: rgba(5, 150, 105, 0.2);
    touch-action: manipulation;
    /* iOS Safari fix for fixed positioning */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.btn-float:active {
    transform: scale(0.9);
}

.btn-float.visible {
    display: flex;
    animation: bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    from {
        opacity: 0;
        transform: scale(0.3);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.location-box {
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    padding: 20px;
    border-radius: var(--radius-md);
    text-align: center;
    margin: 8px 0;
}

/* --- Checkout Screen --- */
#checkout-screen {
    background: var(--bg-main);
    display: none;
    flex-direction: column;
    overflow-y: auto;
    /* Ensure vertical scrolling */
    padding-bottom: 40px;
    /* Space for the button */
}

#checkout-screen .header {
    padding: 12px 16px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    min-height: 56px;
}

#checkout-screen .header h3 {
    font-size: 16px;
    margin: 0;
}

.back-btn {
    background: transparent;
    border: none;
    font-size: 16px;
    color: var(--text-body);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.invoice-card {
    background: var(--bg-surface);
    margin: 8px 16px;
    padding: 16px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    text-align: center;
    border: 1px solid rgba(226, 232, 240, 0.8);
    position: relative;
    /* overflow: hidden; Removed to allow scrolling expansion */
}

.invoice-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.receipt-header {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.invoice-card h2 {
    font-size: 15px;
    color: var(--text-body);
    margin-bottom: 4px;
}

.invoice-card h1 {
    font-size: 32px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 8px;
    font-family: 'Inter', sans-serif;
}

.receipt-divider {
    height: 1px;
    background: repeating-linear-gradient(90deg, var(--border), var(--border) 4px, transparent 4px, transparent 8px);
    margin: 12px 0;
}

.payment-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Payment Methods */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-box {
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: var(--transition-fast);
    background: var(--bg-surface);
}

.radio-box:has(input:checked) {
    border-color: var(--primary);
    background: rgba(15, 118, 110, 0.03);
}

.radio-info {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text-body);
}

.radio-info span {
    font-size: 14px;
}

.radio-info i {
    font-size: 18px;
    color: var(--primary);
}

.radio-box input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--primary);
}

/* Bank Details */
.bank-details-container {
    margin-top: 12px;
    background: #f8fafc;
    padding: 12px;
    border-radius: var(--radius-md);
    display: none;
    border: 1px solid var(--border);
}

.bank-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.bank-item:last-child {
    border-bottom: none;
}

.upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #fff;
    border: 1px dashed var(--border);
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-top: 12px;
    transition: var(--transition-fast);
    font-size: 13px;
}

.file-preview {
    margin-top: 10px;
    display: flex;
    justify-content: center;
}

.file-preview img {
    max-width: 100%;
    max-height: 120px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.file-input {
    display: none;
}

.btn-whatsapp {
    margin: 16px;
    background: #25D366;
    color: white;
    padding: 16px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* --- Admin --- */
#admin-dashboard {
    padding: 20px;
}

.admin-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#admin-modal .modal-content {
    background: var(--bg-surface);
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 80%;
    max-width: 320px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* Loading Skeleton */
.loading {
    width: 100%;
    height: 120px;
    background: linear-gradient(90deg, #f1f5f9 25%, #f8fafc 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-lg);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Custom Scrollbar Hiding */
::-webkit-scrollbar {
    width: 0;
    display: none;
}

* {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Specific to iOS Safari */
    .screen {
        /* Prevent momentum scrolling issues */
        -webkit-overflow-scrolling: touch;
        /* Fix viewport height issues */
        height: -webkit-fill-available;
    }
    
    /* Fix input zoom on iOS */
    input[type="text"],
    input[type="tel"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Prevent bounce scroll */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    .screen {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Android specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: .001dpcm) {
    .screen {
        /* Chrome/Android specific */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}