/* The selected upstream distribution supplies Bootstrap/Tabler components.
   This bridge adapts Anabitas' existing, permission-aware markup to them.
   Navigation remains native details, and tables/galleries keep their own JS. */
:root,
:root[data-ui-theme="tabler"],
:root:has(body.ui-theme-tabler) {
  --anabitas-ink: var(--tblr-body-color, #182433);
  --anabitas-muted: var(--tblr-secondary, #667382);
  --anabitas-page: var(--tblr-body-bg, #f6f8fb);
  --anabitas-surface: var(--tblr-bg-surface, #fff);
  --anabitas-line: var(--tblr-border-color, #dce1e7);
  --anabitas-control: #a7b1bc;
  --anabitas-green: var(--tblr-primary, #206bc4);
  --anabitas-hover: #edf3fa;
  --anabitas-focus: #155caa;
  --ui-font: var(--tblr-font-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif);
  --ui-radius: var(--tblr-border-radius-lg, .5rem);
  --ui-control-radius: var(--tblr-border-radius, .375rem);
  --ui-shadow: var(--tblr-box-shadow-card, 0 1px 3px #1824330a);
  --ui-header-bg: #fff;
  --ui-header-color: #182433;
  --ui-sidebar-bg: #fff;
  --ui-sidebar-color: #3a4859;
  --ui-sidebar-muted: #667382;
  --ui-sidebar-line: #dce1e7;
  --ui-sidebar-hover: #f0f4fa;
  --ui-sidebar-active: #e6effb;
  --ui-sidebar-active-color: #155caa;
  --ui-table-header: #f6f8fb;
}
:root[data-ui-theme="adminlte"],
:root:has(body.ui-theme-adminlte) {
  --anabitas-ink: var(--bs-body-color, #212529);
  --anabitas-muted: #5c6670;
  --anabitas-page: #f4f6f9;
  --anabitas-surface: #fff;
  --anabitas-line: var(--bs-border-color, #dee2e6);
  --anabitas-control: #a0a9b2;
  /* Bootstrap's primary hover shade keeps links readable on the grey page. */
  --anabitas-green: #0b5ed7;
  --anabitas-hover: #eaf2ff;
  --anabitas-focus: #0759c7;
  --ui-font: var(--bs-font-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif);
  --ui-radius: var(--bs-border-radius, .375rem);
  --ui-control-radius: var(--bs-border-radius, .375rem);
  --ui-shadow: 0 0 1px #0002, 0 1px 3px #0003;
  --ui-header-bg: #0d6efd;
  --ui-header-color: #fff;
  --ui-sidebar-bg: #343a40;
  --ui-sidebar-color: #e0e4e8;
  --ui-sidebar-muted: #c0c7ce;
  --ui-sidebar-line: #535c66;
  --ui-sidebar-hover: #454d55;
  --ui-sidebar-active: #0d6efd;
  --ui-sidebar-active-color: #fff;
  --ui-table-header: #edf0f3;
}
html { color-scheme: light; }
body, body.portal-page {
  color: var(--anabitas-ink);
  background: var(--anabitas-page);
  font-family: var(--ui-font);
}
body :where(button, input, select, textarea) { font-family: inherit; }
/* Bootstrap floats legends by default; existing grid fieldsets use native
   legends so their labels remain attached to the group in narrow layouts. */
body fieldset > legend { float: none; width: auto; }
body :where(button, .button, .nav-button, input:not([type="checkbox"]):not([type="radio"]), select, textarea) { border-radius: var(--ui-control-radius); }
body :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) {
  color: var(--anabitas-ink);
  background-color: var(--anabitas-surface);
  border: 1px solid var(--anabitas-control);
  max-width: 100%;
  min-width: 0;
  padding: .625rem .75rem;
  box-sizing: border-box;
  line-height: 1.5;
}
body :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select) { min-height: 44px; }
body :where(input, select, textarea):disabled { background-color: var(--ui-table-header); opacity: 1; }
body :where(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--anabitas-focus);
  outline-offset: 3px;
}
body .btn, body .button, body .nav-button { min-height: 44px; }
body .btn:disabled { cursor: not-allowed; }
body.portal-page .primary, body.portal-page .button.primary,
body .personal-profile-form > button, body.portal-page .invitation-form button,
body:not(.portal-page) > main :where(button[type="submit"], .nav-button:not(.secondary)),
body .portal-header .portal-login-action {
  background: var(--anabitas-green);
  border-color: var(--anabitas-green);
  color: #fff;
}
body.portal-page .primary:hover:not(:disabled), body.portal-page .button.primary:hover,
body .personal-profile-form > button:hover, body.portal-page .invitation-form button:hover,
body .portal-header .portal-login-action:hover {
  background: color-mix(in srgb, var(--anabitas-green) 85%, #000);
  border-color: color-mix(in srgb, var(--anabitas-green) 85%, #000);
  color: #fff;
}
/* Create and danger retain the shared action semantics in both distributions. */
body.portal-page .create-action, body.portal-page .button.create-action {
  background: var(--anabitas-create);
  border-color: var(--anabitas-create);
  color: #fff;
}
body.portal-page .danger, body.portal-page .button.danger { background: #b42332; border-color: #b42332; color: #fff; }
body.portal-page .danger-outline, body.portal-page .button.danger-outline { background: #fff; border-color: #a92032; color: #a92032; }

/* Real navbar components share the same application identity and routes. */
body .portal-header.navbar, body .public-header.navbar {
  --tblr-navbar-bg: var(--ui-header-bg);
  --tblr-navbar-color: var(--ui-header-color);
  --bs-navbar-color: var(--ui-header-color);
  grid-area: auto;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px 24px;
  min-height: 72px;
  padding: 16px clamp(20px, 3vw, 48px);
  background: var(--ui-header-bg);
  color: var(--ui-header-color);
  border-block-end: 1px solid var(--anabitas-line);
  box-shadow: 0 1px 2px #18243305;
}
body .portal-header.navbar .brand, body .public-header.navbar .brand {
  color: var(--ui-header-color);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  text-decoration: none;
}
body .portal-header.navbar .brand span, body .public-header.navbar .brand span {
  color: inherit;
  display: block;
  margin-block-start: 5px;
  font-size: 10px;
  line-height: 1.5;
  font-weight: 500;
  letter-spacing: .09em;
  text-transform: uppercase;
}
body .portal-header.navbar .portal-account-links { color: var(--ui-header-color); }
body .portal-header.navbar .portal-menu > summary { border-radius: var(--ui-control-radius); }
body .portal-menu-panel { border-radius: var(--ui-radius); }

/* Sidebar components are adapted to the existing responsive details shell.
   Unlike the vendor demo shells they do not require a copied app-wrapper. */
body .portal-native-navigation, body .explorer-sidebar {
  --explorer-ink: var(--ui-sidebar-color);
  --explorer-muted: var(--ui-sidebar-muted);
  --explorer-paper: var(--ui-sidebar-bg);
  --explorer-line: var(--ui-sidebar-line);
  color: var(--ui-sidebar-color);
  background: var(--ui-sidebar-bg);
  border: 1px solid var(--ui-sidebar-line);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
}
body .portal-native-navigation.app-sidebar, body .explorer-sidebar.app-sidebar {
  --lte-sidebar-color: var(--ui-sidebar-color);
  --lte-sidebar-hover-color: var(--ui-sidebar-color);
  --lte-sidebar-hover-bg: var(--ui-sidebar-hover);
  --lte-sidebar-menu-active-bg: var(--ui-sidebar-active);
  --lte-sidebar-menu-active-color: var(--ui-sidebar-active-color);
  display: block;
  position: relative;
  inset: auto;
  width: auto;
  min-width: 0;
  max-width: none;
  margin-inline: 0;
  transform: none;
  translate: none;
  transition: none;
  grid-area: auto;
  overflow: visible;
}
body .portal-native-navigation > summary, body .explorer-navigation > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 14px 16px;
  color: var(--ui-sidebar-color);
  border-block-end: 1px solid transparent;
  font-size: .9rem;
  font-weight: 650;
  list-style: none;
}
body .portal-native-navigation > summary::-webkit-details-marker { display: none; }
body .portal-native-navigation > summary::after { content: "+"; font-size: 1.15rem; }
body .portal-native-navigation[open] > summary::after { content: "−"; }
body .portal-native-navigation[open] > summary, body .explorer-navigation[open] > summary { border-block-end-color: var(--ui-sidebar-line); margin-block-end: 8px; }
body .portal-native-navigation-panel.sidebar-wrapper { padding: 0 12px 14px; }
body .portal-native-tree a, body .explorer-tree-fallback a {
  min-height: 44px;
  color: var(--ui-sidebar-color);
  border-radius: var(--ui-control-radius);
  padding: 10px;
  line-height: 1.4;
}
body .portal-native-tree a:hover, body .explorer-tree-fallback a:hover { background: var(--ui-sidebar-hover); color: var(--ui-sidebar-color); }
body .portal-native-tree a[aria-current="page"], body .explorer-tree-fallback a[aria-current="page"] {
  color: var(--ui-sidebar-active-color);
  background: var(--ui-sidebar-active);
  font-weight: 650;
}
body .portal-explorer-return { display: flex; align-items: center; min-height: 44px; color: var(--ui-sidebar-color); }
body .portal-tree-controls, body .explorer-workspaces { border-color: var(--ui-sidebar-line); }
body .portal-tree-user, body .portal-tree-language > span,
body .explorer-workspaces > summary, body .explorer-workspace-current,
body .explorer-tree-hint { color: var(--ui-sidebar-muted); }
body .portal-tree-controls :where(a,button,input,summary):focus-visible,
body .explorer-sidebar :where(a,button,input,summary):focus-visible { outline-color: #70b5ff; }
body #explorer-tree {
  --wb-node-text-color: var(--ui-sidebar-color);
  --wb-background-color: var(--ui-sidebar-bg);
  --wb-hover-color: var(--ui-sidebar-hover);
  --wb-active-color: var(--ui-sidebar-active);
  --wb-active-hover-color: var(--ui-sidebar-active);
  --wb-active-border-color: transparent;
  --wb-active-color-grayscale: var(--ui-sidebar-active);
  --wb-active-hover-color-grayscale: var(--ui-sidebar-active);
  --wb-active-border-color-grayscale: transparent;
}
body #explorer-tree .wb-row.wb-active { color: var(--ui-sidebar-active-color); }
body #explorer-tree .xpl-icon { color: var(--ui-sidebar-muted); }
body #explorer-tree .wb-row.wb-active .xpl-icon { color: var(--ui-sidebar-active-color); }
body #explorer-tree .xpl-folder::before, body #explorer-tree .xpl-folder::after,
body #explorer-tree .xpl-file::before { background: var(--ui-sidebar-bg); }

/* Existing cards, editors and reports use each distribution's surfaces. */
body.portal-page :is(.profile-option, .module-shortcuts a, .personal-profile-form,
  .record-panel, .portal-dashboard .card, .property-address-card, .property-metric,
  .property-notes, .property-detail-card, .system-status-card, .users-panel,
  .users-filters, .bank-panel, .bank-filters, .invitation-card, .area-explorer-card),
body:not(.portal-page) > main {
  border-color: var(--anabitas-line);
  border-radius: var(--ui-radius);
  background: var(--anabitas-surface);
  box-shadow: var(--ui-shadow);
}
body .explorer-content { border-radius: 0 0 var(--ui-radius) var(--ui-radius); }
body .explorer-breadcrumbs { border-radius: var(--ui-radius) var(--ui-radius) 0 0; }
body .explorer-breadcrumbs, body .explorer-content { box-shadow: var(--ui-shadow); }
body.portal-page .portal-dashboard .card { padding: 24px; }
body.portal-page .portal-dashboard .service-icon { border-radius: var(--ui-radius); }
body.portal-page .portal-dashboard .service-arrow { color: var(--anabitas-green); background: var(--anabitas-hover); }
body.portal-page .portal-dashboard .workspace-choice { color: var(--anabitas-green); border-color: var(--anabitas-control); border-radius: var(--ui-control-radius); }
body.portal-page .portal-dashboard .workspace-choice:hover { background: var(--anabitas-hover); }
body.portal-page .portal-dashboard .workspace-choice.is-selected { color: #fff; background: var(--anabitas-green); border-color: var(--anabitas-green); }
body.portal-page .portal-dashboard .workspace-current.has-selection .workspace-dot { background: var(--anabitas-green); }
body .global-settings-form { max-width: 720px; padding: 24px; }
body .global-settings-form > p { display: grid; gap: 8px; margin: 0 0 24px; }
body .global-settings-form label { font-size: .9rem; font-weight: 600; }
body .global-settings-form select { width: 100%; }
body .global-settings-form .helptext { color: var(--anabitas-muted); font-size: .875rem; line-height: 1.6; }
body .global-settings-form > button { align-self: flex-start; }
body .administration-home { --administration-ink: var(--anabitas-ink); --administration-muted: var(--anabitas-muted); --administration-green: var(--anabitas-green); --administration-line: var(--anabitas-line); }
body .administration-card__icon { color: var(--anabitas-green); background: var(--anabitas-hover); border-radius: var(--ui-radius); }
body .administration-grid .administration-card { border-radius: var(--ui-radius); box-shadow: var(--ui-shadow); }
body .area-explorer-icon { background: var(--anabitas-hover); color: var(--anabitas-green); }
body .followup-workbench { --followup-panel-line: var(--anabitas-line); --followup-panel-tint: var(--anabitas-hover); --followup-panel-accent: var(--anabitas-green); border-radius: var(--ui-radius); }
body :is(.portal-child-nav, .property-section-nav, .access-tabs, .bank-nav) { border-color: var(--anabitas-line); }
body :is(.portal-child-nav, .property-section-nav, .access-tabs, .bank-nav) a[aria-current="page"] { color: var(--anabitas-green); border-block-end-color: var(--anabitas-green); }
/* Do not recolour business rows: overdue, editing and last-created states stay. */
body.portal-page :is(.explorer-table, .property-table, .users-table, .bank-table, .help-manager__table) th,
body.portal-page .tabulator .tabulator-header,
body.portal-page .tabulator .tabulator-header .tabulator-col { background: var(--ui-table-header); color: var(--anabitas-muted); border-color: var(--anabitas-line); }
body .explorer-table.table { --bs-table-bg: transparent; --tblr-table-bg: transparent; color: var(--anabitas-ink); }
body .explorer-table.table > :not(caption) > * > * { color: inherit; background: transparent; box-shadow: none; }
body .explorer-table.table > thead > * > * { color: var(--anabitas-muted); background: var(--ui-table-header); }

/* AdminLTE's recognisable blue masthead and charcoal sidebar accompany its
   boxed cards and compact content spacing, on public/authenticated pages. */
html[data-ui-theme="adminlte"] body .portal-header.navbar,
html[data-ui-theme="adminlte"] body .public-header.navbar,
body.ui-theme-adminlte .portal-header.navbar { border-block-end-color: #0b5ed7; box-shadow: 0 2px 5px #0002; }
html[data-ui-theme="adminlte"] body .portal-header.navbar .portal-menu > summary,
body.ui-theme-adminlte .portal-header.navbar .portal-menu > summary { background: #fff1; color: #fff; border-color: #ffffff80; }
html[data-ui-theme="adminlte"] body :is(.portal-header,.public-header).navbar > nav > a:focus-visible,
html[data-ui-theme="adminlte"] body .portal-header.navbar .portal-menu > summary:focus-visible,
html[data-ui-theme="adminlte"] body :is(.portal-header,.public-header).navbar > a:focus-visible,
body.ui-theme-adminlte .portal-header.navbar > a:focus-visible { outline-color: #fff; }
html[data-ui-theme="adminlte"] body .portal-header.navbar .portal-login-action,
html[data-ui-theme="adminlte"] body .public-header.navbar .portal-login-action,
body.ui-theme-adminlte .portal-header.navbar .portal-login-action { color: #0a58ca; background: #fff; border-color: #fff; }
html[data-ui-theme="adminlte"] .public-header.navbar :is(.public-tools-link,.public-register-action) { color: #fff; }
html[data-ui-theme="adminlte"] .public-header.navbar .public-register-action { background: #0b5ed7; border-color: #ffffff80; }
html[data-ui-theme="adminlte"] body.portal-page :is(.record-panel,.portal-dashboard .card,.users-panel,.bank-panel,.area-explorer-card),
html[data-ui-theme="adminlte"] body:not(.portal-page) > main,
body.ui-theme-adminlte #content-main > .module { border-block-start: 3px solid var(--anabitas-green); }
html[data-ui-theme="adminlte"] body.portal-page .portal-dashboard .card { border-radius: .25rem; }
html[data-ui-theme="adminlte"] body.portal-page .portal-dashboard .card h2 { font-size: 1.25rem; font-weight: 500; }
html[data-ui-theme="adminlte"] body .portal-tree-logout button { color: #ffd4d9; background: transparent; border-color: #c09ca2; }
html[data-ui-theme="adminlte"] body .portal-tree-logout button:hover { background: #512f35; }
html[data-ui-theme="adminlte"] body .explorer-workspace-options button { background: #454d55; color: #fff; border-color: #707b85; }
html[data-ui-theme="adminlte"] body .explorer-workspace-options button.is-selected { background: #0d6efd; border-color: #7bb1ff; }
html[data-ui-theme="adminlte"] body .portal-native-navigation :where(a,summary):focus-visible,
html[data-ui-theme="adminlte"] body .explorer-sidebar :where(a,summary):focus-visible { outline-color: #96c6ff; }
html[data-ui-theme="adminlte"] .public-home { --public-green: #0d6efd; --public-ink: #212529; --public-muted: #5c6670; }
html[data-ui-theme="tabler"] .public-home { --public-green: #206bc4; --public-ink: #182433; --public-muted: #667382; }
body.public-home .button { border-radius: var(--ui-control-radius); }
body.public-home .button:hover { background: var(--anabitas-focus); border-color: var(--anabitas-focus); }
body.public-home .public-header .portal-login-action { background: var(--anabitas-green); border-color: var(--anabitas-green); color: #fff; }
body.public-home .public-header .public-register-action { color: var(--anabitas-green); border-color: var(--anabitas-control); }

/* Django admin has no html attribute block. Its bodyclass is server-rendered;
   :has above resolves the same theme tokens without a post-paint script. */
body[class*="ui-theme-"] {
  --primary: var(--anabitas-green); --secondary: var(--ui-table-header); --accent: var(--anabitas-green);
  --body-fg: var(--anabitas-ink); --body-bg: var(--anabitas-page); --body-quiet-color: var(--anabitas-muted); --body-loud-color: var(--anabitas-ink);
  --header-color: var(--ui-header-color); --header-branding-color: var(--ui-header-color); --header-bg: var(--ui-header-bg); --header-link-color: var(--ui-header-color);
  --breadcrumbs-fg: var(--anabitas-muted); --breadcrumbs-link-fg: var(--anabitas-green); --breadcrumbs-bg: var(--ui-table-header);
  --link-fg: var(--anabitas-green); --link-hover-color: var(--anabitas-focus); --link-selected-fg: var(--anabitas-focus);
  --hairline-color: var(--anabitas-line); --border-color: var(--anabitas-line); --darkened-bg: var(--ui-table-header); --selected-bg: var(--anabitas-hover);
  --button-bg: var(--anabitas-green); --button-hover-bg: var(--anabitas-focus); --default-button-bg: var(--anabitas-green); --default-button-hover-bg: var(--anabitas-focus);
}
body[class*="ui-theme-"] #header { background: var(--ui-header-bg); color: var(--ui-header-color); }
body[class*="ui-theme-"] #header .portal-header .brand { color: var(--ui-header-color); }
body[class*="ui-theme-"] :is(.module h2,.module caption,.inline-group h2) { background: var(--ui-table-header); color: var(--anabitas-ink); }
body[class*="ui-theme-"] #nav-sidebar { background: var(--ui-sidebar-bg); color: var(--ui-sidebar-color); border-color: var(--ui-sidebar-line); }
body[class*="ui-theme-"] #nav-sidebar a { color: var(--ui-sidebar-color); }
body[class*="ui-theme-"] #nav-sidebar :is(caption,.current-model) { background: var(--ui-sidebar-active); color: var(--ui-sidebar-active-color); }
body[class*="ui-theme-"] #nav-sidebar caption a { color: var(--ui-sidebar-active-color); }
body[class*="ui-theme-"] .main { min-width: 0; }
body[class*="ui-theme-"] #content { min-width: 0; }

@media (min-width: 1000px) {
  body.portal-page > .portal-native-navigation.app-sidebar[data-portal-management-navigation] { position: sticky; top: 20px; width: 100%; margin: 28px 0 0; max-width: 280px; }
}
@media (min-width: 801px) {
  body .explorer-sidebar.app-sidebar { position: sticky; top: 16px; }
}
@media (max-width: 999px) {
  body.portal-page > .portal-native-navigation.app-sidebar { width: calc(100% - 32px); margin: 16px auto 0; }
}
@media (max-width: 800px) {
  body .explorer-sidebar.app-sidebar { position: static; margin-block-end: 16px; }
}
@media (max-width: 600px) {
  body .portal-header.navbar, body .public-header.navbar { padding: 14px 16px; gap: 12px; }
  body .portal-header.navbar .brand { max-width: calc(100% - 100px); font-size: 26px; }
  body .public-header.navbar .brand { max-width: 100%; }
  body .public-header.navbar nav { margin: 0; width: 100%; flex-wrap: wrap; }
  body .portal-header.navbar .portal-account-links { width: auto; }
  body .portal-menu-panel { max-height: calc(100dvh - 130px); }
  body.portal-page .portal-dashboard .card { padding: 20px; }
  body .explorer-actions .btn { white-space: normal; }
}
@media print {
  body .portal-header.navbar, body .public-header.navbar { color: #000; background: #fff; box-shadow: none; }
  body .portal-native-navigation, body .explorer-sidebar { display: none; }
}
