:root {
  --primary: var(--ui-color-primary) !important;
  --primary-dark: var(--ui-color-primary-strong) !important;
  --teal: var(--ui-color-primary) !important;
  --dark: var(--ui-color-primary-strong) !important;
  --dark-2: var(--ui-color-primary-deep) !important;
  --blue: var(--ui-color-accent) !important;
  --accent: var(--ui-color-accent) !important;
  --navy: var(--ui-color-primary-deep) !important;
  --ink: var(--ui-color-text) !important;
  --text: var(--ui-color-text) !important;
  --muted: var(--ui-color-muted) !important;
  --line: var(--ui-color-line) !important;
  --border: var(--ui-color-line) !important;
  --soft: var(--ui-color-surface-soft) !important;
  --danger: var(--ui-color-danger) !important;
  --bad: var(--ui-color-danger) !important;
  --success: var(--ui-color-success) !important;
  --ok: var(--ui-color-success) !important;
}

html,
body {
  color: var(--ui-color-text) !important;
  font-family: var(--ui-font-family) !important;
  background: var(--ui-page-background) !important;
}

body::before,
body::after {
  pointer-events: none;
}

:where(button, input, select, textarea, a) {
  font-family: inherit;
}

:where(
  .header,
  .app-header,
  .contract-header,
  .invoice-header,
  .page-header,
  .main-header,
  .top,
  .title-bar,
  .workspace-header,
  .settings-header
) {
  color: #fff !important;
  background: var(--ui-gradient-brand) !important;
  border-color: transparent !important;
  box-shadow: var(--ui-shadow-header) !important;
}

:where(
  .topbar,
  .toolbar,
  .nav-bar,
  .navigation,
  .tabs,
  .tab-bar,
  .back-row
) {
  border-color: var(--ui-color-line) !important;
  background: color-mix(in srgb, var(--ui-color-surface) 94%, var(--ui-color-primary) 6%) !important;
  box-shadow: var(--ui-shadow-soft) !important;
}

:where(
  button,
  .btn,
  .button,
  .back,
  .back-btn,
  .primary-btn,
  .action-btn,
  .submit-btn,
  .filter-btn,
  .top-link a,
  a.btn
) {
  min-height: var(--ui-control-height) !important;
  border: 1px solid transparent !important;
  border-radius: var(--ui-radius-sm) !important;
  background: var(--ui-gradient-brand) !important;
  color: #fff !important;
  box-shadow: var(--ui-shadow-control) !important;
  font-weight: 800 !important;
  text-decoration: none !important;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease !important;
}

:where(button, .btn, .button, .back, .back-btn, .action-btn):not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: var(--ui-shadow-control-hover) !important;
}

:where(button, .btn, .button):disabled {
  cursor: not-allowed !important;
  opacity: .48 !important;
}

.ui-inline-form {
  display: inline-flex !important;
  margin: 0 !important;
}

.ui-is-hidden {
  display: none !important;
}

.ui-state-active {
  background: var(--ui-color-primary) !important;
}

.ui-state-muted {
  background: var(--ui-color-muted) !important;
}

.ui-zero-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--ui-color-danger-soft);
  color: var(--ui-color-danger);
  font-weight: 900;
}

.ui-pagination-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--ui-color-line);
  border-radius: var(--ui-radius-sm);
  background: var(--ui-color-surface);
  color: var(--ui-color-primary-strong);
  text-decoration: none;
  font-weight: 800;
}

.ui-pagination-link.is-current {
  border-color: transparent;
  background: var(--ui-gradient-brand);
  color: #fff;
}

:where(.danger, .danger-btn, .delete-btn, .btn-danger, button[name="delete"], [data-action="delete"]) {
  background: var(--ui-color-danger) !important;
  color: #fff !important;
}

:where(.secondary, .secondary-btn, .light, .btn-light, .cancel-btn) {
  border-color: var(--ui-color-line) !important;
  background: var(--ui-color-surface) !important;
  color: var(--ui-color-primary-strong) !important;
  box-shadow: none !important;
}

:where(input, select, textarea, .form-control, .ui-control) {
  min-width: 0;
  border: 1px solid var(--ui-color-line) !important;
  border-radius: var(--ui-radius-sm) !important;
  outline: 0 !important;
  background: var(--ui-color-surface) !important;
  color: var(--ui-color-text) !important;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, .025) !important;
}

:where(input, select, textarea, .form-control, .ui-control):focus {
  border-color: var(--ui-color-accent) !important;
  box-shadow: 0 0 0 3px var(--ui-color-focus) !important;
}

:where(label, .label, .field-label) {
  color: var(--ui-color-primary-strong) !important;
  font-weight: 800 !important;
}

:where(.hero, .brand-hero, .login-hero) :where(h1, h2, p) {
  color: #fff !important;
}

:where(
  .card,
  .panel,
  .box,
  .section,
  .form-box,
  .filter-box,
  .summary-box,
  .stat-card,
  .settings-entry-card,
  .report-card,
  .entry-card,
  .modal-content
) {
  border: 1px solid var(--ui-color-line) !important;
  border-radius: var(--ui-radius-lg) !important;
  background: var(--ui-color-surface) !important;
  box-shadow: var(--ui-shadow-soft) !important;
}

:where(.notice, .alert, .message, .status-message) {
  border: 1px solid var(--ui-color-line) !important;
  border-radius: var(--ui-radius-md) !important;
  background: var(--ui-color-info-soft) !important;
  color: var(--ui-color-primary-strong) !important;
}

:where(.notice.error, .alert.error, .message.error, .error-message) {
  border-color: var(--ui-color-danger-line) !important;
  background: var(--ui-color-danger-soft) !important;
  color: var(--ui-color-danger) !important;
}

:where(.notice.success, .alert.success, .message.success, .success-message) {
  border-color: var(--ui-color-success-line) !important;
  background: var(--ui-color-success-soft) !important;
  color: var(--ui-color-success) !important;
}

:where(table) {
  border: 1px solid var(--ui-color-table-line) !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  background: var(--ui-color-surface) !important;
}

:where(thead, thead tr, table > tr:first-child) {
  background: var(--ui-color-primary-strong) !important;
  color: #fff !important;
}

:where(th) {
  border-color: var(--ui-color-table-line) !important;
  background: var(--ui-color-primary-strong) !important;
  color: #fff !important;
  font-weight: 900 !important;
}

:where(td) {
  border-color: var(--ui-color-table-line) !important;
  background: var(--ui-color-surface) !important;
  color: var(--ui-color-text) !important;
}

:where(tbody tr:nth-child(even) td) {
  background: var(--ui-color-row-alt) !important;
}

:where(tbody tr:hover td) {
  background: var(--ui-color-row-hover) !important;
}

:where(.modal, .dialog-overlay, .overlay) {
  background: rgba(15, 23, 42, .48) !important;
  backdrop-filter: blur(4px);
}

:where(.modal-content, dialog) {
  border: 1px solid var(--ui-color-line) !important;
  border-radius: var(--ui-radius-xl) !important;
  background: var(--ui-color-surface) !important;
  box-shadow: var(--ui-shadow-modal) !important;
}

:where(.tabs button, .tab, .tab-btn, [role="tab"]) {
  border: 1px solid var(--ui-color-line) !important;
  background: var(--ui-color-surface) !important;
  color: var(--ui-color-primary-strong) !important;
  box-shadow: none !important;
}

:where(.tabs button.active, .tab.active, .tab-btn.active, [role="tab"][aria-selected="true"]) {
  border-color: transparent !important;
  background: var(--ui-gradient-brand) !important;
  color: #fff !important;
}

/* Central compatibility for semantic controls retained by the PHP views. */
:where(.user-badge, .user-meta) {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  min-width: 0 !important;
}

:where(.user-badge-icon, .user-icon) {
  flex: 0 0 auto !important;
  width: 40px !important;
  height: 40px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: 1px solid rgba(255, 255, 255, .24) !important;
  border-radius: 12px !important;
  background: var(--ui-gradient-brand) !important;
  color: #fff !important;
  box-shadow: var(--ui-shadow-control) !important;
  font-weight: 900 !important;
  line-height: 1 !important;
}

:where(.user-badge-text) {
  min-width: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  flex-wrap: wrap !important;
}

:where(.user-badge-label) {
  color: var(--ui-color-muted) !important;
  font-size: 11px !important;
  font-weight: 700 !important;
}

:where(.user-badge-name) {
  color: var(--ui-color-text) !important;
  font-weight: 900 !important;
}

:where(.user-badge-role, .role-chip, .role-pill) {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 28px !important;
  padding: 4px 10px !important;
  border: 1px solid var(--ui-color-line) !important;
  border-radius: 999px !important;
  background: var(--ui-color-surface-soft) !important;
  color: var(--ui-color-primary-strong) !important;
  font-size: 11px !important;
  font-weight: 900 !important;
  white-space: nowrap !important;
}

:where(.logout, .logout-link)::before {
  content: "↗" !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 18px !important;
  height: 18px !important;
  margin-inline-end: 6px !important;
  color: currentColor !important;
  font-weight: 900 !important;
}

:where(a, button):is(
  .edit, .edit-btn, .action-edit, .archive, .print, .btn-print,
  .download, .btn-download, .action-link, .action-view,
  .action-download, .open-action, .print-action, .export-action,
  .statement-btn, .match-btn, .contract-view-button,
  .archive-owner-button, .edit-owner-button
) {
  min-height: var(--ui-control-height) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  padding: 6px 11px !important;
  border: 1px solid transparent !important;
  border-radius: var(--ui-radius-sm) !important;
  background: var(--ui-gradient-brand) !important;
  color: #fff !important;
  box-shadow: var(--ui-shadow-control) !important;
  font-weight: 800 !important;
  line-height: 1.2 !important;
  text-decoration: none !important;
}

:where(button, a):is(
  .delete, .delete-btn, .btn-delete, .action-delete,
  .delete-action, .chip-delete, .remove-item
) {
  border-color: transparent !important;
  background: var(--ui-color-danger) !important;
  color: #fff !important;
  box-shadow: var(--ui-shadow-control) !important;
  text-decoration: none !important;
}

body.project-workspace-page :where(.hero) {
  border: 1px solid color-mix(in srgb, var(--ui-color-accent) 38%, transparent) !important;
  border-radius: var(--ui-radius-xl) !important;
  background: var(--ui-gradient-brand) !important;
  color: #fff !important;
  box-shadow: var(--ui-shadow-soft) !important;
}

body.project-workspace-page :where(.hero-number) {
  color: #fff !important;
  font-size: clamp(32px, 4vw, 48px) !important;
  font-weight: 950 !important;
  line-height: 1 !important;
}

/* A wide record must scroll inside its viewport, never be clipped. */
body.project-workspace-page :where(
  .table-wrap, .table-scroll, .table-container, .table-responsive,
  .report-table-wrap, .directory-table, .expiry-table-wrap,
  .owners-table-wrap, .activity-table-wrap
) {
  max-width: 100% !important;
  overflow-x: auto !important;
  overscroll-behavior-x: contain !important;
}

@media print {
  .no-print,
  [data-ui-no-print] {
    display: none !important;
  }
}
