/* =========================================================
   filtary-utilities.css
   Layout primitives + structural components shared by every surface.

   WHY THIS FILE EXISTS
   --------------------
   The Blade templates are written against a utility vocabulary
   (flex / gap-2 / mb-4 / w-full ...) but no utility framework is
   loaded on the web surfaces. Before this file, 36 of those classes
   resolved to nothing: toolbars collapsed, vertical rhythm was
   absent, and `flex` on a <td> silently destroyed table layout.

   This is a hand-written, dependency-free replacement. Rules:

     1. Utilities are single-purpose and low-specificity. They are
        declared BEFORE component styles in load order so any
        `.ui-*` component always wins a specificity tie.
     2. Spacing uses LOGICAL properties (margin-inline, padding-block,
        inset-inline). Arabic RTL must not need a mirrored stylesheet.
     3. Values come from the token scale in maintenance-system-complete.css.
        No bare hex, no bare px where a token exists.
     4. Anything a component repeats three or more times is a
        component (see `ui-*` below), not a utility.
   ========================================================= */

/* =========================================================
   1. DIRECTION PRIMITIVES
   The drawer and any sliding affordance read --drawer-out so a
   single transform works in both RTL and LTR.
   ========================================================= */

html[dir="rtl"] { --drawer-out: 100%; }
html[dir="ltr"] { --drawer-out: -100%; }

/* =========================================================
   2. DISPLAY
   ========================================================= */

.block    { display: block !important; }
.inline   { display: inline !important; }
.flex     { display: flex !important; }
.inline-flex { display: inline-flex !important; }
.grid     { display: grid !important; }
.hidden   { display: none !important; }

/* `display:none` on the sidebar at <=768px is deliberate: the
   sidebar is a drawer there, not a permanent rail. `.is-open`
   re-enables it via higher specificity. */

/* =========================================================
   3. FLEX / GRID DIRECTION & WRAP
   ========================================================= */

.flex-col     { flex-direction: column !important; }
.flex-row     { flex-direction: row !important; }
.flex-wrap    { flex-wrap: wrap !important; }
.flex-nowrap  { flex-wrap: nowrap !important; }
.flex-1       { flex: 1 1 0% !important; }
.flex-none    { flex: none !important; }
.grow         { flex-grow: 1 !important; }

.items-start    { align-items: flex-start !important; }
.items-center   { align-items: center !important; }
.items-end      { align-items: flex-end !important; }
.items-baseline { align-items: baseline !important; }
.items-stretch  { align-items: stretch !important; }

.justify-start   { justify-content: flex-start !important; }
.justify-center  { justify-content: center !important; }
.justify-end     { justify-content: flex-end !important; }
.justify-between { justify-content: space-between !important; }
.justify-around  { justify-content: space-around !important; }

.self-start   { align-self: flex-start !important; }
.self-center  { align-self: center !important; }
.self-end     { align-self: flex-end !important; }

.min-w-0 { min-width: 0 !important; }

/* =========================================================
   4. GRID
   ========================================================= */

.grid-1 { grid-template-columns: repeat(1, minmax(0, 1fr)) !important; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)) !important; }

@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr) !important; }
}

/* =========================================================
   5. GAP
   ========================================================= */

.gap-0 { gap: 0 !important; }
.gap-1 { gap: var(--s1) !important; }
.gap-2 { gap: var(--s2) !important; }
.gap-3 { gap: var(--s3) !important; }
.gap-4 { gap: var(--s4) !important; }
.gap-5 { gap: var(--s5) !important; }
.gap-6 { gap: var(--s6) !important; }

/* =========================================================
   6. SPACING — logical, token-scaled
   ========================================================= */

.mt-0 { margin-block-start: 0 !important; }
.mt-1 { margin-block-start: var(--s1) !important; }
.mt-2 { margin-block-start: var(--s2) !important; }
.mt-3 { margin-block-start: var(--s3) !important; }
.mt-4 { margin-block-start: var(--s4) !important; }
.mt-5 { margin-block-start: var(--s5) !important; }
.mt-6 { margin-block-start: var(--s6) !important; }
.mt-8 { margin-block-start: var(--s8) !important; }
.mt-10 { margin-block-start: var(--s10) !important; }
/* Half steps -- admin and field views ask for these. */
.mt-1.5 { margin-block-start: var(--s1_5) !important; }
.mt-2.5 { margin-block-start: var(--s2_5) !important; }
.mt-3.5 { margin-block-start: var(--s3_5) !important; }
.mt-4.5 { margin-block-start: var(--s4_5) !important; }

.mb-0 { margin-block-end: 0 !important; }
.mb-1 { margin-block-end: var(--s1) !important; }
.mb-2 { margin-block-end: var(--s2) !important; }
.mb-3 { margin-block-end: var(--s3) !important; }
.mb-4 { margin-block-end: var(--s4) !important; }
.mb-5 { margin-block-end: var(--s5) !important; }
.mb-6 { margin-block-end: var(--s6) !important; }
.mb-8 { margin-block-end: var(--s8) !important; }
.mb-12 { margin-block-end: 48px !important; }

.my-1 { margin-block: var(--s1) !important; }
.my-2 { margin-block: var(--s2) !important; }
.my-3 { margin-block: var(--s3) !important; }
.my-4 { margin-block: var(--s4) !important; }
.my-6 { margin-block: var(--s6) !important; }

/* One-off half-steps that the templates already rely on. */
.mt-4\.5 { margin-block-start: 18px !important; }
.mb-4\.5 { margin-block-end: 18px !important; }
.p-3\.5  { padding: 14px !important; }
.p-4\.5  { padding: 18px !important; }

.ms-1 { margin-inline-start: var(--s1) !important; }
.ms-2 { margin-inline-start: var(--s2) !important; }
.ms-3 { margin-inline-start: var(--s3) !important; }
.ms-4 { margin-inline-start: var(--s4) !important; }
.ms-auto { margin-inline-start: auto !important; }
.me-auto { margin-inline-end: auto !important; }
.mx-auto { margin-inline: auto !important; }

.p-0 { padding: 0 !important; }
.p-1 { padding: var(--s1) !important; }
.p-2 { padding: var(--s2) !important; }
.p-3 { padding: var(--s3) !important; }
.p-4 { padding: var(--s4) !important; }
.p-5 { padding: var(--s5) !important; }
.p-6 { padding: var(--s6) !important; }
.p-3.5 { padding: var(--s3_5) !important; }

.px-3 { padding-inline: var(--s3) !important; }
.px-4 { padding-inline: var(--s4) !important; }
.px-5 { padding-inline: var(--s5) !important; }
.py-2 { padding-block: var(--s2) !important; }
.py-3 { padding-block: var(--s3) !important; }
.py-4 { padding-block: var(--s4) !important; }
.py-1.5 { padding-block: var(--s1_5) !important; }
.pt-4 { padding-block-start: var(--s4) !important; }
.pb-4 { padding-block-end: var(--s4) !important; }

/* =========================================================
   7. SIZING
   ========================================================= */

.w-full  { width: 100% !important; }
.w-auto  { width: auto !important; }
.w-12    { width: 3rem !important; }
.w-24    { width: 6rem !important; }
.w-32    { width: 8rem !important; }
.h-12    { height: 3rem !important; }
.h-24    { height: 6rem !important; }
.max-w-full { max-width: 100% !important; }
.max-w-form { max-width: 720px !important; }
.max-h-thumb { max-height: 280px !important; }

/* =========================================================
   8. BORDER / RADIUS / OBJECT
   ========================================================= */

.border-0 { border: 0 !important; }
.rounded-sm { border-radius: var(--radius-sm) !important; }
.rounded-md { border-radius: var(--radius-md) !important; }
.rounded-lg { border-radius: var(--radius-lg) !important; }
.rounded-xl { border-radius: var(--radius-xl) !important; }
.rounded-2xl { border-radius: var(--radius-2xl) !important; }
.rounded-pill { border-radius: var(--radius-pill) !important; }
.rounded-media { border-radius: 14px !important; }
.object-cover { object-fit: cover !important; }
.object-contain { object-fit: contain !important; }
.overflow-hidden { overflow: hidden !important; }
.overflow-auto { overflow: auto !important; }

/* =========================================================
   9. TYPOGRAPHY
   ========================================================= */

.text-xs   { font-size: 11px !important; }
.text-sm   { font-size: 12px !important; }
.text-base { font-size: 14px !important; }
.text-md   { font-size: 15px !important; }
.text-lg   { font-size: 18px !important; }
.text-xl   { font-size: 20px !important; }
.text-2xl  { font-size: 24px !important; }
.text-3xl  { font-size: 30px !important; }

.font-normal   { font-weight: 400 !important; }
.font-medium   { font-weight: 400 !important; }
.font-semibold { font-weight: 700 !important; }
.font-bold     { font-weight: 700 !important; }
.font-extrabold { font-weight: 700 !important; }

.fw-600 { font-weight: 700 !important; }
.fw-700 { font-weight: 700 !important; }
.fw-800 { font-weight: 700 !important; }

.leading-tight  { line-height: 1.25 !important; }
.leading-snug   { line-height: 1.4 !important; }
.leading-normal { line-height: 1.55 !important; }

.underline-offset { text-underline-offset: 3px; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nowrap { white-space: nowrap !important; }
.tabular { font-variant-numeric: tabular-nums; }

/* =========================================================
   10. TABLE INTEGRITY
   `display:flex` on a <td> removes the cell from the table box
   model: the column stops sizing from its content and the row
   loses baseline alignment. Wrap the cell's children instead.
   `.cell-actions` is the sanctioned pattern for a row action group.
   ========================================================= */

.ui-table td.cell-actions,
.ui-table th.cell-actions {
  text-align: end;
  white-space: nowrap;
  width: 1%;
}
.cell-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* =========================================================
   11. ACCESSIBILITY PRIMITIVES
   ========================================================= */

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Skip link — first tab stop on every page. Visually hidden until
   focused, then pinned top-start over the topbar. */
.skip-link {
  position: fixed;
  inset-block-start: 8px;
  inset-inline-start: 8px;
  z-index: var(--z-modal);
  transform: translateY(calc(-100% - 12px));
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background: var(--brand-primary);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-base) var(--ease-out);
}
.skip-link:focus {
  transform: none;
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: 2px;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:where(a, button, input, select, textarea, summary, [tabindex]):focus:not(:focus-visible) {
  outline: none;
}

/* On navy surfaces the brand-blue ring has only 4.6:1 and sits on a
   dark background; a light ring reads far better there. */
.web-sidebar :where(a, button, summary, [tabindex]):focus-visible,
.app-top :where(a, button, [tabindex]):focus-visible {
  outline-color: var(--focus-ring-color-dark);
  box-shadow: none;
}

/* Minimum hit target. Inline links inside a sentence are exempt. */
:where(button, .ui-btn, .sidebar-link, .app-nav a, .ui-tab, .calendar-event) {
  min-height: var(--hit-target);
}
:where(.ui-btn--sm, .sidebar-section, .ui-badge, .status-pill) {
  min-height: 0;
}

::selection { background: var(--selection-bg); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: content-box; }

/* =========================================================
   12. OFF-CANVAS NAVIGATION
   Applies at every width where the sidebar is not a permanent
   rail. `display:none` at <=768px is preserved deliberately
   (see rule 2); `.is-open` outranks it on specificity.
   ========================================================= */

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--hit-target);
  height: var(--hit-target);
  flex: 0 0 var(--hit-target);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.nav-toggle svg { width: 20px; height: 20px; }
.nav-toggle:hover { background: var(--surface-soft); border-color: var(--border-strong); }

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-backdrop);
  background: rgba(8,24,40,.48);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}
.nav-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 1024px) {
  .nav-toggle { display: inline-flex; }

  /* The rail is out of flow here, so the content must reclaim the
     gutter. Without this the page keeps a 220px empty margin. */
  .web-main {
    width: 100% !important;
    margin-inline-end: 0 !important;
  }

  .web-sidebar {
    position: fixed;
    z-index: var(--z-drawer);
    inset-block: 0;
    inset-inline-start: 0;
    width: 272px;
    max-width: 86vw;
    transform: translateX(var(--drawer-out));
    transition: transform var(--dur-slow) var(--ease-spring);
    will-change: transform;
    box-shadow: var(--shadow-lg);
  }
  .web-sidebar.is-open { transform: none; }

  .web-topbar { padding-inline: var(--s4) !important; }
}

/* Below 768px the base sheet sets display:none. Specificity of
   `.web-sidebar.is-open` (0,2,0) beats `.web-sidebar` (0,1,0), so
   the drawer still opens. */
@media (max-width: 768px) {
  .web-sidebar.is-open { display: flex; }
}

/* =========================================================
   13. PAGINATION
   Laravel's default paginator emits Tailwind utility markup. No
   utility framework is loaded on these pages, so it rendered as an
   unstyled stack of blue links. This component replaces it
   (see resources/views/vendor/pagination/filtary.blade.php).
   ========================================================= */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-block-start: var(--s4);
  padding-block-start: var(--s4);
  border-block-start: 1px solid var(--border-light);
}
.pagination:empty { display: none; }

.pagination__summary {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.pagination__list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.pagination__item { display: inline-flex; }

.pagination__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 38px;
  padding-inline: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}
.pagination__link:hover {
  background: var(--surface-soft);
  border-color: var(--brand-primary);
  color: var(--brand-on-soft);
}
.pagination__link[aria-current="page"] {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}
.pagination__link.is-disabled {
  color: var(--text-light);
  background: var(--surface-muted);
  border-color: var(--border-light);
  cursor: not-allowed;
  pointer-events: none;
}
.pagination__gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 38px;
  color: var(--text-light);
  font-weight: 700;
}

/* The glyphs ‹ › are hard-directioned. In RTL, "previous" is to the
   right, so the whole control mirrors. */
.pagination__icon {
  display: inline-block;
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
}
html[dir="rtl"] .pagination__icon { transform: scaleX(-1); }
html[dir="rtl"] .pagination__label { direction: rtl; }

@media (max-width: 640px) {
  .pagination { justify-content: center; }
  .pagination__summary { width: 100%; text-align: center; }
  .pagination__link { min-width: 40px; min-height: 40px; }
}

/* =========================================================
   14. USER PREFERENCE OVERRIDES
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .web-sidebar { transition: none !important; }
}

/* Windows High Contrast / forced-colors: hand control to the OS. */
@media (forced-colors: active) {
  .ui-btn,
  .ui-card,
  .ui-input,
  .ui-select,
  .ui-badge,
  .status-pill,
  .sidebar-link,
  .pagination__link {
    border: 1px solid CanvasText !important;
  }
  .ui-btn--primary,
  .pagination__link[aria-current="page"] {
    background: Highlight !important;
    color: HighlightText !important;
    forced-color-adjust: none;
  }
  .sidebar-link.is-active {
    background: Highlight !important;
    color: HighlightText !important;
  }
  :where(a, button, input, select, textarea, summary):focus-visible {
    outline: 3px solid CanvasText !important;
  }
}

/* Users who ask the OS for more contrast get firmer borders and
   the text-safe end of the ramp. */
@media (prefers-contrast: more) {
  :root {
    --border: #93A9BE;
    --border-light: #C2D2E0;
    --text-muted: var(--text);
    --text-light: var(--text-muted);
  }
  .ui-card,
  .ui-input,
  .ui-select,
  .ui-textarea,
  .ui-btn--outline {
    border-width: 2px !important;
  }
    .ui-table th { color: var(--text); }
  }

  /* ---- Error pages -------------------------------------------------------
     A standalone surface: no layout, no sidebar, no admin sheet. The error
     views must not link a stylesheet themselves, so the few rules they need
     live here with the rest of the shared cascade. */
  .error-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--page-bg);
    color: var(--text);
  }
  .error-card {
    width: 100%;
    max-width: 520px;
    padding: 40px 32px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-2xl);
    box-shadow: 0 1px 2px rgba(16, 32, 47, .06), 0 8px 24px rgba(16, 32, 47, .06);
  }
  .error-code {
    display: inline-block;
    padding: 6px 14px;
    margin-bottom: 20px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: var(--weight-semibold);
    letter-spacing: .04em;
    color: var(--brand-primary-dark);
    background: var(--brand-primary-soft);
    border-radius: var(--radius-pill);
  }
  .error-title {
    margin: 0 0 10px;
    font-size: 24px;
    line-height: 1.35;
    font-weight: var(--weight-bold);
    color: var(--text-strong);
  }
  .error-body {
    margin: 0 0 28px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-muted);
  }
  .error-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
  }
  .error-note {
    margin: 24px 0 0;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text-light);
  }
  /* Arabic is cursive: a hash the reader may need to quote back to support is
     kept LTR inside an RTL page, or the digits reorder on copy. */
  .error-ref {
    display: inline-block;
    unicode-bidi: isolate;
    direction: ltr;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-body);
  }
  @media (max-width: 480px) {
    .error-page { padding: 16px; }
    .error-card { padding: 32px 20px; border-radius: var(--radius-xl); }
    .error-actions { flex-direction: column; }
    .error-actions .ui-btn { width: 100%; }
  }

