/* SBA base styles and components. Requires tokens.css.
   Rules of this file: every value is a token; every direction is logical
   (inline-start / inline-end), never left / right; no letter-spacing; two
   font weights only; frosted glass on the navigation layer only; layout
   adapts by window size class from a 320px phone to a wall display. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* design-lint: allow important - the hidden attribute must always win */
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  line-height: var(--leading-body);
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;            /* never fake a weight or an italic */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(ar) { line-height: var(--leading-body-ar); }
h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
ul[role="list"], ol[role="list"] { padding: 0; list-style: none; }
h1, h2, h3, h4 { font-weight: var(--weight-bold); line-height: var(--leading-tight); text-wrap: balance; }
h1 { font-size: var(--text-h1); }
h2 { font-size: var(--text-h2); }
h3 { font-size: var(--text-h3); line-height: var(--leading-snug); }
:lang(ar) :is(h1, h2, h3, h4) { line-height: 1.45; }
p { max-inline-size: var(--measure); text-wrap: pretty; }
a { color: var(--link); text-underline-offset: 0.2em; }
a:hover { color: var(--action-hover); }
b, strong { font-weight: var(--weight-bold); }
em, i, cite { font-style: normal; }   /* Arabic has no italic; emphasis is weight */
img, svg { display: block; max-inline-size: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft-border); color: var(--text); }

:focus:not(:focus-visible) { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; /* design-lint: allow important - user preference overrides everything */
    animation-iteration-count: 1 !important; /* design-lint: allow important */
    transition-duration: 1ms !important; /* design-lint: allow important */
    scroll-behavior: auto !important; /* design-lint: allow important */
  }
}

.visually-hidden {
  position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.text-secondary { color: var(--text-secondary); }
.text-small { font-size: var(--text-small); }
.num { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; }
/* Codes, phone numbers, emails and URLs keep left-to-right order inside Arabic. */
.ltr { direction: ltr; unicode-bidi: isolate; }

/* Icons: one set, 1.5 stroke, drawn in currentColor. */
.icon { inline-size: var(--icon-md); block-size: var(--icon-md); flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { inline-size: var(--icon-sm); block-size: var(--icon-sm); }
/* Icons that imply direction (back, next, chevrons) mirror in right-to-left. */
[dir="rtl"] .icon--dir { transform: scaleX(-1); }

/* ---------- Materials ---------- */
/* Frosted glass belongs to the navigation layer: bars that content scrolls
   beneath, and small floating messages. It is never used for content. The
   tint is mostly opaque (frosted, not clear), so text stays legible over
   anything. Where blur is unsupported, or the person asks for less
   transparency or more contrast, it turns solid automatically. */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: inset 0 1px 0 var(--glass-highlight);
}
.glass--thick { background: var(--glass-bg-thick); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass-bg: var(--surface); --glass-bg-thick: var(--surface-raised); }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  :root { --glass-bg: var(--surface); --glass-bg-thick: var(--surface-raised); --glass-blur: 0px; --glass-saturate: 1; --scrim-blur: 0px; }
}

/* ---------- App shell ---------- */
/* Navigation changes form with the window: side navigation (840px and wider),
   a rail (600 to 839px), a bottom bar (under 600px). Same destinations, same
   markup, at every size. */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: auto 1fr; min-block-size: 100vh; min-block-size: 100dvh; }
.topbar {
  grid-column: 1 / -1; position: sticky; inset-block-start: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--space-4);
  block-size: var(--topbar-height);
  padding-inline: max(var(--page-gutter), env(safe-area-inset-left), env(safe-area-inset-right));
  border-block-end: 1px solid var(--glass-border);
}
/* Logo: half the bar's height, which leaves the brand guide's clear space
   (half the mark's height) above, below and beside it. */
.topbar__logo { block-size: calc(var(--topbar-height) / 2); inline-size: auto; margin-inline-end: var(--space-4); }
.topbar__spacer { flex: 1; }
.sidenav {
  position: sticky; inset-block-start: var(--topbar-height); align-self: start;
  block-size: calc(100vh - var(--topbar-height)); block-size: calc(100dvh - var(--topbar-height)); overflow-y: auto;
  padding: var(--space-4) var(--space-3); border-inline-end: 1px solid var(--border); background: var(--surface);
}
.sidenav__list { display: grid; gap: var(--space-1); }
.sidenav__link {
  position: relative; display: flex; align-items: center; gap: var(--space-3);
  min-block-size: var(--control-md); padding-inline: var(--space-3);
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none; line-height: var(--leading-snug);
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.sidenav__link[aria-current="page"] { background: var(--surface-selected); font-weight: var(--weight-bold); }
.sidenav__link[aria-current="page"]::before {
  content: ""; position: absolute; inset-inline-start: 0; inset-block: var(--space-2);
  inline-size: 3px; border-radius: var(--radius-full); background: var(--accent);
}
@media (hover: hover) { .sidenav__link:hover { background: var(--surface-hover); color: var(--text); } }
.main { min-inline-size: 0; background: var(--surface-sunken); }
.page { max-inline-size: var(--content-max); margin-inline: auto; padding: var(--space-8) var(--page-gutter) var(--space-16); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-6); }
.page-header { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-4); }
.page-header__text { display: grid; gap: var(--space-1); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-block-size: var(--control-md); padding-inline: var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text);
  font-weight: var(--weight-bold); font-size: var(--text-small); line-height: 1.2;
  text-decoration: none; white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.btn--primary { background: var(--action); color: var(--on-action); }
.btn--primary:hover { background: var(--action-hover); color: var(--on-action); }
.btn--primary:active { background: var(--action-pressed); }
.btn--secondary { border-color: var(--border-strong); background: var(--surface); }
.btn--secondary:hover { background: var(--surface-hover); }
.btn--ghost:hover { background: color-mix(in srgb, currentColor calc(var(--state-hover) * 100%), transparent); }
.btn--ghost:active { background: color-mix(in srgb, currentColor calc(var(--state-pressed) * 100%), transparent); }
.btn--danger { background: var(--danger); color: var(--text-inverse); }
.btn--sm { min-block-size: var(--control-sm); padding-inline: var(--space-3); }
.btn--lg { min-block-size: var(--control-lg); padding-inline: var(--space-6); font-size: var(--text-body); }
.btn--icon { inline-size: var(--control-md); padding: 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: var(--opacity-disabled); cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }

/* ---------- Forms ---------- */
.field { display: grid; gap: var(--space-2); }
.field__label { font-size: var(--text-small); font-weight: var(--weight-bold); line-height: var(--leading-snug); }
.field__hint { font-size: var(--text-small); color: var(--text-secondary); }
.field__error { display: flex; gap: var(--space-2); align-items: start; font-size: var(--text-small); color: var(--danger); }
.input, .select, .textarea {
  inline-size: 100%; min-block-size: var(--control-md); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); line-height: var(--leading-snug);
  transition: border-color var(--duration-fast) var(--ease-standard);
}
.textarea { min-block-size: 6rem; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-secondary); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-secondary); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline-offset: 0; border-color: var(--focus-ring); border-radius: var(--radius-sm); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-sunken); color: var(--text-disabled); cursor: not-allowed; }
.input-group { position: relative; }
.input-group > .icon { position: absolute; inset-block-start: 50%; inset-inline-start: var(--space-3); translate: 0 -50%; color: var(--text-secondary); pointer-events: none; }
.input-group > .input { padding-inline-start: var(--space-10); }
.check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check input { inline-size: 1.125rem; block-size: 1.125rem; margin: 0; accent-color: var(--action); }

/* ---------- Surfaces ---------- */
/* A panel groups content on the page. A card is a distinct object in a
   collection. Do not wrap every block in either. */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.panel__header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-block-end: 1px solid var(--border); }
.panel__body { padding: var(--space-5); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); }

/* Summary strip: related figures in one surface, separated by hairlines. */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.summary__item { display: grid; gap: var(--space-1); padding: var(--space-5) var(--space-6); border-inline-start: 1px solid var(--border); }
.summary__item:first-child { border-inline-start: 0; }
.summary__label { font-size: var(--text-small); color: var(--text-secondary); line-height: var(--leading-snug); }
.summary__value { font-size: var(--text-h1); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.summary__unit { font-size: var(--text-body); font-weight: var(--weight-regular); color: var(--text-secondary); }
.summary__note { font-size: var(--text-small); color: var(--text-secondary); line-height: var(--leading-snug); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { inline-size: 100%; border-collapse: collapse; font-size: var(--text-small); line-height: var(--leading-snug); }
.table th, .table td { padding: var(--space-3) var(--space-5); text-align: start; vertical-align: middle; border-block-end: 1px solid var(--border); white-space: nowrap; }
.table th { font-weight: var(--weight-bold); color: var(--text-secondary); background: var(--surface); position: sticky; inset-block-start: 0; }
.table tbody tr:last-child td { border-block-end: 0; }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr[aria-selected="true"] { background: var(--surface-selected); }
.table .cell-num { text-align: end; }
/* Sharjah has proportional figures only, so numeric cells use a face with tabular figures. */
.table td.cell-num { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; }
.table .cell-title { font-weight: var(--weight-bold); white-space: normal; min-inline-size: 14rem; }
/* The title column is the row's link: text colour, underlined on hover and focus. */
.table .cell-title a { color: var(--text); text-decoration: none; }
.table .cell-title a:hover { text-decoration: underline; }
.table .cell-actions { text-align: end; }

/* ---------- Segmented control and tabs ---------- */
.segmented { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius-sm); background: var(--surface-muted); }
.segmented__item { min-block-size: calc(var(--control-sm) + 2px); padding-inline: var(--space-3); border: 0; border-radius: calc(var(--radius-sm) - 2px); background: transparent; font-size: var(--text-small); cursor: pointer; }
.segmented__item[aria-pressed="true"] { background: var(--surface); font-weight: var(--weight-bold); box-shadow: var(--shadow-1); }
.tabs { display: flex; gap: var(--space-6); border-block-end: 1px solid var(--border); }
.tabs__tab { position: relative; padding-block: var(--space-3); border: 0; background: none; color: var(--text-secondary); cursor: pointer; }
.tabs__tab[aria-selected="true"] { color: var(--text); font-weight: var(--weight-bold); }
.tabs__tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 0; inset-block-end: -1px; block-size: 2px; background: var(--accent); }

/* ---------- Status and tags ---------- */
/* Status is a dot plus a word: colour is never the only signal. */
.status { display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.status::before { content: ""; inline-size: 0.5rem; block-size: 0.5rem; border-radius: var(--radius-full); background: var(--text-disabled); flex: none; }
.status--success::before { background: var(--success); }
.status--warning::before { background: var(--warning); }
.status--danger::before { background: var(--danger); }
.status--info::before { background: var(--info); }
.status--accent::before { background: var(--accent); }
.tag { display: inline-flex; align-items: center; min-block-size: 1.5rem; padding-inline: var(--space-2); border-radius: var(--radius-xs); background: var(--surface-muted); font-size: var(--text-caption); line-height: 1; }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: var(--space-3); align-items: start; padding: var(--space-3) var(--space-4); border: 1px solid var(--info-border); border-radius: var(--radius-md); background: var(--info-soft); color: var(--on-info-soft); font-size: var(--text-small); line-height: var(--leading-body); }
:lang(ar) .alert { line-height: var(--leading-body-ar); }
.alert .icon { margin-block-start: var(--space-1); }
.alert--success { border-color: var(--success-border); background: var(--success-soft); color: var(--on-success-soft); }
.alert--warning { border-color: var(--warning-border); background: var(--warning-soft); color: var(--on-warning-soft); }
.alert--danger { border-color: var(--danger-border); background: var(--danger-soft); color: var(--on-danger-soft); }
.alert a { color: inherit; font-weight: var(--weight-bold); }

/* ---------- Dialog ---------- */
.dialog { inline-size: min(34rem, calc(100vw - var(--space-8))); padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-3); }
.dialog::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(var(--scrim-blur, 6px)); backdrop-filter: blur(var(--scrim-blur, 6px)); }
.dialog[open] { animation: dialog-in var(--duration-slow) var(--ease-enter); }
@keyframes dialog-in { from { opacity: 0; translate: 0 0.5rem; } }
.dialog__header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-5) var(--space-6) 0; }
.dialog__body { display: grid; gap: var(--space-5); padding: var(--space-5) var(--space-6); }
.dialog__footer { display: flex; justify-content: end; gap: var(--space-3); padding: var(--space-4) var(--space-6) var(--space-6); }

/* ---------- Empty and loading states ---------- */
.empty { display: grid; justify-items: center; gap: var(--space-3); padding: var(--space-16) var(--space-6); text-align: center; }
.empty .icon { inline-size: 2.5rem; block-size: 2.5rem; color: var(--text-secondary); }
.empty p { color: var(--text-secondary); }
.skeleton { display: block; block-size: 0.875rem; border-radius: var(--radius-xs); background: var(--surface-muted); animation: skeleton 1.2s var(--ease-standard) infinite alternate; }
@keyframes skeleton { to { background: var(--surface-muted-strong); } }

/* ---------- Small pieces ---------- */
.avatar { display: inline-grid; place-items: center; inline-size: var(--control-md); block-size: var(--control-md); border-radius: var(--radius-full); background: var(--surface-muted); font-size: var(--text-small); font-weight: var(--weight-bold); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.stack { display: grid; gap: var(--space-4); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) var(--space-5); border-block-start: 1px solid var(--border); font-size: var(--text-small); color: var(--text-secondary); }

/* Floating message. Sits above the bottom bar on compact windows. */
.toast {
  position: fixed; z-index: var(--z-toast);
  inset-inline: 0; inset-block-end: calc(var(--space-6) + env(safe-area-inset-bottom));
  inline-size: fit-content; max-inline-size: calc(100vw - var(--space-8)); margin-inline: auto;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border: 1px solid var(--glass-border); border-radius: var(--radius-md);
  font-size: var(--text-small); line-height: var(--leading-snug); box-shadow: var(--shadow-2), inset 0 1px 0 var(--glass-highlight);
}

/* ---------- Adaptive layout ---------- */
/* Window size classes: compact < 600 | medium 600-839 | expanded 840-1199 |
   large 1200-1599 | extra-large >= 1600. Lay out by the space available,
   never by device type. */

/* medium, or any wider window that is short (a phone on its side): the side
   navigation becomes a rail */
@media (min-width: 600px) and (max-width: 839.98px), (min-width: 600px) and (max-height: 479.98px) {
  .app { grid-template-columns: var(--rail-width) minmax(0, 1fr); }
  .sidenav { padding: var(--space-3) var(--space-2); }
  .sidenav__link { flex-direction: column; justify-content: center; gap: var(--space-1); min-block-size: 3.75rem; padding: var(--space-2) var(--space-1); font-size: var(--text-caption); text-align: center; }
  /* Tables keep their columns but drop the ones marked optional; the detail
     view still shows them. */
  .table th, .table td { padding-inline: var(--space-3); }
  .table .cell-optional { display: none; }
}

/* compact: bottom navigation in frosted glass, one column, larger actions */
@media (max-width: 599.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar { gap: var(--space-2); }
  .sidenav {
    position: fixed; inset-inline: 0; inset-block: auto 0; z-index: var(--z-sticky);
    block-size: auto; overflow: visible; padding: 0; padding-block-end: env(safe-area-inset-bottom);
    border-inline-end: 0; border-block-start: 1px solid var(--glass-border);
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  }
  .sidenav__list { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; }
  .sidenav__link { flex-direction: column; justify-content: center; gap: var(--space-1); min-block-size: var(--bottombar-height); padding: var(--space-1); border-radius: 0; font-size: var(--text-caption); text-align: center; }
  .sidenav__link[aria-current="page"] { background: transparent; }
  .sidenav__link[aria-current="page"]::before { inset-inline: 28%; inset-block: 0 auto; inline-size: auto; block-size: 3px; }
  .page { padding-block: var(--space-6) calc(var(--bottombar-height) + env(safe-area-inset-bottom) + var(--space-8)); }
  .toast { inset-block-end: calc(var(--bottombar-height) + env(safe-area-inset-bottom) + var(--space-4)); }
  .page-header .btn--primary { inline-size: 100%; min-block-size: var(--control-lg); }
  .summary { grid-template-columns: 1fr; }
  .summary__item { border-inline-start: 0; border-block-start: 1px solid var(--border); padding: var(--space-4) var(--space-5); }
  .summary__item:first-child { border-block-start: 0; }
  .summary__value { font-size: var(--text-h2); }
  .panel__header > * { flex: 1 1 100%; }
  .dialog__footer { flex-direction: column-reverse; }
  .dialog__footer .btn { inline-size: 100%; min-block-size: var(--control-lg); }

  /* A table marked .table--stack becomes a list: each row a block, each cell
     a labelled line. Cells need data-label. */
  .table--stack thead { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; }
  .table--stack tr { padding: var(--space-3) var(--space-5); border-block-end: 1px solid var(--border); }
  .table--stack tbody tr:last-child { border-block-end: 0; }
  .table--stack td { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); padding: var(--space-1) 0; border: 0; white-space: normal; text-align: end; }
  .table--stack td::before { content: attr(data-label); flex: none; color: var(--text-secondary); text-align: start; font-family: var(--font-sans); }
  .table--stack td.cell-title { display: block; min-inline-size: 0; padding-block-end: var(--space-2); font-size: var(--text-body); text-align: start; }
  .table--stack td.cell-title::before { content: none; }
}

/* short windows (a phone on its side): give the height back to the content */
@media (max-height: 479.98px) {
  .topbar { position: static; }
  .sidenav { inset-block-start: 0; block-size: 100vh; block-size: 100dvh; }
}

/* very large displays (wall screens, meeting rooms): scale everything up so
   it reads from a distance. All sizes are in rem, so one line does it. */
@media (min-width: 2200px) { html { font-size: 112.5%; } }
@media (min-width: 3200px) { html { font-size: 150%; } }

/* touch: every control gets at least a 44px hit area, and no hover styles
   that stick after a tap. Kept at the end so it wins over component sizes. */
@media (pointer: coarse) {
  .btn, .input, .select, .segmented__item { min-block-size: var(--target-min); }
  .btn--icon, .segmented__item { min-inline-size: var(--target-min); }
  .sidenav__link { min-block-size: var(--control-lg); }
  .check { min-block-size: var(--target-min); }
}
@media (hover: none) { .table tbody tr:hover { background: transparent; } }

/* high-contrast modes set by the operating system */
@media (forced-colors: active) {
  .btn { border-color: ButtonBorder; }
  .sidenav__link[aria-current="page"] { outline: 2px solid Highlight; outline-offset: -2px; }
  .status::before { forced-color-adjust: none; }
}

/* print: the content only, on white */
@media print {
  .topbar, .sidenav, .btn, .segmented, .input-group, .pagination, .toast, .dialog { display: none; }
  .app { display: block; }
  body, .main { background: none; }
  .page { max-inline-size: none; padding: 0; }
  .table th { position: static; }
  a { color: inherit; text-decoration: none; }
  @page { margin: 16mm; }
}
