/* Web W3 control kit: the desktop Theme.xaml styles as classes with the same names (Button → .btn, OutlineButton → .btn-outline,
   SmallButton → .btn-small, IconButton → .btn-icon, CardButton → .btn-card, ToolbarButton/ToolbarToggle → .btn-toolbar,
   DangerButton → .btn-danger, TextBox → .input, ComboBox → .select, Card → .card, TabItem → .tabs .tab, TabStripItem → .tab-strip,
   ContextMenu/MenuItem → .menu/.menu-item, CheckBox → .toggle, RadioButton → .radio, DataGrid → .grid, ListBoxItem → .list-item,
   Expander → .expander, ProgressBar → .progress, Heading/SectionTitle/MutedText → .heading/.section-title/.muted).
   Colours only from tokens.css (generated from the desktop palettes); sizes from metric tokens, or the Theme.xaml literal when the
   desktop uses the same number in every skin. The patient site (.pt) keeps its own look. */

:root {
    --motion: 150ms cubic-bezier(.2, 0, 0, 1);
    --font-family: Vazirmatn, Tahoma, sans-serif;
    --overlay-hover: color-mix(in srgb, var(--ink) 7%, transparent);
    --overlay-press: color-mix(in srgb, var(--ink) 14%, transparent);
    --backdrop: color-mix(in srgb, var(--ink) 35%, transparent);
}

/* ---- Base (Window style: font, size, ink on page background) ---- */
body:not(:has(.pt)) {
    margin: 0;
    font-family: var(--font-family);
    font-size: var(--font-body);
    color: var(--ink);
    background: var(--page-background);
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--primary);
    color: var(--on-primary);
}

:focus-visible {
    outline: 2px solid var(--primary-border);
    outline-offset: 2px;
}

/* Thin pill scrollbars that show on hover (Theme.xaml ScrollBar: 4px pill, Muted, Primary while dragging). */
* {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--muted) 55%, transparent) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--muted) 55%, transparent);
    background-clip: content-box;
    border: 3px solid transparent;
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--muted);
}

::-webkit-scrollbar-thumb:active {
    background-color: var(--primary);
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
    background: transparent;
}

/* ---- Text ---- */
.heading {
    margin: 4px 0 12px;
    font-size: var(--font-title);
    font-weight: 700;
}

.section-title {
    margin: 2px 0 16px;
    font-size: var(--font-card-title);
    font-weight: 700;
}

.page-title {
    margin: 0;
    font-size: var(--font-page-title);
    font-weight: var(--weight-page-title);
}

.muted {
    color: var(--muted);
    font-size: var(--font-label);
}

/* ---- Icon (Kit/Icon.razor; desktop ClinicIcon: stroke = Primary unless set) ---- */
.icon {
    display: inline-block;
    flex: none;
    vertical-align: middle;
    color: var(--primary);
    overflow: visible;
}

/* ---- Card ---- */
.card {
    margin: var(--card-margin);
    padding: var(--card-padding);
    border: var(--card-border-thickness-t) solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--card-shadow);
}

/* ---- Buttons ---- */
.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-s);
    min-height: var(--control-height);
    margin: 3px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    background: var(--primary-gradient);
    color: var(--on-primary);
    font: inherit;
    font-size: var(--font-control);
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: border-color var(--motion), opacity var(--motion), background-color var(--motion);
}

/* Hover/press overlay (Theme.xaml "Ov": Ink at 7% / 14%). */
.btn::after {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: var(--ink);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--motion);
}

.btn:hover::after {
    opacity: .07;
}

.btn:active::after {
    opacity: .14;
}

.btn:focus-visible {
    border-color: var(--primary-border);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: .45;
    cursor: default;
    pointer-events: none;
}

.btn .icon {
    color: currentColor;
}

/* WHY (V1-1): the desktop's light buttons keep ClinicIcon's default Primary stroke; only the filled primary button inverts. */
.btn-outline .icon,
.btn-small .icon,
.btn-card .icon {
    color: var(--primary);
}

.btn-outline,
.btn-danger,
.btn-small,
.btn-icon,
.btn-card {
    border-color: var(--line-strong);
    background: var(--surface);
    color: var(--ink);
}

.btn-danger {
    border-color: var(--danger-line);
    color: var(--danger);
}

.btn-small {
    min-height: var(--control-height-small);
    padding: 0 10px;
    border-color: var(--line);
    font-size: var(--font-label);
}

.btn-icon {
    width: var(--control-height);
    height: var(--control-height);
    padding: 0;
}

.btn-icon.btn-small {
    width: var(--control-height-small);
    height: var(--control-height-small);
}

/* Desktop PatientNavAction (PatientNavigation.xaml): 36px square, no frame, muted; hover = primary-soft + primary-ink. */
.btn-nav,
.btn-nav.btn-icon,
.btn-nav.btn-toolbar {
    display: inline-grid;
    place-items: center;
    box-sizing: border-box;
    width: 36px;
    height: 36px;
    margin: 3px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background-color var(--motion), color var(--motion);
}

.btn-nav:hover {
    background: var(--primary-soft);
    color: var(--primary-ink);
}

.btn-nav:active {
    background: var(--hover);
}

.btn-nav:focus-visible {
    border-color: var(--primary-border);
}

.btn-card {
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    margin: var(--card-margin);
    padding: 18px;
    border: var(--card-border-thickness-t) solid var(--line);
    border-radius: var(--radius-card);
    box-shadow: var(--card-shadow);
    font-size: var(--font-body);
    font-weight: 400;
    text-align: start;
    white-space: normal;
}

.btn-card:hover {
    border-color: var(--primary-border);
}

.btn-card:hover::after {
    opacity: .04;
}

.btn-card:active::after {
    opacity: .1;
}

/* ToolbarButton / ToolbarToggle (aria-pressed="true" = checked). */
.btn-toolbar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 1px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    transition: background-color var(--motion), border-color var(--motion);
}

.btn-toolbar:hover {
    background: var(--hover);
}

.btn-toolbar:active {
    background: var(--primary-soft);
}

.btn-toolbar[aria-pressed="true"] {
    border-color: var(--primary-border);
    background: var(--primary-soft);
    color: var(--primary);
}

.btn-toolbar:disabled {
    opacity: .4;
    cursor: default;
}

.btn-toolbar .icon {
    color: currentColor;
}

/* ---- Inputs (TextBox / PasswordBox) ---- */
.input {
    box-sizing: border-box;
    width: 100%;
    min-height: var(--control-height);
    margin: 4px 0 7px;
    padding: 4px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    background: var(--surface-alt);
    color: var(--ink);
    caret-color: var(--ink);
    font: inherit;
    font-size: var(--font-body);
    outline: 0;
    transition: border-color var(--motion);
}

textarea.input {
    padding-block: 8px;
    resize: vertical;
}

.input::placeholder {
    color: var(--placeholder);
    opacity: 1;
}

.input:focus,
.input:focus-within {
    border-color: var(--primary);
}

.input:disabled {
    opacity: .55;
}

.input[readonly] {
    background: var(--page-background);
}

/* ---- Select (ComboBox: quiet outlined control, chevron on the left that turns Primary when open/focused) ---- */
.select {
    box-sizing: border-box;
    min-height: var(--control-height);
    margin: 4px 0 8px;
    padding: 0 12px 0 32px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    /* WHY: two half-filled gradients draw the 8×4 chevron in the token colour (a data-URI icon could not use var()). */
    background:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%, var(--muted) calc(50% + 1.5px), transparent calc(50% + 1.5px)) 13px 50% / 5px 5px no-repeat,
        linear-gradient(-45deg, transparent 50%, var(--muted) 50%, var(--muted) calc(50% + 1.5px), transparent calc(50% + 1.5px)) 17px 50% / 5px 5px no-repeat,
        var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: var(--font-control);
    cursor: pointer;
    appearance: none;
    outline: 0;
    transition: border-color var(--motion);
}

.select:hover {
    border-color: var(--primary-border);
}

.select:focus,
.select[aria-expanded="true"] {
    border-color: var(--primary);
}

.select:disabled {
    opacity: .5;
    cursor: default;
}

.select option {
    background: var(--surface);
    color: var(--ink);
}

/* ---- Chip (Card.Status / StatusTemplate: soft filled) ---- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 4px 11px;
    border-radius: var(--radius-chip);
    background: var(--primary-soft);
    color: var(--primary-ink);
    font-size: var(--font-small);
    font-weight: 600;
    white-space: nowrap;
}

.chip-ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.chip-warn {
    background: var(--warn-soft);
    color: var(--warn);
}

.chip-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.chip-violet {
    background: var(--violet-soft);
    color: var(--violet);
}

.chip-teal {
    background: var(--teal-soft);
    color: var(--teal);
}

.chip-muted {
    background: var(--surface-alt);
    color: var(--muted);
}

button.chip {
    border: 0;
    font-family: inherit;
    cursor: pointer;
}

/* ---- Tabs (TabItem) and tab strip (TabStripItem); the selected one has aria-selected="true" ---- */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 0;
}

.tabs .tab {
    margin: 0 2px;
    padding: 9px 16px;
    border: 0;
    border-radius: var(--radius-chip);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--motion), color var(--motion);
}

.tabs .tab:hover {
    background: var(--hover);
}

.tabs .tab[aria-selected="true"] {
    background: var(--primary-soft);
    color: var(--primary-ink);
}

.tab-strip {
    display: flex;
    flex-wrap: wrap;
}

.tab-strip > * {
    margin: 3px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--surface-alt);
    color: var(--muted);
    font: inherit;
    cursor: pointer;
    transition: background-color var(--motion), border-color var(--motion);
}

.tab-strip > :hover {
    background: var(--hover);
}

.tab-strip > [aria-selected="true"] {
    border-color: var(--primary-border);
    background: var(--primary-soft);
    color: var(--primary-ink);
}

/* ---- Segmented choice (one of a few options, e.g. gender) ---- */
.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--surface-alt);
}

.segmented > * {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: calc(var(--control-height-small) - 2px);
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: calc(var(--radius-control) - 3px);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: var(--font-label);
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--motion), color var(--motion);
}

.segmented > :hover {
    color: var(--ink);
}

.segmented > [aria-pressed="true"],
.segmented > [aria-checked="true"] {
    border-color: var(--primary-border);
    background: var(--primary-soft);
    color: var(--primary-ink);
}

.segmented .icon {
    color: currentColor;
}

/* ---- Toggle switch (CheckBox): <label class="toggle"><input type="checkbox"> text</label> ---- */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 9px 0;
    color: var(--ink);
    cursor: pointer;
}

.toggle input {
    position: relative;
    flex: none;
    width: 40px;
    height: 22px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 11px;
    background: var(--toggle-off);
    appearance: none;
    cursor: pointer;
    transition: background-color var(--motion);
}

/* RTL: the thumb starts at the right (desktop: Left in a RightToLeft window) and moves left when checked. */
.toggle input::before {
    content: "";
    position: absolute;
    top: 3px;
    inset-inline-start: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--surface);
    transition: inset-inline-start var(--motion), background-color var(--motion);
}

.toggle input:checked {
    background: var(--primary);
}

.toggle input:checked::before {
    inset-inline-start: 21px;
    background: var(--on-primary);
}

.toggle input:disabled {
    opacity: .55;
    cursor: default;
}

/* ---- Radio: <label class="radio"><input type="radio"> text</label> ---- */
.radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    cursor: pointer;
}

.radio input {
    display: grid;
    place-content: center;
    flex: none;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    border: 1.5px solid var(--line-strong);
    border-radius: 50%;
    background: var(--surface);
    appearance: none;
    cursor: pointer;
    transition: border-color var(--motion);
}

.radio input::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    transform: scale(0);
    transition: transform var(--motion);
}

.radio input:checked,
.radio:hover input {
    border-color: var(--primary);
}

.radio input:checked::before {
    transform: scale(1);
}

.radio input:disabled {
    opacity: .55;
}

/* ---- Data grid (DataGrid): <table class="grid">; selected row has aria-selected="true" ---- */
.grid {
    width: 100%;
    border-collapse: collapse;
    color: var(--ink);
}

.grid th {
    height: 42px;
    padding: 8px 10px;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: var(--font-label);
    font-weight: 600;
    text-align: start;
    white-space: nowrap;
}

.grid td {
    height: var(--row-height);
    padding: 0 10px;
    border-bottom: 1px solid var(--line);
}

.grid tbody tr {
    transition: background-color var(--motion);
}

.grid tbody tr:hover {
    background: var(--hover);
}

.grid tbody tr[aria-selected="true"] {
    background: var(--primary-soft);
}

/* ---- List item (ListBoxItem) ---- */
.list-item {
    display: block;
    margin: 2px 0;
    padding: 6px;
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--ink);
    cursor: pointer;
    transition: background-color var(--motion), border-color var(--motion);
}

.list-item:hover {
    background: var(--hover);
}

.list-item[aria-selected="true"] {
    border-color: var(--primary-border);
    background: var(--primary-soft);
}

/* ---- Expander: <details class="expander"><summary>…</summary>…</details> ---- */
.expander > summary {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 2px;
    color: var(--ink);
    list-style: none;
    cursor: pointer;
}

.expander > summary::-webkit-details-marker {
    display: none;
}

.expander > summary::before {
    content: "";
    width: 6px;
    height: 6px;
    margin-top: -4px;
    border: solid var(--muted);
    border-width: 0 1.6px 1.6px 0;
    transform: rotate(45deg);
    transition: transform var(--motion), border-color var(--motion);
}

.expander > summary:hover::before {
    border-color: var(--primary);
}

.expander[open] > summary::before {
    margin-top: 4px;
    transform: rotate(-135deg);
}

/* ---- Progress (ProgressBar: 3px, Primary) ---- */
.progress {
    width: 100%;
    height: 3px;
    border: 0;
    border-radius: 3px;
    background: transparent;
    appearance: none;
}

.progress::-webkit-progress-bar {
    background: transparent;
}

.progress::-webkit-progress-value {
    border-radius: 3px;
    background: var(--primary);
}

.progress::-moz-progress-bar {
    border-radius: 3px;
    background: var(--primary);
}

/* ---- Menu (ContextMenu / MenuItem) ---- */
.menu {
    display: flex;
    flex-direction: column;
    min-width: 160px;
    padding: 4px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-popup);
    animation: kit-pop var(--motion);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    min-height: var(--control-height-small);
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: var(--font-label);
    text-align: start;
    cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible,
.menu-item[aria-selected="true"] {
    background: var(--hover);
    outline: 0;
}

.menu-item[aria-checked="true"] {
    background: var(--primary-soft);
    color: var(--primary-ink);
    font-weight: 600;
}

.menu-item:disabled {
    opacity: .5;
    cursor: default;
}

.menu-separator {
    height: 1px;
    margin: 4px 0;
    border: 0;
    background: var(--line);
}

/* ---- Tooltip ---- */
.tooltip {
    padding: 6px 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--font-label);
    box-shadow: var(--shadow-popup);
    pointer-events: none;
}

/* ---- Toast (message bar) ---- */
.toast:not(.pt .toast) {
    position: fixed;
    inset-inline: auto 24px;
    bottom: 20px;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: var(--space-m);
    max-width: min(520px, calc(100vw - 48px));
    padding: 12px 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--font-label);
    box-shadow: var(--shadow-popup);
    animation: kit-rise var(--motion);
}

.toast:not(.pt .toast) button {
    padding: 0 6px;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: var(--font-body);
    cursor: pointer;
}

.toast-ok:not(.pt .toast) {
    border-color: var(--ok);
    background: var(--ok-soft);
}

.toast-danger:not(.pt .toast) {
    border-color: var(--danger-line);
    background: var(--danger-soft);
    color: var(--danger);
}

/* ---- Modal (dialog surface; size is the component's) and its backdrop ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--backdrop);
    animation: kit-fade var(--motion);
}

.modal {
    padding: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-popup);
    animation: kit-pop var(--motion);
}

/* ---- Skeleton (never a blank page) ---- */
.skeleton {
    display: block;
    min-height: 1em;
    border-radius: var(--radius-control);
    background: linear-gradient(90deg, var(--surface-alt) 25%, var(--line) 50%, var(--surface-alt) 75%) 0 0 / 200% 100%;
    color: transparent;
    animation: kit-shimmer 1.2s linear infinite;
}

.skeleton-text {
    height: .9em;
    margin: .35em 0;
    border-radius: 6px;
}

/* ---- Popup card (W5): the frame of the date/time/snippet popups (desktop: Border Surface + LineStrong, radius 16–18) ---- */
.kit-pop-card {
    box-sizing: border-box;
    padding: 12px;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-popup);
    animation: kit-pop var(--motion);
}

@keyframes kit-fade {
    from { opacity: 0; }
}

@keyframes kit-pop {
    from { opacity: 0; transform: translateY(-4px) scale(.98); }
}

@keyframes kit-rise {
    from { opacity: 0; transform: translateY(8px); }
}

@keyframes kit-shimmer {
    to { background-position: -200% 0; }
}

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

/* ---- Failures (Web W18): a page or dialog error, the lost server connection, an unexpected crash ---- */
.page-error {
    display: grid;
    justify-items: center;
    gap: var(--space-m);
    padding: var(--space-xl);
    color: var(--ink);
    text-align: center;
}

#components-reconnect-modal {
    display: none;
}

#components-reconnect-modal:is(.components-reconnect-show, .components-reconnect-failed, .components-reconnect-rejected) {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--backdrop);
}

.rc-box {
    display: grid;
    justify-items: center;
    gap: var(--space-m);
    width: min(420px, 100%);
    padding: var(--space-xl);
    text-align: center;
}

.rc-box .rc-state {
    display: none;
    margin: 0;
}

.components-reconnect-show .rc-box .rc-trying,
.components-reconnect-failed .rc-box .rc-failed,
.components-reconnect-rejected .rc-box .rc-rejected {
    display: block;
}

#blazor-error-ui {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 1001;
    display: none;
    justify-content: center;
    align-items: center;
    gap: var(--space-l);
    padding: var(--space-m) var(--space-l);
    border-top: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--danger);
    box-shadow: var(--shadow-popup);
}

#blazor-error-ui .reload {
    color: var(--primary-ink);
}
