html {
  position: relative;
  min-height: 100%;
  font-size: 14px;
  background: var(--hb-bg);
}

@media (min-width: 768px) {
  html { font-size: 16px; }
}

body.app-body {
  min-height: 100vh;
  margin: 0;
  background: var(--hb-bg);
  color: var(--hb-text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--bs-link-color);
  text-underline-offset: .16em;
}

a:hover { color: var(--bs-link-hover-color); }

.app-icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.app-shell { min-height: 100vh; }

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  width: var(--hb-sidebar-width);
  padding: var(--hb-space-3);
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--hb-sidebar);
  border-inline-end: 1px solid var(--hb-border);
}

.app-sidebar-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 60px;
  padding: var(--hb-space-2) var(--hb-space-3) var(--hb-space-3);
  border-block-end: 1px solid var(--hb-border);
  color: var(--hb-sidebar-text);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: var(--hb-line-tight);
  overflow-wrap: anywhere;
  text-decoration: none;
}

.app-sidebar-brand:hover { color: var(--hb-sidebar-text); }
.app-sidebar-dismiss { position: absolute; inset: var(--hb-space-3) var(--hb-space-3) auto auto; }
.app-sidebar:has(.app-sidebar-dismiss) .app-sidebar-brand { padding-inline-end: calc(var(--hb-target) + var(--hb-space-2)); }
@media (min-width: 992px) {
  .app-sidebar:has(.app-sidebar-dismiss) .app-sidebar-brand { padding-inline-end: var(--hb-space-3); }
}
.app-sidebar-brand small { margin-block-start: var(--hb-space-1); color: var(--hb-sidebar-muted); font-size: var(--hb-small-size); font-weight: 500; }

.app-nav { display: grid; gap: var(--hb-space-4); padding: var(--hb-space-3) 0; }
.app-nav-group h2 {
  margin: 0;
  padding: var(--hb-space-1) var(--hb-space-3);
  color: var(--hb-sidebar-muted);
  font-size: var(--hb-label-size);
  font-weight: 630;
  line-height: var(--hb-line-tight);
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: var(--hb-space-3);
  min-height: var(--hb-target);
  padding: var(--hb-space-2) var(--hb-space-3);
  border-inline-start: 2px solid transparent;
  border-radius: var(--hb-radius-sm);
  color: var(--hb-text-soft);
  font-size: var(--hb-small-size);
  font-weight: 560;
  line-height: var(--hb-line-tight);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.app-nav-link:hover { color: var(--hb-text); background: var(--hb-surface-2); }
.app-nav-link.is-active { color: var(--hb-accent); background: var(--hb-primary-soft); border-inline-start-color: var(--hb-accent); font-weight: 680; }

.app-nav-icon {
  width: 1.3rem;
  height: 1.3rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-avatar {
  display: inline-grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 50%;
  color: var(--hb-accent);
  background: var(--hb-primary-soft);
  font-size: var(--hb-small-size);
  font-weight: 700;
}

.app-skip-link {
  position: fixed;
  inset: var(--hb-space-2) auto auto var(--hb-space-2);
  z-index: 1050;
  padding: var(--hb-space-3);
  background: var(--hb-surface);
  transform: translateY(-150%);
}
.app-skip-link:focus { transform: none; }

.has-app-sidebar .app-stage {
  min-height: 100vh;
  margin-left: var(--hb-sidebar-width);
}

.app-stage { min-width: 0; }

.app-topbar {
  --hb-topbar-end-padding: clamp(1.25rem, 3vw, 3rem);
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--hb-topbar-height);
  padding: var(--hb-space-2) clamp(var(--hb-space-3), 2vw, var(--hb-space-8));
  padding-inline-end: var(--hb-topbar-end-padding);
  background: var(--hb-surface);
  border-bottom: 1px solid var(--hb-border);
}

.app-topbar-start,
.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 0;
}

.app-topbar-actions { flex-shrink: 0; margin-left: auto; }

.notification-toggle { position: relative; min-width: 44px; min-height: 44px; list-style: none; cursor: pointer; }
.notification-toggle::-webkit-details-marker { display: none; }
.notification-count {
  position: absolute;
  inset: .15rem .15rem auto auto;
  min-width: 1.2em;
  padding: 0 .2em;
  border-radius: 1rem;
  background: var(--hb-primary-soft);
  color: var(--hb-text);
  text-align: center;
  font-size: .72rem;
  font-weight: 700;
}
.notification-panel {
  position: absolute;
  inset-inline-end: var(--hb-topbar-end-padding);
  top: calc(100% + .25rem);
  width: min(25rem, calc(100vw - 2rem));
  max-height: min(70vh, 38rem);
  overflow: auto;
  padding: .75rem;
  border: 1px solid var(--hb-border);
  border-radius: .7rem;
  background: var(--hb-surface);
  box-shadow: var(--hb-shadow);
  overflow-wrap: anywhere;
}
.notification-panel-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.notification-panel-heading .btn, .notification-all { min-height: 44px; }
.notification-all { display: inline-flex; align-items: center; }
.notification-item {
  display: grid;
  gap: .2rem;
  padding: .55rem .7rem;
  min-height: 44px;
  width: 100%;
  text-align: start;
  color: var(--hb-text);
  background: var(--hb-surface);
  border: 1px solid var(--hb-border);
  border-radius: .4rem;
}
.notification-items li + li { margin-top: .35rem; }
.notification-item:hover { background: var(--hb-surface-2); }
.notification-item small { color: var(--hb-muted); }
.notification-unread { color: var(--hb-text); font-weight: 650; }

.app-product-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.app-product-title span {
  color: var(--hb-text);
  font-weight: 740;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-product-title small {
  color: var(--hb-text);
  font-size: var(--hb-body-size);
  font-weight: 640;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-public-brand {
  display: flex;
  align-items: center;
  min-height: 48px;
  color: var(--hb-text);
  font-size: 1.12rem;
  font-weight: 740;
  text-decoration: none;
}

.app-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .42rem;
  min-width: 44px;
  min-height: 44px;
  padding: .5rem .7rem;
  border: 1px solid var(--hb-border);
  border-radius: var(--hb-radius);
  color: var(--hb-text-soft);
  background: var(--hb-surface);
  text-decoration: none;
}

button.app-icon-button { cursor: pointer; }

.app-icon-button:hover {
  color: var(--hb-text);
  background: var(--hb-surface-2);
  border-color: var(--hb-border-strong);
}

.app-icon-button:active { background: var(--hb-surface-3); }

.app-icon-button svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-action-label {
  font-size: .75rem;
  font-weight: 700;
}

:is(.app-language-menu, .app-account-menu) summary {
  cursor: pointer;
  list-style: none;
}

:is(.app-language-menu, .app-account-menu) summary::-webkit-details-marker { display: none; }
.app-language-menu .app-action-label { display: inline; }

:is(.app-language-options, .app-account-options) {
  position: absolute;
  inset-block-start: calc(100% + .25rem);
  inset-inline-end: var(--hb-topbar-end-padding);
  inline-size: 11rem;
  max-inline-size: calc(100% - var(--hb-topbar-end-padding) - 1rem);
  padding: .25rem;
  border: 1px solid var(--hb-border);
  border-radius: .72rem;
  background: var(--hb-surface);
  box-shadow: var(--hb-shadow);
}

.app-account-options { inline-size: 17rem; }
.app-account-name { padding: var(--hb-space-2) var(--hb-space-3); margin: 0; color: var(--hb-muted); overflow-wrap: anywhere; }

.app-language-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  width: 100%;
  min-height: 44px;
  padding: .5rem .75rem;
  border: 0;
  border-radius: .45rem;
  background: transparent;
  color: var(--hb-text);
  text-align: start;
  text-decoration: none;
}

.app-language-option:is(:hover, [aria-current="true"]) {
  background: var(--hb-surface-3);
}

.theme-icon { display: none; }
html[data-theme="dark"] .theme-icon-sun { display: block; }
html[data-theme="light"] .theme-icon-moon { display: block; }

.app-logout-form { margin: 0; }

.app-content {
  width: 100%;
  max-width: var(--hb-content-width);
  margin: 0;
  padding: clamp(var(--hb-space-4), 2.5vw, var(--hb-space-10));
}

.public-shell .app-content {
  max-width: 900px;
  padding-top: clamp(1.2rem, 4vw, 3rem);
}

.app-main-content { min-height: calc(100vh - var(--hb-topbar-height) - 6rem); }

.app-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1rem;
  margin-top: 2.5rem;
  padding: 1.1rem 0 0;
  color: var(--hb-muted);
  border-top: 1px solid var(--hb-border);
  font-size: .82rem;
}

.app-footer a { color: var(--hb-muted); }

.app-sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 1030;
  display: none;
  padding: 0;
  border: 0;
  background: var(--hb-scrim);
}

.card,
.modal-content,
.dropdown-menu,
.list-group-item {
  color: var(--hb-text);
  background: var(--hb-surface);
  border-color: var(--hb-border);
}

.form-control,
.form-select,
.input-group-text {
  color: var(--hb-text);
  background-color: var(--hb-surface-2);
  border-color: var(--hb-border);
}

.form-control::placeholder { color: var(--hb-muted); opacity: 1; }

.form-control:focus,
.form-select:focus {
  color: var(--hb-text);
  background-color: var(--hb-surface-2);
  border-color: color-mix(in srgb, var(--hb-primary) 65%, var(--hb-border));
}

.form-check-input {
  background-color: var(--hb-surface-2);
  border-color: var(--hb-border-strong);
}

.record-edit-form { max-inline-size: var(--hb-form-width); }

.record-edit-form :is(.form-control, .form-select, .btn) { min-block-size: 44px; }

.record-edit-form > a {
  display: inline-flex;
  align-items: center;
  min-block-size: 44px;
}

.form-more {
  margin-block: .75rem 1rem;
  padding-inline: .875rem;
  border: 1px solid var(--hb-border);
  border-radius: .5rem;
  background-color: var(--hb-surface);
}

.form-more > summary {
  min-block-size: 44px;
  padding-block: .625rem;
  color: var(--hb-text);
  font-weight: 600;
  cursor: pointer;
}

.form-more[open] > summary { margin-block-end: .75rem; }

.address-lookup-keys {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr));
  column-gap: .75rem;
}

.address-lookup-status:empty { margin: 0; }

.form-control.address-lookup-updated {
  background-color: color-mix(in srgb, var(--hb-success) 22%, var(--hb-surface));
}

@media (max-width: 575.98px) {
  .address-lookup-keys { grid-template-columns: minmax(0, 1fr); }
}

@media print {
  .table {
    --bs-table-color: var(--hb-text-soft);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--hb-border);
    --bs-table-striped-color: var(--hb-text-soft);
    --bs-table-striped-bg: color-mix(in srgb, var(--hb-surface-2) 72%, transparent);
    --bs-table-hover-color: var(--hb-text);
    --bs-table-hover-bg: color-mix(in srgb, var(--hb-surface-3) 75%, transparent);
  }

  .table thead th {
    color: var(--hb-muted);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .015em;
    text-transform: none;
  }
}

.text-muted { color: var(--hb-muted) !important; }
.border,
.border-top,
.border-bottom { border-color: var(--hb-border) !important; }

.pagination {
  --bs-pagination-bg: var(--hb-surface);
  --bs-pagination-color: var(--hb-text-soft);
  --bs-pagination-border-color: var(--hb-border);
  --bs-pagination-hover-bg: var(--hb-surface-2);
  --bs-pagination-hover-color: var(--hb-text);
  --bs-pagination-hover-border-color: var(--hb-border-strong);
  --bs-pagination-active-bg: var(--hb-primary);
  --bs-pagination-active-border-color: var(--hb-primary);
}

.authenticator-qr {
  display: block;
  width: 320px;
  max-width: 100%;
  height: auto;
  margin-bottom: 1rem;
  padding: .45rem;
  border-radius: .65rem;
  background: var(--hb-paper);
  image-rendering: pixelated;
}

.app-login {
  max-width: 29rem;
  padding: clamp(1rem, 4vw, 2rem);
  border: 1px solid var(--hb-border);
  border-radius: 1rem;
  background: var(--hb-surface);
  box-shadow: var(--hb-shadow-sm);
}

.app-login h1 {
  margin: 0 0 1.3rem;
  color: var(--hb-text);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 760;
  letter-spacing: -.025em;
}

.app-login .btn-primary {
  min-height: 44px;
  padding-inline: 1.35rem;
}

.account-link-actions {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
}

.account-link-actions a {
  min-width: 0;
  overflow-wrap: anywhere;
}

.account-link-actions button {
  flex-shrink: 0;
  min-height: 44px;
}

.platform-company-create,
.platform-company-card-link {
  display: flex;
  align-items: center;
  min-height: 44px;
}

.platform-company-card-link { overflow-wrap: anywhere; }

@media (max-width: 1199px) {
  :root { --hb-sidebar-width: 238px; }
  .app-nav-link { font-size: .88rem; }
}

@media (max-width: 991.98px) {
  .app-topbar {
    min-height: 64px;
    padding-inline-start: .85rem;
  }

  .app-action-label { display: none; }

  .app-content { padding: 1rem; }
  .has-app-sidebar .app-stage { margin-left: 0; }

  .app-sidebar {
    width: min(86vw, 300px);
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform .22s ease, visibility .22s;
  }

  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .app-sidebar {
    transform: translateX(0);
    visibility: visible;
  }
  body.sidebar-open .app-sidebar-overlay { display: block; }

}

@media (max-width: 600px) {
  .app-topbar-actions { gap: .4rem; }
  .app-icon-button { padding: .42rem; }

  .app-login { border-radius: .8rem; }
}

@media (max-width: 420px) {
  .app-topbar:has(.app-notifications) {
    --hb-topbar-end-padding: .4rem;
    padding-inline-start: .4rem;
    gap: .2rem;
  }

  .app-topbar:has(.app-notifications) :is(.app-topbar-start, .app-topbar-actions) { gap: .18rem; }
  .app-topbar .app-language-menu .app-action-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
