/* Webfor UI Design System V1 — global component and token contract. */
:root {
  color-scheme: light;
  --color-background: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-secondary: #f0f3f7;
  --color-surface-tertiary: #e7ecf2;
  --color-text: #17202e;
  --color-text-secondary: #5d6979;
  --color-text-disabled: #8b95a3;
  --color-border: #d8dee7;
  --color-border-strong: #bdc7d4;
  --color-primary: #1671d9;
  --color-primary-hover: #0d5fbe;
  --color-primary-active: #0a4f9e;
  --color-focus: rgba(22, 113, 217, .28);
  --color-success: #177a4b;
  --color-success-bg: #e9f7f0;
  --color-warning: #8a5a00;
  --color-warning-bg: #fff6dc;
  --color-danger: #b4233d;
  --color-danger-bg: #fff0f2;
  --color-info: #12649b;
  --color-info-bg: #eaf6ff;
  --color-on-dark: #f7fbff;
  --color-on-dark-secondary: #bdcbd9;
  --color-danger-on-dark: #ffb8c1;
  --color-danger-on-dark-strong: #ffd9de;
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-size-caption: .75rem;
  --font-size-label: .8125rem;
  --font-size-body: .9375rem;
  --font-size-card-title: 1.0625rem;
  --font-size-section-title: 1.25rem;
  --font-size-page-title: clamp(1.5rem, 2.1vw, 2rem);
  --font-size-kpi: clamp(1.75rem, 3vw, 2.5rem);
  --line-height-tight: 1.2;
  --line-height-body: 1.5;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --radius-control: 10px;
  --radius-card: 14px;
  --radius-modal: 18px;
  --radius-pill: 999px;
  --control-height: 42px;
  --page-max-width: 1600px;
  --shadow-card: 0 1px 2px rgba(17, 24, 39, .04), 0 8px 24px rgba(17, 24, 39, .06);
  --shadow-modal: 0 24px 70px rgba(17, 24, 39, .22);
  --motion-fast: 150ms;
  --motion-normal: 220ms;

  /* Compatibility aliases: new modules must use semantic names above. */
  --bg: var(--color-background);
  --page-bg: var(--color-background);
  --surface: var(--color-surface);
  --panel: var(--color-surface);
  --surface2: var(--color-surface-secondary);
  --panel-soft: var(--color-surface-secondary);
  --text: var(--color-text);
  --text-main: var(--color-text);
  --muted: var(--color-text-secondary);
  --text-muted: var(--color-text-secondary);
  --line: var(--color-border);
  --border: var(--color-border);
  --primary: var(--color-primary);
  --shadow: var(--shadow-card);
}

:root.theme-dark,
html.theme-dark {
  color-scheme: dark;
  --color-background: #0b111b;
  --color-surface: #131c29;
  --color-surface-secondary: #1a2636;
  --color-surface-tertiary: #223247;
  --color-text: #f2f5f9;
  --color-text-secondary: #b7c3d2;
  --color-text-disabled: #7d8da2;
  --color-border: #2d3d52;
  --color-border-strong: #405570;
  --color-primary: #68adf5;
  --color-primary-hover: #8ac2fa;
  --color-primary-active: #a6d1fb;
  --color-focus: rgba(104, 173, 245, .32);
  --color-success: #9be2be;
  --color-success-bg: #123226;
  --color-warning: #f1d078;
  --color-warning-bg: #382d13;
  --color-danger: #ffb3c0;
  --color-danger-bg: #3b1922;
  --color-info: #acd9ff;
  --color-info-bg: #102e47;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .24), 0 10px 28px rgba(0, 0, 0, .18);
  --shadow-modal: 0 26px 80px rgba(0, 0, 0, .5);
}

html { font-family: var(--font-system); font-size: 16px; text-rendering: optimizeLegibility; }
body { margin: 0; background: var(--color-background); color: var(--color-text); font-family: inherit; font-size: var(--font-size-body); line-height: var(--line-height-body); }
button, input, select, textarea { font: inherit; }
img, svg, video, canvas { max-width: 100%; }
a { color: var(--color-primary); text-underline-offset: .18em; }
a:hover { color: var(--color-primary-hover); }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }

:where(.main, main.main) { width: 100%; max-width: none; padding: var(--space-6) clamp(var(--space-4), 2.25vw, var(--space-8)) var(--space-12); }
:where(.main, main.main) > :where(.page, .page-shell, .content-shell, .module-page) { width: min(100%, var(--page-max-width)); margin-inline: auto; }
:where(.top, .page-head, .page-header, .section-head) { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin: 0 0 var(--space-6); }
:where(.top, .page-head, .page-header) h1,
:where(.top, .page-head, .page-header) h2 { margin: 0; color: var(--color-text); font-size: var(--font-size-page-title); font-weight: 700; letter-spacing: -.025em; line-height: var(--line-height-tight); }
:where(.top, .page-head, .page-header) p { max-width: 72ch; margin: var(--space-2) 0 0; color: var(--color-text-secondary); }
h2 { font-size: var(--font-size-section-title); letter-spacing: -.015em; }
h3 { font-size: var(--font-size-card-title); }

:where(.card, .panel, .box, .widget, .tile, [class$="-card"], [class$="-panel"]) { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
:where(.card, .panel, .box, .widget, .tile) { padding: var(--space-5); margin-bottom: var(--space-4); }
:where(.card, .panel) > :first-child { margin-top: 0; }
:where(.card, .panel) > :last-child { margin-bottom: 0; }
:where(.grid4, .kpi-grid, .stats-grid, .cards-grid) { gap: var(--space-4); }
:where(.kpi .label, .metric-label, .stat-label) { color: var(--color-text-secondary); font-size: var(--font-size-label); font-weight: 600; }
:where(.kpi .value, .metric-value, .stat-value, .kpi-value) { color: var(--color-text); font-size: var(--font-size-kpi); font-weight: 700; letter-spacing: -.035em; line-height: 1.1; }

:where(.btn, .button, button:not(.nav-group-toggle):not(.wf-theme-toggle)) { min-height: var(--control-height); padding: 0 var(--space-4); display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); border: 1px solid transparent; border-radius: var(--radius-control); background: var(--color-primary); color: #fff; font-size: var(--font-size-body); font-weight: 650; line-height: 1; cursor: pointer; transition: background-color var(--motion-fast), border-color var(--motion-fast), box-shadow var(--motion-fast), transform var(--motion-fast); }
:where(.btn, .button, button:not(.nav-group-toggle):not(.wf-theme-toggle)):hover { background: var(--color-primary-hover); color: #fff; }
:where(.btn, .button, button:not(.nav-group-toggle):not(.wf-theme-toggle)):active { background: var(--color-primary-active); transform: translateY(1px); }
:where(.btn.alt, .btn.secondary, .button.secondary, .btn-outline) { background: var(--color-surface-secondary); color: var(--color-text); border-color: var(--color-border-strong); }
:where(.btn.alt, .btn.secondary, .button.secondary, .btn-outline):hover { background: var(--color-surface-tertiary); color: var(--color-text); }
:where(.btn.ghost, .btn.tertiary, .button.ghost) { background: transparent; color: var(--color-primary); border-color: transparent; }
:where(.btn.ghost, .btn.tertiary, .button.ghost):hover { background: var(--color-surface-secondary); color: var(--color-primary-hover); }
:where(.btn.red, .btn.danger, .btn.destructive, .button.danger) { background: var(--color-danger); color: #fff; }
:where(.btn.green, .btn.success, .button.success) { background: var(--color-success); color: #fff; }
:where(.btn.icon, .btn-icon, .icon-button) { width: var(--control-height); padding: 0; }
:where(.btn, .button, button):disabled,
:where(.btn, .button, button)[aria-disabled="true"] { opacity: .52; cursor: not-allowed; pointer-events: none; transform: none; }

:where(.field, .form-group) { min-width: 0; }
:where(.field, .form-group) > label,
:where(form) > label { display: block; margin: 0 0 var(--space-2); color: var(--color-text); font-size: var(--font-size-label); font-weight: 650; }
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea, .form-control, .form-select) { width: 100%; min-height: var(--control-height); padding: 9px var(--space-3); border: 1px solid var(--color-border-strong); border-radius: var(--radius-control); background: var(--color-surface); color: var(--color-text); box-shadow: none; }
:where(textarea, textarea.form-control) { min-height: 96px; resize: vertical; }
:where(input, select, textarea)::placeholder { color: var(--color-text-disabled); opacity: 1; }
:where(input, select, textarea):hover { border-color: var(--color-text-disabled); }
:where(input, select, textarea):focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-focus); outline: none; }
:where(input, select, textarea):disabled,
:where(input, select, textarea)[readonly] { background: var(--color-surface-secondary); color: var(--color-text-disabled); cursor: not-allowed; }
html body[class][class] main input[type="checkbox"],
html body[class][class] main input[type="radio"] {
  inline-size: 18px !important;
  block-size: 18px !important;
  width: 18px !important;
  height: 18px !important;
  min-inline-size: 18px;
  max-inline-size: 18px;
  accent-color: var(--color-primary);
}

/* Profile labels may contain long synthetic or federated display names. */
html body[class][class] .logged-profile-text,
html body[class][class] .logged-profile-text > b {
  min-inline-size: 0;
  max-inline-size: 100%;
  white-space: normal !important;
  overflow-wrap: anywhere;
}
:where(.helper, .help-text, .form-text, .small, .muted, .caption) { color: var(--color-text-secondary); font-size: var(--font-size-caption); }
:where(.field-error, .invalid-feedback, [aria-invalid="true"] + .helper) { color: var(--color-danger); }
:where(input, select, textarea)[aria-invalid="true"] { border-color: var(--color-danger); }

:where(.table-wrap, .table-responsive, .responsive-table) { max-width: 100%; overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-card); background: var(--color-surface); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; color: var(--color-text); font-variant-numeric: tabular-nums; }
th, td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: middle; }
th { background: var(--color-surface-secondary); color: var(--color-text-secondary); font-size: var(--font-size-caption); font-weight: 700; letter-spacing: .025em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--color-primary) 5%, var(--color-surface)); }
td.actions, th.actions { text-align: right; white-space: nowrap; }

:where(.status, .badge, .status-badge, [class*="status-"]) { display: inline-flex; align-items: center; min-height: 24px; padding: 3px var(--space-2); border: 1px solid var(--color-border); border-radius: var(--radius-pill); background: var(--color-surface-secondary); color: var(--color-text-secondary); font-size: var(--font-size-caption); font-weight: 700; line-height: 1.25; white-space: nowrap; }
:where(.success, .ok, .s-approved, .badge.success, .status.success) { border-color: var(--color-success); background: var(--color-success-bg); color: var(--color-success); }
:where(.warning, .warn, .badge.warning, .status.warning) { border-color: var(--color-warning); background: var(--color-warning-bg); color: var(--color-warning); }
:where(.danger, .error, .err, .badge.danger, .status.danger) { border-color: var(--color-danger); background: var(--color-danger-bg); color: var(--color-danger); }
:where(.info, .badge.info, .status.info) { border-color: var(--color-info); background: var(--color-info-bg); color: var(--color-info); }
:where(.flash, .alert, .notice, .toast) { padding: var(--space-3) var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface-secondary); color: var(--color-text); }

:where(.modal, dialog, [role="dialog"]) { color: var(--color-text); }
:where(.modal-content, dialog, .dialog) { width: min(640px, calc(100vw - 32px)); max-height: min(86vh, 900px); overflow: auto; border: 1px solid var(--color-border); border-radius: var(--radius-modal); background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-modal); }
:where(.modal-header, .modal-body, .modal-footer) { padding: var(--space-5) var(--space-6); }
:where(.modal-header, .modal-footer) { border-color: var(--color-border); }
:where(.modal-footer) { display: flex; justify-content: flex-end; gap: var(--space-2); }
:where(.modal-backdrop, .overlay, dialog::backdrop) { background: rgba(3, 8, 16, .64); backdrop-filter: blur(2px); }

:where(.pagination, .pager) { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
:where(.pagination a, .pagination button, .pager a) { min-width: var(--control-height); min-height: var(--control-height); display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface); color: var(--color-text); }

.login-wrap, .login-fullscreen, .login-page { font-family: var(--font-system); }
.login-wrap .login, .login-center { border: 1px solid var(--color-border); border-radius: var(--radius-modal); background: color-mix(in srgb, var(--color-surface) 92%, transparent); color: var(--color-text); box-shadow: var(--shadow-modal); }

/* Authentication is an intrinsically dark surface, independent of app theme. */
.wf-auth-shell {
  --color-text: var(--color-on-dark);
  --color-text-secondary: var(--color-on-dark-secondary);
  color: var(--color-text);
}
.wf-auth-shell :where(.wf-brand strong, .wf-title h1, .wf-instructions-head strong, .wf-section-label) { color: var(--color-text); }
.wf-auth-shell :where(.wf-title p, .wf-secure, .wf-expiry, .wf-footer, .helper, .help-text) { color: var(--color-text-secondary); }
.wf-auth-shell :where(label, .wf-simple-field label, .wf-code-side label, .wf-trust) { color: var(--color-text); }
.wf-auth-shell .wf-alert { color: var(--color-danger-on-dark-strong); }
.wf-auth-shell .wf-alert strong { color: var(--color-danger-on-dark); }
.wf-auth-shell :where(a, .wf-link a, .wf-footer a) { color: #79baff; }
.wf-auth-shell :where(a, .wf-link a, .wf-footer a):hover { color: #acd6ff; }

/* Keep legacy full-width page sections inside the executive content gutter. */
body.wf-executive-v2 main.main > :not(.app-header):not(.top):not(.flash):not(.ai-float) {
  max-inline-size: calc(100% - 56px) !important;
  box-sizing: border-box;
}

/* Compatibility: legacy unification scripts must not turn content grids into toolbars. */
:where(.wiki-grid).wf-v3611-toolbar {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  min-width: 0;
}
:where(.wiki-grid) *, :where(.admin-panel-grid) *, :where(.admin-panel-card) * {
  min-width: 0;
  max-inline-size: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

@media (max-width: 1024px) {
  :where(.main, main.main) { padding-inline: var(--space-5); }
  :where(.grid4) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  :where(.wiki-grid).wf-v3611-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

@media (max-width: 600px) {
  :root { --control-height: 44px; }
  :where(.main, main.main) { padding: var(--space-4) var(--space-3) var(--space-10); }
  :where(.top, .page-head, .page-header, .section-head) { flex-direction: column; align-items: stretch; margin-bottom: var(--space-5); }
  :where(.top, .page-head, .page-header) > :where(.actions, .toolbar, a.btn, button.btn) { width: 100%; }
  :where(.grid4, .kpi-grid, .stats-grid, .cards-grid, .form, .form-grid) { grid-template-columns: minmax(0, 1fr); }
  :where(.wiki-grid).wf-v3611-toolbar { grid-template-columns: minmax(0, 1fr) !important; }
  :where(.card, .panel, .box, .widget, .tile) { padding: var(--space-4); border-radius: 12px; }
  :where(.actions, .toolbar, .filter-row) { width: 100%; align-items: stretch; }
  :where(.actions .btn, .toolbar .btn) { flex: 1 1 auto; }
  :where(.modal-header, .modal-body, .modal-footer) { padding: var(--space-4); }
  :where(.modal-footer) { flex-direction: column-reverse; }
  :where(.modal-footer .btn, .modal-footer button) { width: 100%; }
  th, td { padding: var(--space-3); }
}

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

@media (forced-colors: active) {
  :where(.btn, button, input, select, textarea, .card, .panel, .badge, .status) { border: 1px solid CanvasText; }
}
