/* ASAS - reset, typography and layout primitives (Milestone F1)
 *
 * Depends on tokens.css. Load order: tokens.css -> base.css -> components.css.
 *
 * LOGICAL PROPERTIES ONLY. `business_settings.default_language` defaults to
 * 'ar' and the conversation engine matches Arabic intent, so this is a
 * bilingual AR/EN product and RTL is a Release-1 requirement, not an
 * enhancement. Never write left/right/margin-left/padding-right/text-align:left
 * in this codebase - use inline-start/inline-end. Retrofitting logical
 * properties across forty surfaces later is the expensive version.
 */

/* ============================================================ RESET ==== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--t-body-size);
  line-height: var(--t-body-lh);
  font-weight: var(--t-body-w);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

img, svg, video, canvas { display: block; max-inline-size: 100%; }
svg { flex: none; }

button, input, select, textarea { font: inherit; color: inherit; margin: 0; }
button { background: none; border: 0; padding: 0; cursor: pointer; }

table { border-collapse: collapse; border-spacing: 0; }

a { color: var(--accent-6); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Inside data, a link is the record itself: it reads as text and lights up on
 * hover, so a table of names is not a wall of accent colour. */
.table a, .list a { color: var(--text-primary); font-weight: 500; }
.table a:hover, .list a:hover { color: var(--accent-6); }

hr { border: 0; border-block-start: var(--bw) solid var(--border-subtle); margin: 0; }

[hidden] { display: none !important; }
/* Class form, for nodes toggled by script that must keep their attributes. */
.hidden { display: none !important; }

/* Focus. `:focus-visible` only, so pointer users are not shown rings - but a
 * replacement is MANDATORY wherever the default outline is removed. A bare
 * `outline: none` is a review-blocking defect in this codebase. */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}
.on-inverse :focus-visible { box-shadow: var(--focus-ring-inverse); }
/* A region that receives focus programmatically (the shell moves focus to
 * #page after every navigation, tabindex=-1) is not a control: ringing it drew
 * a 4px accent rule under the page header on every screen. Controls inside it
 * keep their rings. */
[tabindex="-1"]:focus-visible { box-shadow: none; }

::selection { background: var(--accent-2); color: var(--text-primary); }

/* Skip link - visible only when focused. */
.skip-link {
  position: absolute;
  inset-block-start: var(--s-2);
  inset-inline-start: var(--s-2);
  z-index: var(--z-tooltip);
  padding: var(--s-3) var(--s-5);
  background: var(--bg-surface);
  border: var(--bw) solid var(--border-input);
  border-radius: var(--r-sm);
  transform: translateY(-200%);
}
.skip-link:focus-visible { transform: none; }

/* ================================================ DIRECTION & LANGUAGE == */

:lang(ar), [dir="rtl"] { font-family: var(--font-arabic); }

/* Arabic is set ~7% larger than the Latin it pairs with (identity rule), with
 * more leading - Plex Arabic's descenders and the seen's bowl need the room.
 * Done by re-stating the size tokens, so every component follows. */
html[lang="ar"] {
  --t-body-size: 15px;      --t-body-lh: 24px;
  --t-secondary-size: 14px; --t-secondary-lh: 22px;
  --t-cell-size: 14px;      --t-cell-lh: 22px;
  --t-label-size: 13px;     --t-label-lh: 20px;
  --t-meta-size: 12px;      --t-meta-lh: 18px;
  --t-sub-size: 14px;       --t-sub-lh: 22px;
  --t-overline-ls: 0;       --t-meta-ls: 0;
}

/* Glyphs that encode direction must mirror in RTL. Applied by class so we
 * never mirror an icon whose meaning is direction-independent (a clock, a
 * checkmark). The Monolith is symmetrical and is NEVER mirrored. */
[dir="rtl"] .icon-directional { transform: scaleX(-1); }

/* ============================================== TYPOGRAPHIC ROLES ====== */

/* Headlines speak in the wordmark's voice: Alexandria. Body copy steps back
 * to Instrument Sans / Plex Arabic. Arabic display is Bold and never tracked. */
.t-display, .t-page-title, .t-section-title, .t-metric, .t-metric-lg,
.dialog-header h2, .drawer-header h2, .empty-title, .state-title {
  font-family: var(--font-display);
}
html[lang="ar"] :is(.t-display, .t-page-title, .t-section-title, .t-metric, .t-metric-lg,
  .dialog-header h2, .drawer-header h2, .empty-title, .state-title) {
  font-weight: 700; letter-spacing: 0;
}

.t-display {
  font-size: var(--t-display-size); line-height: var(--t-display-lh);
  font-weight: var(--t-display-w); letter-spacing: var(--t-display-ls);
}
.t-page-title {
  font-size: var(--t-page-size); line-height: var(--t-page-lh);
  font-weight: var(--t-page-w); letter-spacing: var(--t-page-ls);
}
.t-section-title {
  font-size: var(--t-section-size); line-height: var(--t-section-lh);
  font-weight: var(--t-section-w); letter-spacing: var(--t-section-ls);
}
.t-subsection {
  font-size: var(--t-sub-size); line-height: var(--t-sub-lh);
  font-weight: var(--t-sub-w);
}
.t-body { font-size: var(--t-body-size); line-height: var(--t-body-lh); }
.t-strong { font-weight: var(--t-strong-w); }
.t-secondary {
  font-size: var(--t-secondary-size); line-height: var(--t-secondary-lh);
  color: var(--text-secondary);
}
.t-label {
  font-size: var(--t-label-size); line-height: var(--t-label-lh);
  font-weight: var(--t-label-w); color: var(--text-tertiary);
}
.t-meta {
  font-size: var(--t-meta-size); line-height: var(--t-meta-lh);
  font-weight: var(--t-meta-w); letter-spacing: var(--t-meta-ls);
  color: var(--text-tertiary);
}
.t-overline {
  font-size: var(--t-overline-size); line-height: var(--t-overline-lh);
  font-weight: var(--t-overline-w); letter-spacing: var(--t-overline-ls);
  text-transform: uppercase; color: var(--text-tertiary);
}
.t-metric {
  font-size: var(--t-metric-size); line-height: var(--t-metric-lh);
  font-weight: var(--t-metric-w); letter-spacing: var(--t-metric-ls);
  font-variant-numeric: tabular-nums;
}
/* Max three per page. Nothing in this application is larger. */
.t-metric-lg {
  font-size: var(--t-metric-lg-size); line-height: var(--t-metric-lg-lh);
  font-weight: var(--t-metric-w); letter-spacing: var(--t-metric-ls);
  font-variant-numeric: tabular-nums;
}
.t-code {
  font-family: var(--font-mono);
  font-size: var(--t-code-size); line-height: var(--t-code-lh);
}
.t-num { font-variant-numeric: tabular-nums; }

.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.text-success   { color: var(--success-6); }
.text-warning   { color: var(--warning-6); }
.text-danger    { color: var(--danger-6); }
.text-accent    { color: var(--accent-6); }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  line-clamp: 2; overflow: hidden;
}

/* Screen-reader-only, but focusable when it needs to be. */
.sr-only {
  position: absolute; inline-size: 1px; block-size: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ================================================ LAYOUT PRIMITIVES ==== */

.stack   { display: flex; flex-direction: column; }
.row     { display: flex; flex-direction: row; align-items: center; }
.row-top { display: flex; flex-direction: row; align-items: flex-start; }
.wrap    { flex-wrap: wrap; }
.grow    { flex: 1 1 auto; min-inline-size: 0; }
.none    { flex: none; }
.between { justify-content: space-between; }
.center  { justify-content: center; }
.end     { justify-content: flex-end; }
.items-center { align-items: center; }
.items-end    { align-items: flex-end; }

.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }
.gap-5 { gap: var(--s-5); } .gap-6 { gap: var(--s-6); }
.gap-7 { gap: var(--s-7); } .gap-8 { gap: var(--s-8); }

.mbs-2 { margin-block-start: var(--s-2); } .mbs-4 { margin-block-start: var(--s-4); }
.mbs-5 { margin-block-start: var(--s-5); } .mbs-6 { margin-block-start: var(--s-6); }
.mbs-8 { margin-block-start: var(--s-8); }
.mbe-2 { margin-block-end: var(--s-2); } .mbe-4 { margin-block-end: var(--s-4); }
.mbe-5 { margin-block-end: var(--s-5); } .mbe-6 { margin-block-end: var(--s-6); }
.mis-auto { margin-inline-start: auto; }
.mie-auto { margin-inline-end: auto; }

.p-4 { padding: var(--s-4); } .p-5 { padding: var(--s-5); }
.p-6 { padding: var(--s-6); } .p-8 { padding: var(--s-8); }

.grid { display: grid; gap: var(--s-5); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-all { grid-column: 1 / -1; }

/* Records and forms are measured; tables and the inbox are full-bleed. */
.measure { max-inline-size: var(--content-max); }
.gutter  { padding-inline: var(--gutter); }

.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }
.scroll-y { overflow-y: auto; overscroll-behavior-y: contain; }

/* ==================================================== BREAKPOINTS ====== */

@media (max-width: 1119px) { :root { --gutter: 16px; } }
@media (max-width: 767px) {
  :root { --gutter: 12px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 899px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Touch targets grow on coarse pointers (WCAG 2.2 SC 2.5.8). */
@media (pointer: coarse) {
  .tap { min-block-size: 44px; min-inline-size: 44px; }
}

/* ======================================================== MOTION ======= */

/* Motion is permitted ONLY for: state transition, layer enter/exit, feedback
 * and progress - plus the ONE brand signature, the filament (ignition once per
 * session, then breath). "The body is still. The light moves." No hover lift,
 * no parallax, no scroll-triggered reveal, no counting numbers, no animation of
 * the message stream or attention strip. Only transform and opacity animate. */

/* Ignition: the light appears first, then the body resolves around it. The
 * shell adds .is-igniting to the brand mark on the first mount of a session. */
@keyframes asas-filament-in { from { opacity: 0; transform: scaleY(.2); } to { opacity: 1; transform: none; } }
@keyframes asas-body-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes asas-breathe { 0%, 100% { opacity: .55; transform: scaleX(1); } 50% { opacity: 1; transform: scaleX(1.6); } }
.monolith .monolith-filament, .monolith .monolith-halo { transform-box: fill-box; transform-origin: center; }
.monolith.is-igniting .monolith-filament { animation: asas-filament-in calc(var(--dur-ignite) * .45) var(--ease-out) both; }
.monolith.is-igniting .monolith-body { animation: asas-body-in var(--dur-ignite) var(--ease-out) calc(var(--dur-ignite) * .2) both; }
.monolith.is-breathing .monolith-halo { animation: asas-breathe var(--dur-breath) ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 1ms;
    --dur-base: 1ms;
    --dur-slow: 1ms;
    --dur-ignite: 1ms;
  }
  /* Reduced motion: the lit, static mark. */
  .monolith .monolith-halo, .monolith .monolith-filament, .monolith .monolith-body { animation: none !important; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  /* Transforms are removed entirely rather than shortened: a 1ms slide still
   * reads as a jump. Opacity changes are retained - they are not vestibular
   * triggers and they carry the state change. */
  .drawer, .sheet, .dialog, .toast, .tooltip { transform: none !important; }
  .skeleton { animation: none !important; background-image: none !important; }
}

/* The clinic logo beside its name in the console header (clinic branding). */
.app-brand-logo { display: inline-block; vertical-align: middle; margin-inline-end: 6px; object-fit: contain; }
.branding-logo-preview { display: block; max-width: 180px; height: auto; object-fit: contain; border: 1px solid var(--border, #ddd); border-radius: 6px; padding: 6px; background: #fff; }
