/* ui-polish.css — shared by every page. Load it AFTER the page's own styles.
   1. Concentric corners: where one rounded rectangle sits inside another,
        inner radius = outer radius - the gap between them
      so both curves share the same centre. The pages that are apps (admin, clinic, patient, staff set-up) mark <body class="app-page">.
   2. Touch, motion and scrolling behaviour in the style of iOS apps. */

:where(:root) {
  --control-radius: 12px;                 /* buttons, inputs and tinted boxes (the patient / clinic portals use 14px) */
  --menu-radius: 1.125rem;
  --menu-padding: .375rem;
  --drawer-radius: 1.75rem;               /* admin menu drawer on phones */
  --top-bar-height: 3.75rem;
  --ease-spring: cubic-bezier(.32, .72, 0, 1);   /* fast start, long soft landing, like an iOS sheet */
}

/* ======================= 1. concentric corners ======================= */

/* outer surfaces: radius = radius of what is inside + the padding around it */
:where(.app-page) .card { --surface-inset: 1rem; --surface-radius: calc(var(--control-radius) + var(--surface-inset)); border-radius: var(--surface-radius); }
:where(.app-page) .card.p-2 { --surface-inset: .5rem; }
:where(.app-page) .card.p-3 { --surface-inset: .75rem; }
:where(.app-page) .card:is(.p-5, .p-8, .p-10) { --surface-inset: 1.25rem; }
:where(.app-page) .card:is(.p-6, .p-7) { --surface-inset: 1.25rem; padding: var(--surface-inset); }

/* pop-up windows */
:where(.app-page) .rounded-3xl:is(.p-5, .p-6) { --surface-inset: 1.25rem; padding: var(--surface-inset); border-radius: calc(var(--control-radius) + var(--surface-inset)); }
.app-page .rounded-3xl.p-8 { --surface-inset: 1.5rem; padding: var(--surface-inset); border-radius: calc(var(--control-radius) + var(--surface-inset)); }

/* first level inside a surface */
:where(.app-page) :where(.card, .rounded-3xl) :is(.rounded-lg, .rounded-xl, .rounded-2xl, .inp, .ghost, .btn, .opt, .sub) { border-radius: var(--control-radius); }

/* second level: controls inside a padded box that is itself inside a surface (never sharper than 8px) */
:where(.app-page) :where(.card, .rounded-3xl) :where(.rounded-xl, .rounded-2xl):where(.p-2, .p-3, .p-4) :is(.rounded-lg, .rounded-xl, .inp, .ghost, .btn) {
  border-radius: max(calc(var(--control-radius) - .25rem), .5rem);
}

/* segmented controls: .25rem of padding, so the segments are .25rem tighter than their track */
.app-page :is(.rounded-xl, .rounded-2xl).p-1 { border-radius: var(--control-radius); }
.app-page :is(.rounded-xl, .rounded-2xl).p-1 > * { border-radius: calc(var(--control-radius) - .25rem); }

/* ======================= 2. touch ======================= */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
a, button, input, label, select, summary, textarea, [role="button"], [role="option"], [role="menuitem"] {
  touch-action: manipulation;             /* no wait for a possible double-tap zoom */
  -webkit-tap-highlight-color: transparent;
}
a:active { opacity: .75; }
tr[data-dx]:active > td, .row:active, .dd-menu [role="option"]:active { background-color: #e6f3fc; }

/* iPhones zoom the whole page when a field with text under 16px gets focus */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { font-size: max(1rem, 16px) !important; }
}

/* on a touch screen "hover" sticks after a tap, so nothing should stay lifted */
@media (hover: none) {
  .btn:hover, .btn-accent:hover, .stat:hover, .card:hover, .card-sm:hover, .spc:hover, .feat:hover, .store:hover,
  #backToTop.show:hover, [class*="hover:-translate-y"]:hover { transform: none; }
  .app-page .ghost:hover { background-color: #fff; border-color: #d3e0ec; }
}

/* ======================= 3. motion ======================= */
@keyframes contentArrive { from { opacity: 0; transform: translateY(.5rem); } to { opacity: 1; transform: none; } }
@keyframes overlayFade { from { opacity: 0; } }
@keyframes overlayRise { from { opacity: 0; transform: translateY(1.5rem) scale(.96); } }

/* a new screen, tab or opened table row eases into place */
.app-page #main > *, .app-page .panel.on { animation: contentArrive .38s var(--ease-spring) backwards; }
.app-page #main > p:only-child { animation-delay: .2s; }          /* a quick load never flashes the spinner */
.app-page .dx.open > td > div { animation: contentArrive .3s var(--ease-spring) backwards; }

/* the pop-up window: the backdrop fades while the sheet rises; closing plays it backwards and can be interrupted */
.app-page #modal { transition: opacity .22s ease, display .22s allow-discrete; }
.app-page #modal > * { transition: transform .42s var(--ease-spring), opacity .22s ease; }
.app-page #modal > .rise { animation: none; opacity: 1; transform: none; }
.app-page #modal.hidden { opacity: 0; pointer-events: none; }
.app-page #modal.hidden > * { transform: translateY(1.25rem) scale(.97); }
@starting-style {
  .app-page #modal:not(.hidden) { opacity: 0; }
  .app-page #modal:not(.hidden) > * { opacity: 0; transform: translateY(1.5rem) scale(.96); }
}
/* confirmation and picker windows made on the spot (closed with dismissOverlay in ui-common.js) */
.overlay-layer { animation: overlayFade .22s ease backwards; }
.overlay-layer > * { animation: overlayRise .42s var(--ease-spring) backwards; }

/* ======================= 4. scrolling ======================= */
.overflow-x-auto { overscroll-behavior-x: contain; }              /* swiping a wide table never goes "back" a page */
.app-page #modal, .app-page #modal .overflow-y-auto, .overlay-layer, .overlay-layer .overflow-y-auto { overscroll-behavior: contain; }
@media (max-width: 1023px) {
  html:has(.app-page #modal:not(.hidden)), html:has(.overlay-layer:not([inert])) { overflow: hidden; }   /* the page behind stays put */
}
table td, .stat b { font-variant-numeric: tabular-nums; }

/* ======================= 5. "reduce motion" ======================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  .app-page #main > *, .app-page .panel.on, .app-page .dx.open > td > div, .overlay-layer, .overlay-layer > * { animation: none !important; }
  .app-page #modal, .app-page #modal > *, .side, .menuScrim, .topBarTitle, #navInd, .fp, .dd-menu {
    transition-duration: .01ms !important; transition-delay: 0s !important;
  }
}
