/* ==========================================================================
   Base: maps Bootstrap 5 variables to MostaERP tokens, typography, focus.
   Bootstrap is used for grid, utilities and JS behaviours only.
   ========================================================================== */

:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
  --bs-body-font-family: var(--font-family);
  --bs-body-font-size: var(--fs-body);
  --bs-body-line-height: var(--lh-base);
  --bs-body-color: var(--text);
  --bs-body-bg: var(--bg);
  --bs-border-color: var(--border);
  --bs-border-radius: var(--r-md);
  --bs-link-color: var(--accent-text);
  --bs-link-hover-color: var(--accent-hover);
  --bs-emphasis-color: var(--text);
  --bs-secondary-color: var(--text-muted);
  --bs-tertiary-bg: var(--surface-2);
  --bs-gutter-x: var(--gutter);
  --bs-gutter-y: var(--gutter);
}

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

body {
  font-family: var(--font-family);
  font-size: var(--fs-body);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: var(--fw-semibold); line-height: var(--lh-tight); color: var(--text); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4, h5, h6 { font-size: var(--fs-sm); }
p { margin: 0 0 var(--sp-2); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-hover); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; opacity: 1; }
small, .text-small { font-size: var(--fs-xs); }
code { font-family: var(--font-mono); font-size: 0.92em; background: var(--surface-hover); padding: 0.1em 0.35em; border-radius: var(--r-sm); color: var(--text); }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: var(--r-sm); }

::selection { background: var(--accent-soft-strong); }

/* Utility colours that follow the theme */
.text-muted-2 { color: var(--text-muted) !important; }
.text-faint { color: var(--text-faint) !important; }
.text-success-2 { color: var(--success) !important; }
.text-danger-2 { color: var(--danger) !important; }
.text-warning-2 { color: var(--warning) !important; }
.fw-med { font-weight: var(--fw-medium); }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Slim scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* Directional icons flip in RTL */
[dir="rtl"] .bi-flip-rtl { transform: scaleX(-1); }

.visually-hidden-focusable:focus { position: fixed; inset-block-start: 8px; inset-inline-start: 8px; z-index: var(--z-modal); background: var(--surface); padding: .4rem .7rem; border-radius: var(--r-md); box-shadow: var(--sh-menu); }

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

/* Links are never underlined (normal, hover, focus, active) — colour and the focus ring carry the state. Bootstrap's own
   a:hover / .link-* / .text-decoration-underline rules are overridden here, once, for the whole app. */
a, a:hover, a:focus, a:focus-visible, a:active, a:visited,
.link-primary, .link-secondary, .link-body-emphasis, .text-decoration-underline, .text-decoration-underline-hover:hover { text-decoration: none !important; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

/* Links are not underlined, so a link inside running text needs more than its colour to be told apart (WCAG 1.4.1): a heavier weight. */
p a:not(.m-btn), .m-field__hint a, .m-alert a:not(.m-btn), .ct-header__meta a, .page-header__title p a, .m-empty__text a, .m-list__main small a, .m-list__main > a, .ct-people a { font-weight: var(--fw-medium); }

/* Bootstrap's colour utilities follow the app's semantic tokens (calmer, and contrast-checked in both themes) instead of Bootstrap's own palette. */
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }
.text-primary { color: var(--accent-text) !important; }
.text-secondary, .text-muted, .text-body-secondary { color: var(--text-muted) !important; }
