/* ============================================================
   SANABIL MEDICAL ESTABLISHMENT — Base Layer
   Global tokens, reset, pill navbar, glass, ambient effects.
   ============================================================ */

:root {
    /* --- SANABIL BRAND COLORS --- */
    --navy: #0B2A4A;
    --navy-deep: #071E36;
    --navy-mid: #174A73;
    --teal: #0EA5A0;
    --teal-soft: #0B8580;
    --teal-bright: #13B5B0;
    --teal-glow: rgba(14, 165, 160, 0.35);
    --accent: #0EA5A0;
    --accent-soft: #0B8580;
    --accent-glow: rgba(14, 165, 160, 0.28);

    /* --- CORE PALETTE (Light) --- */
    --bg-core: #F6F9FA;
    --bg-soft: #EEF4F6;
    --bg-card: rgba(255, 255, 255, 0.92);
    --text-main: #102A41;
    --text-muted: #5B6B7A;
    --text-soft: #8FA1B1;

    /* --- GLASS --- */
    --glass-border: rgba(11, 42, 74, 0.22);
    --glass-surface: rgba(255, 255, 255, 0.86);
    --surface-strong: rgba(255, 255, 255, 0.95);
    --surface-muted: rgba(255, 255, 255, 0.84);
    --shadow-elevated: 0 18px 40px rgba(11, 42, 74, 0.1);

    /* --- FONTS --- */
    --font-en: 'Inter', sans-serif;
    --font-ar: 'Tajawal', sans-serif;
    --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
}

html {
    color-scheme: light;
    font-size: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: clamp(5.25rem, 8vw, 6.75rem);
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* --- Global reset & typography --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
}

@supports (overflow: clip) {
    html, body { overflow-x: clip; }
}

body {
    background-color: var(--bg-core);
    color: var(--text-main);
    font-family: var(--font-ar), var(--font-en), sans-serif;
    line-height: 1.72;
    overflow-x: hidden;
    position: relative;
    isolation: isolate;
    text-wrap: pretty;
    overflow-wrap: anywhere;
}

img, video, canvas, svg, iframe {
    max-width: 100%;
}

img, video {
    transition: opacity 0.4s ease-in-out, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

body.menu-open { overflow: hidden; }

/* Force RTL for Arabic */
html[dir="rtl"] { direction: rtl; text-align: right; }

html[dir="rtl"] body, html[dir="rtl"] h1, html[dir="rtl"] h2,
html[dir="rtl"] h3, html[dir="rtl"] h4, html[dir="rtl"] p,
html[dir="rtl"] span, html[dir="rtl"] a, html[dir="rtl"] button {
    font-family: var(--font-ar) !important;
}

h1, h2, h3, h4 {
    font-family: var(--font-en), var(--font-ar), sans-serif;
    letter-spacing: -0.01em;
    line-height: 1.15;
    text-wrap: balance;
}

#lang-btn,
[data-lang-toggle] {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

/* --- NAVBAR (fixed) --- */
header#navbar {
    position: fixed;
    top: 0; left: 0; width: 100%; z-index: 1000;
    padding: 1.5rem;
    transition: all 0.4s ease;
    background: transparent;
}

header#navbar.scrolled {
    padding-top: 0.5rem; padding-bottom: 0.5rem;
}

header#navbar > nav.pill-nav-shell {
    --nav-h: 46px;
    --base: rgba(246, 249, 250, 0.86);
    --base-strong: rgba(255, 255, 255, 0.94);
    --pill-bg: rgba(255, 255, 255, 0.74);
    --pill-text: #16324F;
    --hover-text: #0B2A4A;
    --accent: var(--teal);
    --accent-soft: rgba(14, 165, 160, 0.22);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: min(100%, 82rem);
    padding: 0;
    direction: rtl;
    filter: drop-shadow(0 18px 42px rgba(7, 30, 54, 0.1));
}

header#navbar .pill-logo,
header#navbar .pill-icon-control,
header#navbar .pill-menu-button {
    width: var(--nav-h);
    height: var(--nav-h);
    border-radius: 9999px;
    background: linear-gradient(145deg, var(--base-strong), rgba(231, 245, 244, 0.9));
    border: 1px solid rgba(11, 42, 74, 0.16);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    box-shadow: 0 12px 30px rgba(7, 30, 54, 0.12);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
}

header#navbar .pill-logo {
    padding: 0.34rem;
    overflow: hidden;
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease;
}

header#navbar .pill-logo:hover {
    transform: rotate(8deg) scale(1.035);
    box-shadow: 0 16px 36px rgba(11, 42, 74, 0.18);
}

header#navbar .pill-logo img,
header#navbar .pill-logo svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

header#navbar .pill-nav-items {
    align-items: center;
    height: var(--nav-h);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(233, 246, 245, 0.72));
    border: 1px solid rgba(11, 42, 74, 0.16);
    border-radius: 9999px;
    box-shadow: 0 12px 32px rgba(7, 30, 54, 0.1);
    backdrop-filter: blur(18px) saturate(165%);
    -webkit-backdrop-filter: blur(18px) saturate(165%);
}

header#navbar .pill-list {
    list-style: none;
    display: flex;
    align-items: stretch;
    gap: 3px;
    height: 100%;
    margin: 0;
    padding: 3px;
}

header#navbar .pill-list > li {
    display: flex;
    height: 100%;
}

header#navbar .pill,
header#navbar .pill-list > li > a:not(.pill) {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 4.25rem;
    height: 100%;
    padding: 0 1.08rem;
    overflow: hidden;
    border-radius: 9999px;
    background: var(--pill-bg);
    color: var(--pill-text) !important;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
    letter-spacing: 0;
    transition: color 0.32s ease, background 0.32s ease, transform 0.32s ease;
}

header#navbar .pill .hover-circle,
header#navbar .pill-list > li > a:not(.pill)::before {
    position: absolute;
    left: 50%;
    bottom: -190%;
    width: 150%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 18%, #17BCB7 0%, #0EA5A0 55%, #0B8580 100%);
    z-index: 1;
    transform: translateX(-50%) scale(0);
    transform-origin: 50% 100%;
    transition: transform 0.52s cubic-bezier(0.22, 1, 0.36, 1), bottom 0.52s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
}

header#navbar .pill-list > li > a:not(.pill)::before { content: ""; }

header#navbar .pill:hover .hover-circle,
header#navbar .pill:focus-visible .hover-circle,
header#navbar .pill-list > li > a:not(.pill):hover::before,
header#navbar .pill-list > li > a:not(.pill):focus-visible::before {
    bottom: -72%;
    transform: translateX(-50%) scale(1.25);
}

header#navbar .label-stack,
header#navbar .pill-list > li > a:not(.pill) { position: relative; z-index: 2; }

header#navbar .pill-label,
header#navbar .pill-label-hover {
    display: inline-block;
    line-height: 1;
    transition: transform 0.46s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.32s ease;
}

header#navbar .pill-label-hover {
    position: absolute;
    inset: 0 auto auto 0;
    color: var(--hover-text) !important;
    opacity: 0;
    transform: translateY(1.45rem);
}

header#navbar .pill:hover .pill-label,
header#navbar .pill:focus-visible .pill-label { transform: translateY(-1.45rem); }

header#navbar .pill:hover .pill-label-hover,
header#navbar .pill:focus-visible .pill-label-hover {
    opacity: 1;
    transform: translateY(0);
}

header#navbar .pill.is-active::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -6px;
    width: 12px;
    height: 12px;
    border-radius: 9999px;
    background: var(--accent);
    transform: translateX(-50%);
    z-index: 4;
}

header#navbar .pill-nav-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 0 0 auto;
}

header#navbar .pill-icon-control,
header#navbar .pill-menu-button {
    padding: 0;
    color: #16324F !important;
    font-size: 0.72rem;
    font-weight: 900;
    cursor: pointer;
    transition: background 0.35s ease, color 0.35s ease, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease;
}

header#navbar .pill-icon-control:hover,
header#navbar .pill-menu-button:hover {
    background: linear-gradient(135deg, rgba(14, 165, 160, 0.98), rgba(7, 30, 54, 0.96));
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 16px 34px rgba(11, 42, 74, 0.2);
}

header#navbar .pill-cta {
    align-items: center;
    justify-content: center;
    min-height: var(--nav-h);
    padding: 0 1.15rem;
    border-radius: 9999px;
    background: var(--accent);
    color: #ffffff !important;
    font-size: 0.76rem;
    font-weight: 900;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: 0 14px 32px rgba(14, 165, 160, 0.24);
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), filter 0.35s ease, box-shadow 0.35s ease;
}

header#navbar .pill-cta:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
    box-shadow: 0 18px 40px rgba(11, 42, 74, 0.24);
}

header#navbar .hamburger-line {
    width: 16px;
    height: 2px;
    background: currentColor;
    border-radius: 9999px;
    display: block;
}

header#navbar .pill-menu-button {
    display: none;
    flex-direction: column;
    gap: 4px;
}

/* --- Glass panel --- */
.glass-panel {
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(11, 42, 74, 0.18);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* --- Ambient glow --- */
.ambient-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    background: radial-gradient(circle, rgba(14, 165, 160, 0.12) 0%, rgba(14, 165, 160, 0) 70%);
    animation: sanabil-drift 26s ease-in-out infinite alternate;
    pointer-events: none;
    contain: paint;
}

.glow-1 { width: 600px; height: 600px; top: -10%; left: -10%; animation-duration: 28s; }
.glow-2 { width: 400px; height: 400px; bottom: 20%; right: -5%; background: radial-gradient(circle, rgba(23, 74, 115, 0.12) 0%, rgba(23, 74, 115, 0) 70%); animation-duration: 32s; animation-delay: -10s; }
.glow-3 { width: 500px; height: 500px; top: 40%; left: 40%; background: radial-gradient(circle, rgba(14, 165, 160, 0.08) 0%, rgba(14, 165, 160, 0) 70%); animation-duration: 36s; animation-delay: -5s; }

@keyframes sanabil-drift {
    0% { transform: translate(0, 0) scale(1); opacity: 0.8; }
    33% { transform: translate(5%, 10%) scale(1.1); opacity: 1; }
    66% { transform: translate(-5%, 5%) scale(0.9); opacity: 0.7; }
    100% { transform: translate(10%, -10%) scale(1.05); opacity: 0.9; }
}

/* --- Mobile menu --- */
@media (max-width: 768px) {
    header#navbar { padding: 0.85rem 0.85rem 0; }

    header#navbar > nav.pill-nav-shell {
        --nav-h: 44px;
        width: 100%;
    }

    header#navbar .pill-menu-button { display: inline-flex; }

    #mobile-menu {
        inset: auto 0.85rem auto 0.85rem;
        top: calc(env(safe-area-inset-top, 0px) + 4.25rem);
        width: auto;
        height: auto;
        max-height: calc(100dvh - 5.25rem);
        justify-content: flex-start;
        gap: 0.3rem;
        padding: 0.3rem;
        overflow-y: auto;
        background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(231, 245, 244, 0.9));
        border-radius: 1.7rem;
        border: 1px solid rgba(11, 42, 74, 0.16);
        box-shadow: 0 22px 60px rgba(7, 30, 54, 0.18);
        backdrop-filter: blur(20px) saturate(160%);
        -webkit-backdrop-filter: blur(20px) saturate(160%);
        transform: translateY(-0.4rem);
        transition: opacity 0.25s ease, transform 0.25s ease;
    }

    #mobile-menu.active { transform: translateY(0); }

    #mobile-menu button { display: none; }

    #mobile-menu a {
        width: 100%;
        max-width: none;
        min-height: 3.2rem;
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: 0.9rem 1rem;
        border-radius: 9999px;
        background: rgba(255, 255, 255, 0.78);
        border: 0;
        color: #0B2A4A !important;
        font-size: 0.96rem;
        font-weight: 800;
        box-shadow: none;
        transform: translateY(0);
    }

    #mobile-menu a:hover {
        background: #0EA5A0;
        color: #ffffff !important;
    }
}

/* --- Zero-overflow guards --- */
.flex, .grid, [class*="grid"], [class*="flex"], section, div, main, header, footer {
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

@media (max-width: 768px) {
    a, button, input, select, textarea, .btn, [role="button"] {
        min-height: 48px;
        min-width: 44px;
        -webkit-tap-highlight-color: rgba(14, 165, 160, 0.15);
    }

    .px-4, .px-6, .px-8, .p-6, .p-8 {
        padding-left: clamp(0.85rem, 3.5vw, 1.25rem) !important;
        padding-right: clamp(0.85rem, 3.5vw, 1.25rem) !important;
    }

    video, canvas, iframe {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
    }
}

/* --- Focus & interaction polish --- */
:where(button, .btn, .button, a.btn, input[type="submit"], input[type="button"], .pill-icon-control, .pill-menu-button) {
    min-height: 2.875rem;
    border-radius: 999px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

:where(button, .btn, .button, a.btn, input[type="submit"], input[type="button"], .pill-icon-control, .pill-menu-button):hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated);
}

:where(button, .btn, .button, a.btn, input[type="submit"], input[type="button"], .pill-icon-control, .pill-menu-button):active:not(:disabled) {
    transform: translateY(0) scale(0.985);
}

:where(button, .btn, .button, a.btn, input[type="submit"], input[type="button"], .pill-icon-control, .pill-menu-button, input, textarea, select):focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px rgba(14, 165, 160, 0.22);
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .ambient-glow { animation: none !important; }
}

/* --- Lite experience --- */
html.is-lite-experience *,
html.is-lite-experience *::before,
html.is-lite-experience *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
}

html.is-lite-experience .glass-panel,
html.is-lite-experience .pill-nav-items {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}