/*
  FlowSentry v3 — base: element defaults, typography, focus, native controls.
  Element rules sit inside :where() (zero specificity), so any class — a primitive, a scoped page style or a Tailwind
  utility — overrides them without !important. Radzen's own inputs (class rz-*) are left alone.
*/

@layer fs-base {

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--fs-appbar-h) + var(--fs-space-4));
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--fs-font-sans);
  font-size: var(--fs-text-base);
  line-height: var(--fs-leading-base);
  font-feature-settings: var(--fs-font-features);
  letter-spacing: -0.003em;
  color: var(--fs-color-text-primary);
  background: var(--fs-color-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--fs-color-accent-soft-hover);
  color: var(--fs-color-text-primary);
}

/* Typography */
:where(h1, h2, h3, h4, h5, h6) {
  margin: 0 0 var(--fs-space-3);
  color: var(--fs-color-text-primary);
  font-weight: var(--fs-weight-semibold);
  letter-spacing: var(--fs-tracking-tight);
  text-wrap: balance;
}

:where(h1) { font-size: var(--fs-text-2xl); line-height: var(--fs-leading-2xl); letter-spacing: var(--fs-tracking-tighter); }
:where(h2) { font-size: var(--fs-text-lg); line-height: var(--fs-leading-lg); }
:where(h3) { font-size: var(--fs-text-md); line-height: var(--fs-leading-md); }
:where(h4, h5, h6) { font-size: var(--fs-text-base); line-height: var(--fs-leading-base); }

:where(p) {
  margin: 0 0 var(--fs-space-3);
  text-wrap: pretty;
}

:where(p:last-child) {
  margin-bottom: 0;
}

:where(a) {
  color: var(--fs-color-text-link);
  text-decoration: none;
  text-underline-offset: 0.18em;
  transition: color var(--fs-transition);
}

:where(a:hover) {
  color: var(--fs-color-accent-hover);
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

:where(strong, b) { font-weight: var(--fs-weight-semibold); }
:where(small) { font-size: var(--fs-text-xs); }

:where(code, kbd, samp, pre) {
  font-family: var(--fs-font-mono);
  font-size: 0.92em;
}

:where(code) {
  padding: 0.1em 0.35em;
  border-radius: var(--fs-radius-xs);
  background: var(--fs-color-surface-sunken);
  border: 1px solid var(--fs-color-border-subtle);
}

:where(pre) {
  margin: 0;
  padding: var(--fs-space-3) var(--fs-space-4);
  overflow: auto;
  border-radius: var(--fs-radius-md);
  background: var(--fs-color-surface-sunken);
  border: 1px solid var(--fs-color-border);
}

:where(pre code) {
  padding: 0;
  border: 0;
  background: none;
}

:where(hr) {
  height: 1px;
  margin: var(--fs-space-5) 0;
  border: 0;
  background: var(--fs-color-border);
}

:where(img, svg, video, canvas) {
  max-width: 100%;
}

:where(ul, ol) {
  padding-left: 1.25rem;
}

:where(table) {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

:where(th) {
  text-align: left;
  font-weight: var(--fs-weight-semibold);
}

:where(fieldset) {
  min-width: 0;
}

:where(legend) {
  padding: 0;
  font-weight: var(--fs-weight-semibold);
}

}

/* Figures, identifiers, amounts and timestamps. */
.fs-mono {
  font-family: var(--fs-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.94em;
  letter-spacing: -0.01em;
}

.fs-figure,
.fs-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "cv11";
}

@layer fs-base {

/* Focus */
:focus-visible {
  outline: 2px solid var(--fs-color-focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

h1:focus,
[tabindex="-1"]:focus {
  outline: none;
}

/* Native controls */
:where(button, input, select, textarea) {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
}

:where(button) {
  cursor: pointer;
}

:where(button:disabled) {
  cursor: not-allowed;
}

:where(input:not([type=checkbox], [type=radio], [type=file], [type=range], [type=color], [type=submit], [type=button], [type=reset], [type=image], [type=hidden])):not([class*="rz-"]),
:where(select):not([class*="rz-"]),
:where(textarea):not([class*="rz-"]) {
  min-height: var(--fs-control-h);
  padding: 0 var(--fs-space-3);
  border: 1px solid var(--fs-color-border-input);
  border-radius: var(--fs-radius-sm);
  background-color: var(--fs-color-surface);
  color: var(--fs-color-text-primary);
  font-size: var(--fs-text-base);
  line-height: var(--fs-leading-base);
  box-shadow: var(--fs-shadow-xs);
  transition: border-color var(--fs-transition), box-shadow var(--fs-transition), background-color var(--fs-transition);
}

:where(textarea):not([class*="rz-"]) {
  min-height: 88px;
  padding: var(--fs-space-2) var(--fs-space-3);
  resize: vertical;
}

:where(select):not([class*="rz-"], [multiple], [size]) {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23878f9e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 16px;
}

:where(input, select, textarea):not([class*="rz-"]):hover:not(:disabled, :focus) {
  border-color: var(--fs-color-border-strong);
}

:where(input, select, textarea):not([class*="rz-"], [type=checkbox], [type=radio], [type=file], [type=range]):focus {
  outline: none;
  border-color: var(--fs-color-accent);
  box-shadow: var(--fs-focus-ring);
}

:where(input, select, textarea):disabled {
  cursor: not-allowed;
  background-color: var(--fs-color-surface-sunken);
  color: var(--fs-color-text-disabled);
  box-shadow: none;
}

:where(input, select, textarea)[aria-invalid="true"] {
  border-color: var(--fs-color-danger-fg);
}

:where(input, select, textarea)[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--fs-color-danger-bg);
}

:where(input, textarea)::placeholder {
  color: var(--fs-color-text-tertiary);
  opacity: 0.85;
}

:where(input[type=checkbox], input[type=radio]) {
  width: 16px;
  height: 16px;
  margin: 0;
  vertical-align: -3px;
  accent-color: var(--fs-color-accent-solid);
  cursor: pointer;
}

:where(input[type=file]) {
  font-size: var(--fs-text-sm);
  color: var(--fs-color-text-secondary);
}

:where(input[type=file])::file-selector-button {
  height: var(--fs-control-h-sm);
  margin-right: var(--fs-space-3);
  padding: 0 var(--fs-space-3);
  border: 1px solid var(--fs-color-border-input);
  border-radius: var(--fs-radius-sm);
  background: var(--fs-color-surface);
  color: var(--fs-color-text-primary);
  font: inherit;
  font-weight: var(--fs-weight-medium);
  cursor: pointer;
}

:where(input[type=search])::-webkit-search-cancel-button {
  cursor: pointer;
}

}

/* CSS-only switch: <input type="checkbox" class="fs-switch" role="switch" />. */
.fs-switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  margin: 0;
  border-radius: var(--fs-radius-pill);
  background: var(--fs-color-border-strong);
  cursor: pointer;
  vertical-align: middle;
  transition: background-color var(--fs-transition-med);
}

.fs-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--fs-dur) var(--fs-ease-emphasised);
}

.fs-switch:checked {
  background: var(--fs-color-accent-solid);
}

.fs-switch:checked::after {
  transform: translateX(14px);
}

.fs-switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Authenticator QR — server-rendered inline SVG (QRCoder); stays black on white in both themes. */
.fs-qr {
  width: 190px;
  height: 190px;
  padding: var(--fs-space-2);
  background: #ffffff;
  border: 1px solid var(--fs-color-border);
  border-radius: var(--fs-radius-md);
}

.fs-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Screen-reader-only text. */
.fs-sr-only,
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Material Symbols (RadzenIcon) follow the text colour and size of their context. */
i.rzi,
.rz-icon {
  color: inherit;
}

/* Scrollbars: thin, quiet, theme-aware. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--fs-color-border-strong) transparent;
}

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