/* Medcio app layer: shell, navigation, motion, touch, tutorial and mobile.
   Loaded after the page stylesheet on every page, so it wins on equal specificity. */

:root {
    --ease-out: cubic-bezier(.22, 1, .36, 1);
    --ease-sheet: cubic-bezier(.32, .72, 0, 1);
    --tabbar-height: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --focus-ring: 0 0 0 3px color-mix(in srgb, #0a2bff 28%, transparent);
}

/* ---------- Base: touch and typography ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.no-scroll { overflow: hidden; }
body { -webkit-tap-highlight-color: transparent; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
a, button, input, select, textarea, label, summary { touch-action: manipulation; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
html[dir="ltr"] body, html[dir="ltr"] button, html[dir="ltr"] input, html[dir="ltr"] select, html[dir="ltr"] textarea {
    font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
}
h1, h2, h3 { font-family: "IBM Plex Sans Arabic", Roboto, "Segoe UI", system-ui, sans-serif; font-weight: 700; }
.topline h1 { font-size: clamp(24px, 2.6vw, 30px); line-height: 1.2; letter-spacing: -.01em; }
.page-kicker { letter-spacing: .06em; }

/* ---------- Page transitions (native, no JavaScript) ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .16s; animation-timing-function: var(--ease-out); }
.side-rail { view-transition-name: side-rail; }
.mobile-app-header { view-transition-name: app-header; }
.mobile-tabbar { view-transition-name: tab-bar; }
::view-transition-group(side-rail), ::view-transition-group(app-header), ::view-transition-group(tab-bar) { animation: none; }
.main { animation: page-in .22s var(--ease-out) both; }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Press feedback (replaces the old Tailwind runtime) ---------- */
.button, .rs-chip span, .rs-template > span, .case-completion-action, .actions-trigger, .mobile-tab, .rail-nav a, .inline-action, .specialty-option-body, .registration-submit {
    transition: transform .12s var(--ease-out), background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.button:active, .case-completion-action:active, .actions-trigger:active, .inline-action:active, .registration-submit:active { transform: scale(.97); }
.rs-chip:active span, .rs-template:active > span, .specialty-option:active .specialty-option-body { transform: scale(.98); }
@media (hover: none) {
    .rail-nav a:not(.is-active):hover { transform: none; }
}

/* Busy state for submitted forms */
.button.is-busy, .registration-submit.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.button.is-busy::after, .registration-submit.is-busy::after {
    position: absolute; inset: 0; width: 18px; height: 18px; margin: auto; border: 2px solid currentColor; border-radius: 50%;
    border-color: rgba(255, 255, 255, .9) rgba(255, 255, 255, .9) transparent; content: ""; animation: spin .7s linear infinite;
}
.button-secondary.is-busy::after, .button-quiet.is-busy::after { border-color: #0a2bff #0a2bff transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Side navigation (server-rendered) ---------- */
.rail-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 4px 14px; }
.rail-top .rail-brand { padding: 0 !important; }
.rail-top .rail-close { display: none; }
.rail-icon-wrap { display: inline-grid; flex: 0 0 18px; place-items: center; width: 18px; height: 18px; }
.rail-svg { width: 18px; height: 18px; }
.rail-nav { display: flex !important; flex-direction: column; gap: 14px; }
.rail-group { display: flex; flex-direction: column; gap: 2px; }
.rail-nav a { display: flex; align-items: center; gap: 11px; min-height: 40px; }
.rail-language { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin: 14px 0 12px; padding: 3px; border: 1px solid rgba(255, 255, 255, .12); border-radius: 10px; background: rgba(255, 255, 255, .06); }
.rail-language button { min-height: 32px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent; color: rgba(255, 255, 255, .78); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.rail-language button.is-active { background: #fff; color: var(--c-brand-deep); }
.rail-language button:not(.is-active):hover { color: #fff; }
.rail-user { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; padding: 8px; border-radius: 10px; color: inherit; text-decoration: none; }
.rail-user:hover { background: rgba(255, 255, 255, .07); }
.rail-user-copy { display: flex; flex-direction: column; min-width: 0; }
.rail-user-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout { display: inline-flex; align-items: center; gap: 8px; }
.signout-icon { width: 16px; height: 16px; }

/* ---------- Phones and tablets: app bar, drawer, tab bar ---------- */
.mobile-tabbar, .language-hint { display: none; }
@media (max-width: 1023px) {
    .mobile-app-header { padding-top: calc(10px + var(--safe-top)); min-height: calc(56px + var(--safe-top)); box-shadow: 0 1px 0 rgba(255, 255, 255, .06); }
    .mobile-app-brand img { width: 112px; height: 26px; }
    .mobile-app-actions { display: flex; gap: 8px; }
    .mobile-icon-button { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(255, 255, 255, .18); border-radius: 12px; background: rgba(255, 255, 255, .08); color: #fff; }
    .mobile-icon-button svg { width: 20px; height: 20px; }
    .mobile-icon-button:active { transform: scale(.94); }
    .rail-top .rail-close { position: static; display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; }
    .rail-top .rail-close svg { width: 18px; height: 18px; }
    .side-rail { width: min(86vw, 300px) !important; padding-top: calc(16px + var(--safe-top)); padding-bottom: calc(16px + var(--safe-bottom)); transition: transform .32s var(--ease-sheet), visibility .32s; }
    .mobile-sidebar-backdrop { transition: opacity .28s ease; backdrop-filter: blur(2px); }

    .mobile-tabbar {
        position: fixed; right: 0; bottom: 0; left: 0; z-index: 45; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
        height: calc(var(--tabbar-height) + var(--safe-bottom)); padding: 6px 6px var(--safe-bottom);
        border-top: 1px solid var(--c-border); background: rgba(255, 255, 255, .94); backdrop-filter: saturate(1.6) blur(14px);
        box-shadow: 0 -6px 24px rgba(15, 23, 42, .06);
    }
    .mobile-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; border-radius: 12px; color: var(--c-muted); font-size: 11px; font-weight: 600; text-decoration: none; }
    .mobile-tab-icon { display: inline-grid; place-items: center; width: 44px; height: 28px; border-radius: 999px; transition: background-color .15s ease; }
    .mobile-tab-icon svg { width: 21px; height: 21px; }
    .mobile-tab.is-active { color: var(--c-brand); }
    .mobile-tab.is-active .mobile-tab-icon { background: var(--c-teal-soft); }
    .mobile-tab:active .mobile-tab-icon { transform: scale(.92); }
    .mobile-tab--add .mobile-tab-icon { width: 46px; height: 46px; margin-top: -18px; border-radius: 16px; background: var(--c-brand); color: #fff; box-shadow: 0 8px 20px rgba(10, 43, 255, .32); }
    .mobile-tab--add .mobile-tab-label { margin-top: -2px; }
    .mobile-tab-label { overflow: hidden; max-width: 100%; text-overflow: ellipsis; white-space: nowrap; }

    .main { padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 28px) !important; }
    .topline > div:first-child .lede { font-size: 14px; }

    /* Inputs at 16px stop iOS from zooming into fields. */
    input, select, textarea { font-size: 16px !important; }
    input, select { min-height: 44px; }

    /* Dialogs become bottom sheets. */
    .patient-action-dialog { width: 100vw !important; max-width: 100vw !important; height: auto; max-height: 92dvh; margin: auto 0 0 !important; border-radius: 18px 18px 0 0 !important; }
    .patient-action-dialog[open] { animation: sheet-up .3s var(--ease-sheet); }
    .patient-action-dialog-surface { max-height: 92dvh; padding-bottom: var(--safe-bottom); }

    .language-hint {
        position: fixed; right: 12px; bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 10px); left: 12px; z-index: 44;
        grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 12px 12px 12px 14px;
        border: 1px solid var(--c-border); border-radius: 14px; background: #fff; box-shadow: 0 12px 32px rgba(15, 23, 42, .14);
        animation: sheet-up .35s var(--ease-sheet);
    }
    .language-hint:not([hidden]) { display: grid; }
    .language-hint p { grid-column: 2 / 4; margin: 0; font-size: 13px; line-height: 1.55; }
    .language-hint .button { grid-column: 2; justify-self: start; min-height: 36px; padding: 0 14px; }
    .language-hint-close { position: absolute; top: 6px; left: 6px; }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Desktop language hint: slim banner at the top of the page. */
@media (min-width: 1024px) {
    .language-hint:not([hidden]) { position: fixed; bottom: 20px; left: 24px; z-index: 44; display: flex; align-items: center; gap: 12px; max-width: 520px; padding: 12px 14px; border: 1px solid var(--c-border); border-radius: 14px; background: #fff; box-shadow: 0 12px 32px rgba(15, 23, 42, .14); }
    .language-hint p { margin: 0; font-size: 13px; line-height: 1.55; }
    .language-hint .button { flex: 0 0 auto; min-height: 34px; padding: 0 14px; }
}
.language-hint-icon { width: 22px; height: 22px; color: var(--c-brand); }
.language-hint-close { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: var(--c-muted); cursor: pointer; }
.language-hint-close svg { width: 16px; height: 16px; }

/* ---------- First-use tutorial ---------- */
.tour { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; background: rgba(11, 26, 114, .38); backdrop-filter: blur(3px); animation: fade-in .2s ease both; }
.tour.is-leaving { animation: fade-out .2s ease both; }
.tour-card { position: relative; width: min(100%, 460px); padding: 30px 28px 22px; border-radius: 20px; background: #fff; box-shadow: 0 30px 80px rgba(11, 26, 114, .3); animation: pop-in .32s var(--ease-out) both; }
.tour-skip { position: absolute; top: 14px; inset-inline-end: 14px; padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--c-muted); font: inherit; font-size: 13px; cursor: pointer; }
.tour-skip:hover { background: var(--c-bg); color: var(--c-ink-strong); }
.tour-step { min-height: 190px; animation: step-in .25s var(--ease-out) both; }
.tour-icon { display: inline-grid; place-items: center; width: 54px; height: 54px; margin-bottom: 16px; border-radius: 16px; background: var(--c-teal-soft); color: var(--c-brand); }
.tour-icon svg { width: 26px; height: 26px; }
.tour-step h2 { margin: 0 0 10px; color: var(--c-ink-strong); font-size: 21px; line-height: 1.3; }
.tour-step p { margin: 0; color: var(--c-ink); font-size: 15px; line-height: 1.65; }
.tour-dots { display: flex; gap: 6px; margin: 18px 0; }
.tour-dots span { width: 7px; height: 7px; border-radius: 999px; background: var(--c-border); transition: width .2s var(--ease-out), background-color .2s ease; }
.tour-dots span.is-active { width: 22px; background: var(--c-brand); }
.tour-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tour-actions [data-tour-next] { margin-inline-start: auto; }
.tour-guide-link { color: var(--c-brand); font-size: 13px; font-weight: 600; text-decoration: none; }
.tour-guide-link:hover { text-decoration: underline; }
@media (max-width: 640px) {
    .tour { align-items: end; padding: 0; }
    .tour-card { width: 100%; padding: 28px 22px calc(18px + var(--safe-bottom)); border-radius: 22px 22px 0 0; animation: sheet-up .35s var(--ease-sheet) both; }
    .tour-actions .button { flex: 1; }
    .tour-guide-link { order: 3; width: 100%; text-align: center; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes step-in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }
html[dir="rtl"] .tour-step { animation-name: step-in-rtl; }
@keyframes step-in-rtl { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Content pages: guide and privacy ---------- */
.doc-page { max-width: 860px; }
.doc-hero { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 26px; }
.doc-hero-icon { display: inline-grid; flex: 0 0 52px; place-items: center; width: 52px; height: 52px; border-radius: 15px; background: var(--c-teal-soft); color: var(--c-brand); }
.doc-hero-icon svg { width: 26px; height: 26px; }
.doc-toc { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.doc-toc a { padding: 7px 12px; border: 1px solid var(--c-border); border-radius: 999px; background: #fff; color: var(--c-ink); font-size: 13px; text-decoration: none; }
.doc-toc a:hover { border-color: var(--c-brand); color: var(--c-brand); }
.doc-section { margin-bottom: 14px; padding: 22px 24px; border: 1px solid var(--c-border); border-radius: 14px; background: #fff; scroll-margin-top: 80px; }
.doc-section h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; color: var(--c-ink-strong); font-size: 18px; }
.doc-section h2 svg { width: 20px; height: 20px; color: var(--c-brand); }
.doc-section p, .doc-section li { color: var(--c-ink); font-size: 15px; line-height: 1.7; }
.doc-section p { margin: 0 0 10px; }
.doc-section ul, .doc-section ol { margin: 0 0 10px; padding-inline-start: 22px; }
.doc-section li { margin-bottom: 4px; }
.doc-steps { display: grid; gap: 10px; margin: 6px 0 0; padding: 0; list-style: none; counter-reset: step; }
.doc-steps li { position: relative; padding: 12px 14px 12px 48px; border-radius: 10px; background: var(--c-bg); counter-increment: step; }
html[dir="rtl"] .doc-steps li { padding: 12px 48px 12px 14px; }
.doc-steps li::before { position: absolute; top: 12px; inset-inline-start: 14px; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--c-brand); color: #fff; content: counter(step); font-size: 12px; font-weight: 700; }
.doc-callout { display: flex; gap: 12px; padding: 14px 16px; border-radius: 12px; background: var(--c-teal-soft); color: var(--c-ink-strong); font-size: 14px; line-height: 1.6; }
.doc-callout svg { flex: 0 0 20px; width: 20px; height: 20px; color: var(--c-brand); }
.doc-meta { color: var(--c-muted); font-size: 13px; }

/* Standalone public page (privacy) */
.public-page { min-height: 100vh; background: var(--c-bg, #f7f9ff); }
.public-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(14px + var(--safe-top)) clamp(16px, 4vw, 40px) 14px; border-bottom: 1px solid var(--c-border); background: rgba(255, 255, 255, .92); backdrop-filter: blur(12px); }
.public-header img { width: 120px; height: auto; }
.public-header nav { display: flex; gap: 8px; align-items: center; }
.public-main { width: min(100%, 900px); margin: 0 auto; padding: 32px clamp(16px, 4vw, 40px) 60px; }
.consent-panel { position: sticky; bottom: 0; z-index: 5; margin-top: 18px; padding: 18px 20px calc(18px + var(--safe-bottom)); border: 1px solid var(--c-brand); border-radius: 16px; background: #fff; box-shadow: 0 -8px 30px rgba(15, 23, 42, .1); }
.consent-panel label { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; color: var(--c-ink-strong); font-size: 14px; line-height: 1.55; }
.consent-panel input[type="checkbox"] { flex: 0 0 18px; width: 18px; height: 18px; min-height: 0; margin-top: 2px; accent-color: var(--c-brand); }
.consent-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Registration consent */
.consent-check { display: flex !important; flex-direction: row !important; gap: 10px; align-items: flex-start; margin: 4px 0 16px; font-size: 13.5px; line-height: 1.55; }
.consent-check input { flex: 0 0 18px; width: 18px !important; height: 18px; min-height: 0 !important; margin: 2px 0 0 !important; padding: 0 !important; accent-color: #1733ff; }
.consent-check a { color: #1733ff; font-weight: 600; }

/* ---------- Auth pages on phones: the form comes first ---------- */
@media (max-width: 760px) {
    .registration-visual { display: none !important; }
    .registration-form-side { padding-top: calc(22px + var(--safe-top)) !important; }
    .form-topbar { margin-bottom: 28px !important; }
    .form-intro h1 { font-size: 32px !important; }
}
@media (min-width: 761px) and (max-width: 1100px) {
    .registration-form-side { order: -1; }
    .registration-visual { min-height: 300px !important; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* Invitation page logo (locale.js would otherwise paint a background logo too). */
.invitation-brand--logo { background: none !important; }
.invitation-brand--logo img { display: block; width: 132px; height: auto; }
.form-trust { flex-wrap: wrap; }
.form-trust-link { color: #1733ff; font-size: 13px; font-weight: 600; text-decoration: none; }
.form-trust-link:hover { text-decoration: underline; }

/* Component display rules must never defeat the hidden attribute. */
[hidden] { display: none !important; }
.rail-bottom .signout { justify-content: flex-start; gap: 8px; width: auto; }
/* Platform-owner announcement, injected into the clinical shell. */
.platform-announcement{position:fixed;z-index:45;inset-block-start:12px;inset-inline-start:calc(240px + 24px);inset-inline-end:24px;padding:10px 16px;border:1px solid #b9d2f5;border-radius:8px;background:#edf5ff;color:#183b68;text-align:center;font-size:13px;box-shadow:0 3px 12px #10294d12}.platform-announcement--warning{border-color:#e5c16b;background:#fff7e3;color:#684b0d}@media(max-width:760px){.platform-announcement{inset-inline:12px;inset-block-start:62px}}
