/* ==========================================================================
   STYLE  (assets/css/style.css)
   --------------------------------------------------------------------------
   Shared UI used by more than one page. Page-only rules go in <page>.css.

    1. Brand / logo           9. Stat card
    2. App shell             10. List card, task row
    3. Sidebar + drawer      11. Progress rows
    4. Topbar + search       12. Alert
    5. Dropdown              13. Toast
    6. Avatar + account      14. Floating action button
    7. Mobile bottom nav     15. Auth shell + auth form
    8. Page head             16. Collapsible sidebar (icon rail)
                             17. Header icons, tooltips, account menu
                             18. Nav groups: accordion + rail flyouts
   Breakpoints: 576 / 768 / 992 / 1200 (same as utilities.css)
   ========================================================================== */

/* ==========================================================================
   1. BRAND / LOGO   (overrides components.css .brand__logo height)
   ========================================================================== */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-width: 0;
}
.brand__logo {
  height: 26px;
  width: auto;
  max-width: none;
}

/* ==========================================================================
   2. APP SHELL
   Desktop: [ sidebar | topbar / main ]   Mobile: topbar / main / bottom nav
   ========================================================================== */
.app {
  min-height: 100vh;
  min-height: 100dvh;
}
.app__body {
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.app__main {
  flex: 1;
  width: 100%;
  max-width: 100%;
  padding: var(--sp-8) clamp(16px, 3vw, 40px) var(--sp-12);
}

@media (max-width: 991.98px) {
  .app__body {
    margin-left: 0;
  }
}
@media (max-width: 767.98px) {
  .app__main {
    padding: var(--sp-5) var(--sp-4)
      calc(var(--mobile-nav-h) + var(--sp-10) + env(safe-area-inset-bottom));
  }
}

/* ==========================================================================
   3. SIDEBAR  (always dark panel, both themes)
   ========================================================================== */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  color: var(--panel-muted);
  padding: var(--sp-4) var(--sp-3);
}
.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 var(--sp-2) 0 var(--sp-3);
  margin-bottom: var(--sp-3);
}
.sidebar__head .brand__logo {
  height: 24px;
}
.sidebar__close {
  display: none;
  color: var(--panel-muted);
}
.sidebar__close:hover {
  background: var(--panel-hover);
  color: var(--panel-text);
}

.sidebar__nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 calc(var(--sp-3) * -1);
  padding: 0 var(--sp-3);
  scrollbar-width: thin;
  scrollbar-color: var(--panel-2) transparent;
}
.sidebar__label {
  margin: var(--sp-4) 0 var(--sp-1);
  padding: 0 var(--sp-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--panel-subtle);
}
.sidebar__list {
  display: grid;
  gap: 2px;
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--panel-muted);
  transition:
    background-color var(--fast) var(--ease),
    color var(--fast) var(--ease);
}
.sidebar__link:hover {
  background: var(--panel-hover);
  color: var(--panel-text);
}
.sidebar__link.is-active {
  background: var(--panel-active);
  color: var(--panel-text);
  font-weight: 600;
}
.sidebar__link.is-active .icon {
  color: var(--panel-accent);
}
/* active marker bar */
.sidebar__link {
  position: relative;
}
.sidebar__link.is-active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--panel-accent);
}
.sidebar__foot {
  padding-top: var(--sp-3);
  margin-top: var(--sp-2);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* scrim behind the drawer */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(7, 11, 22, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--slow) var(--ease);
}
.drawer-open .scrim {
  opacity: 1;
}

/* < 992px: sidebar becomes an off-canvas drawer */
@media (max-width: 991.98px) {
  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform var(--slow) var(--ease);
    box-shadow: var(--shadow-lg);
    padding-top: calc(var(--sp-4) + env(safe-area-inset-top));
  }
  .drawer-open .sidebar {
    transform: none;
  }
  .sidebar__close {
    display: inline-grid;
  }
  .drawer-open {
    overflow: hidden;
  }
}

/* ==========================================================================
   4. TOPBAR + SEARCH
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--header-h);
  padding: 0 clamp(16px, 3vw, 40px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__menu,
.topbar__brand,
.topbar__search-btn {
  display: none;
}
.topbar__brand .brand__logo {
  height: 22px;
}
.topbar__tools {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}
.topbar__create {
  height: 40px;
  padding: 0 16px;
}

.search {
  position: relative;
  flex: 1;
  max-width: 560px;
}
.search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}
.search__input {
  width: 100%;
  height: 42px;
  padding: 0 40px 0 42px;
  font-size: 14.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition:
    border-color var(--fast) var(--ease),
    box-shadow var(--fast) var(--ease),
    background-color var(--fast) var(--ease);
}
.search__input::placeholder {
  color: var(--text-subtle);
}
.search__input:focus {
  background: var(--surface);
  border-color: var(--brand);
}
.search__input::-webkit-search-cancel-button {
  display: none;
}
.search__kbd {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}
.search__input:focus ~ .search__kbd {
  opacity: 0;
}

@media (max-width: 991.98px) {
  .topbar__menu,
  .topbar__brand {
    display: inline-flex;
  }
  .topbar__menu {
    border-color: transparent;
    background: transparent;
    margin-left: -8px;
  }
}
/* < 768px: search collapses into an icon that expands over the bar */
@media (max-width: 767.98px) {
  .topbar {
    gap: var(--sp-2);
    padding: 0 var(--sp-4);
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-h) + env(safe-area-inset-top));
  }
  .topbar__search-btn {
    display: inline-grid;
    border-color: transparent;
    background: transparent;
  }
  .topbar__search {
    position: absolute;
    inset: env(safe-area-inset-top) 0 0 0;
    z-index: 2;
    max-width: none;
    display: none;
    align-items: center;
    padding: 0 var(--sp-4);
    background: var(--surface);
  }
  .topbar__search .search__icon {
    left: calc(var(--sp-4) + 14px);
  }
  .search-open .topbar__search {
    display: flex;
  }
  .search__kbd {
    display: none;
  }
  .topbar__create {
    width: 40px;
    padding: 0;
  }
  .topbar__create-text {
    display: none;
  }
  .topbar__theme {
    display: none;
  }
}
/* tablets: hide the account name so the bar fits */
@media (min-width: 768px) and (max-width: 991.98px) {
  .account-btn__name,
  .account-btn__mode,
  .topbar__divider {
    display: none;
  }
}
/* phones: logo can shrink, tighter tool spacing so nothing overflows */
@media (max-width: 479.98px) {
  .topbar__brand { min-width: 0; flex: 0 1 auto; }
  .topbar__brand .brand__logo { height: 20px; max-width: 96px; }
  .topbar__tools { gap: 2px; }
  .topbar__create { width: 36px; height: 36px; }
}
@media (max-width: 359.98px) {
  .topbar__create {
    display: none;
  }
}

/* ==========================================================================
   5. DROPDOWN
   <div class="dropdown" data-dropdown>
   ========================================================================== */
.dropdown {
  position: relative;
}
/* Moved to dropdown.css */

/* notifications */
.notif {
  display: flex;
  gap: 10px;
  padding: 10px;
  font-size: 13.5px;
  color: var(--text-muted);
  border-radius: 7px;
}
.notif:hover {
  background: var(--surface-hover);
}
.notif small {
  display: block;
  margin-top: 2px;
  color: var(--text-subtle);
}
.notif strong {
  color: var(--text);
  font-weight: 600;
}
.notif__dot {
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: transparent;
}
.notif.is-unread .notif__dot {
  background: var(--brand);
}

/* ==========================================================================
   6. AVATAR + ACCOUNT CARD
   ========================================================================== */
.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.avatar--sm {
  width: 32px;
  height: 32px;
  font-size: 12px;
}
.avatar--lg {
  width: 52px;
  height: 52px;
  font-size: 17px;
}
.avatar-btn {
  border-radius: 50%;
}
.avatar-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.avatar-btn:hover .avatar {
  filter: brightness(0.96);
}

.account-card {
  display: flex;
  gap: 14px;
  padding: 16px;
}
.account-card__name {
  font-size: 16px;
  font-weight: 700;
}
.account-card__email {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   7. MOBILE BOTTOM NAV  (< 768px)
   ========================================================================== */
.mobile-nav {
  display: none;
}
@media (max-width: 767.98px) {
  .mobile-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
  }
  .mobile-nav__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-subtle);
  }
  .mobile-nav__link.is-active {
    color: var(--brand);
  }
}

/* ==========================================================================
   8. PAGE HEAD
   ========================================================================== */
.page-head {
  margin-bottom: var(--sp-6);
}
.page-head__title {
  font-size: clamp(24px, 1.2rem + 1.2vw, 34px);
  font-weight: 700;
  letter-spacing: -0.025em;
}
.page-head__sub {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ==========================================================================
   9. STAT CARD
   ========================================================================== */
.stat-card {
  padding: var(--sp-5) var(--sp-6);
}
.stat-card__label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}
.stat-card__value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  font-size: clamp(26px, 1.3rem + 1vw, 34px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.stat-card__value--danger {
  color: var(--danger);
}
.stat-card__value--warning {
  color: var(--warning);
}
.stat-card__value--success {
  color: var(--success);
}
.stat-card__meta {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0;
}

/* ==========================================================================
   10. LIST CARD + TASK ROW
   ========================================================================== */
.list-card {
  padding: 0;
  overflow: hidden;
}
.list-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--border);
}
.list-card__title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.list-card__head .link {
  font-size: 14px;
}

.task-row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 12px var(--sp-6);
  border-bottom: 1px solid var(--border);
  transition: background-color var(--fast) var(--ease);
}
.task-row:last-child {
  border-bottom: 0;
}
.task-row:hover {
  background: var(--surface-2);
}
.task-row__body {
  flex: 1;
  min-width: 0;
}
.task-row__title {
  font-size: 15px;
  font-weight: 600;
  transition: color var(--fast) var(--ease);
}
.task-row__related {
  font-size: 13.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-row__when {
  flex: none;
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.task-row__when.is-overdue {
  color: var(--warning);
  font-weight: 600;
}
.task-row.is-done .task-row__title {
  color: var(--text-subtle);
  text-decoration: line-through;
}
.task-row.is-done .task-row__when {
  color: var(--text-subtle);
  font-weight: 400;
}

@media (max-width: 575.98px) {
  .list-card__head,
  .task-row {
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }
  .task-row {
    gap: var(--sp-3);
    align-items: flex-start;
  }
  .task-row__check {
    margin-top: 2px;
  }
  .task-row__when {
    font-size: 12.5px;
  }
}

/* ==========================================================================
   11. PROGRESS ROWS
   ========================================================================== */
.progress-list {
  display: grid;
  gap: var(--sp-5);
  padding: var(--sp-5) var(--sp-6) var(--sp-6);
}
.progress-row__head {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: 8px;
  font-size: 15px;
}
.progress-row__label {
  font-weight: 600;
}
.progress-row__amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.progress {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.progress__bar {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.9s var(--ease);
}
.js .progress__bar:not(.is-in) {
  width: 0;
}
@media (max-width: 575.98px) {
  .progress-list {
    padding: var(--sp-4);
  }
}

/* ==========================================================================
   12. ALERT
   ========================================================================== */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
}
.alert__icon {
  margin-top: 1px;
}
.alert--info {
  background: var(--brand-soft);
  color: var(--brand-ink);
}
.alert--success {
  background: var(--success-bg);
  color: var(--success);
}
.alert--warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.alert--danger {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ==========================================================================
   13. TOAST   CRM.toast('Message', 'success' | 'info' | 'danger')
   ========================================================================== */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  justify-items: center;
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--slow) var(--ease);
  pointer-events: auto;
}
.toast.is-leaving {
  animation: toast-out var(--slow) var(--ease) forwards;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(10px);
  }
}
@media (max-width: 767.98px) {
  .layout-app .toast-region {
    bottom: calc(var(--mobile-nav-h) + 16px + env(safe-area-inset-bottom));
  }
}

/* ==========================================================================
   14. FLOATING ACTION BUTTON  (mobile only)
   ========================================================================== */
.fab {
  display: none;
}
@media (max-width: 767.98px) {
  .fab {
    position: fixed;
    right: 18px;
    z-index: 45;
    bottom: calc(var(--mobile-nav-h) + 18px + env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--brand-contrast);
    box-shadow: var(--shadow-brand);
  }
  .fab:active {
    transform: scale(0.96);
  }
}

/* ==========================================================================
   15. AUTH SHELL + AUTH FORM  (login.php, forgot-password.php)
   ========================================================================== */
.auth {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
}
.auth__theme {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 5;
}

.auth-form {
  width: 100%;
  max-width: 440px;
}
.auth-form__title {
  font-size: clamp(26px, 1.3rem + 1vw, 34px);
  font-weight: 700;
  letter-spacing: -0.025em;
}
.auth-form__sub {
  margin: 8px 0 var(--sp-6);
  color: var(--text-muted);
  font-size: 15.5px;
}
.auth-form__foot {
  margin-top: var(--sp-6);
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

/* "or sign in with email" rule */
.divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-5) 0;
  font-size: 13px;
  color: var(--text-subtle);
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ==========================================================================
   16. COLLAPSIBLE SIDEBAR  (desktop >= 992px)
   <html class="sidebar-collapsed"> is set before paint (header.php) and
   toggled by base.js. Expanded 256px  ->  collapsed 72px icon rail.
   ========================================================================== */
:root {
  --sidebar-rail: 72px;
}

.sidebar,
.app__body {
  transition:
    width var(--slow) var(--ease),
    margin-left var(--slow) var(--ease),
    transform var(--slow) var(--ease);
}
.sidebar__brand {
  position: relative;
  height: 32px;
}
.sidebar__mark {
  display: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.sidebar__text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* collapse button: small circle on the sidebar's right edge, level with the logo */
.sidebar__head {
  position: relative;
}
.sidebar__toggle {
  position: absolute;
  top: 50%;
  right: -26px;
  z-index: 5;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  transition:
    background-color var(--fast) var(--ease),
    color var(--fast) var(--ease),
    transform var(--fast) var(--ease);
}
.sidebar__toggle:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
}
.sidebar__toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.sidebar__toggle-icon {
  transition: transform var(--slow) var(--ease);
}
.no-transition .sidebar,
.no-transition .app__body,
.no-transition .sidebar * {
  transition: none !important;
}

@media (min-width: 992px) {
  .sidebar-collapsed .sidebar {
    width: var(--sidebar-rail);
    padding-left: 12px;
    padding-right: 12px;
  }
  .sidebar-collapsed .app__body {
    margin-left: var(--sidebar-rail);
  }

  .sidebar-collapsed .sidebar__head {
    justify-content: center;
    padding: 0;
  }
  .sidebar-collapsed .sidebar__toggle {
    right: -25px;
  }
  .sidebar-collapsed .sidebar__logo {
    display: none;
  }
  .sidebar-collapsed .sidebar__mark {
    display: block;
  }

  /* group headings shrink to a thin divider */
  .sidebar-collapsed .sidebar__label {
    height: 1px;
    margin: 12px 8px;
    padding: 0;
    background: rgba(255, 255, 255, 0.08);
  }
  .sidebar-collapsed .sidebar__label span {
    display: none;
  }

  .sidebar-collapsed .sidebar__link {
    justify-content: center;
    padding: 0;
    gap: 0;
  }
  .sidebar-collapsed .sidebar__text {
    display: none;
  }
  .sidebar-collapsed .sidebar__link.is-active::before {
    left: -12px;
  }
  .sidebar-collapsed .sidebar__toggle-icon {
    transform: rotate(180deg);
  }
}

/* floating tooltip for rail icons (positioned by base.js so the scrolling
   nav never clips it) */
.rail-tip {
  position: fixed;
  z-index: 120;
  transform: translateY(-50%);
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
  pointer-events: none;
  animation: pop var(--fast) var(--ease);
}

/* drawer (mobile/tablet) always shows the full menu */
@media (max-width: 991.98px) {
  .sidebar__toggle {
    display: none;
  }
}

/* ==========================================================================
   17. HEADER ICONS, TOOLTIPS, ACCOUNT MENU
   ========================================================================== */
.topbar__icons {
  display: flex;
  align-items: center;
  gap: 2px;
}
.tb-btn.topbar__search-btn {
  display: none;
}
@media (max-width: 767.98px) {
  .tb-btn.topbar__search-btn {
    display: inline-grid;
  }
}

/* borderless icon button */
.tb-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition:
    background-color var(--fast) var(--ease),
    color var(--fast) var(--ease);
}
.tb-btn:hover,
.tb-btn[aria-expanded="true"] {
  background: var(--surface-hover);
  color: var(--text);
}
.tb-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.tb-btn.has-dot::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
}

/* hover tooltip under header icons */
.tb-btn[data-tip]:hover::before {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 90;
  pointer-events: none;
}
.tb-btn[aria-expanded="true"]::before {
  display: none;
}

.topbar__divider {
  width: 1px;
  height: 24px;
  margin: 0 6px;
  background: var(--border);
  flex: none;
}

/* account pill: avatar + account name + mode + caret */
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition:
    background-color var(--fast) var(--ease),
    border-color var(--fast) var(--ease);
}
.account-btn:hover,
.account-btn[aria-expanded="true"] {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.account-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.account-btn__name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-btn__mode {
  color: var(--text-subtle);
}
.account-btn__caret {
  color: var(--text-muted);
  transition: transform var(--fast) var(--ease);
}
.account-btn[aria-expanded="true"] .account-btn__caret {
  transform: rotate(180deg);
}
.avatar--xs {
  width: 30px;
  height: 30px;
  font-size: 11px;
}

/* account menu parts */
.dropdown__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 6px;
}
.dropdown__item--strong {
  font-weight: 600;
  font-size: 14.5px;
}
.dropdown__item--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}
.dropdown__item--stack small {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}
.dropdown__item > .icon:last-child:not(:first-child) {
  color: var(--text-subtle);
}
.dropdown__section--muted {
  background: var(--surface-2);
}
.dropdown__rule {
  height: 1px;
  margin: 8px 0;
  border: 0;
  background: var(--border);
}
.account-meta__name {
  font-weight: 700;
  font-size: 15px;
}
.account-meta__id {
  font-size: 13.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.account-card {
  border-bottom: 0;
}
.account-card .avatar--lg {
  width: 56px;
  height: 56px;
  font-size: 18px;
}
.link--underline {
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  margin-bottom: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
}

/* responsive: drop the less-used icons first */
@media (max-width: 1199.98px) {
  .tb-btn--hide-lg {
    display: none;
  }
}
@media (max-width: 767.98px) {
  .tb-btn--hide-md {
    display: none;
  }
  .topbar__divider,
  .account-btn__name,
  .account-btn__mode {
    display: none;
  }
  .account-btn {
    padding: 0 6px 0 4px;
    gap: 4px;
    background: transparent;
    border-color: transparent;
  }
  .topbar__icons {
    gap: 0;
  }
  .tb-btn {
    width: 36px;
    height: 36px;
  }
  .tb-btn[data-tip]:hover::before {
    display: none;
  }
}

/* AI assistant button beside search */
.assistant-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.assistant-btn .icon {
  color: var(--accent);
}
.assistant-btn:hover {
  background: var(--surface-hover);
}
.assistant-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
@media (max-width: 1199.98px) {
  .assistant-btn span {
    display: none;
  }
  .assistant-btn {
    padding: 0 10px;
  }
}
@media (max-width: 767.98px) {
  .assistant-btn {
    display: none;
  }
}

/* ==========================================================================
   18. NAV GROUPS  (CRM-style)
   Expanded : accordion   .nav-group__btn[aria-expanded="true"] + panel
   Collapsed: flyout      .nav-group.is-flyout > .nav-group__panel (fixed)
   ========================================================================== */
.sidebar__rule {
  height: 1px;
  margin: 10px 12px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
}
.sidebar__list + .sidebar__rule + .sidebar__list {
  gap: 2px;
}

.nav-group__btn {
  width: 100%;
  text-align: left;
}
.nav-group__chev {
  margin-left: auto;
  color: var(--panel-subtle);
  transition: transform var(--fast) var(--ease);
}
.nav-group__btn[aria-expanded="true"] .nav-group__chev {
  transform: rotate(180deg);
}
.nav-group.has-active > .nav-group__btn {
  color: var(--panel-text);
}
.nav-group.has-active > .nav-group__btn .icon:first-child {
  color: var(--panel-accent);
}

/* accordion panel */
.nav-group__panel {
  display: none;
  padding: 2px 0 8px;
}
.nav-group__btn[aria-expanded="true"] + .nav-group__panel {
  display: block;
  animation: nav-open 0.2s var(--ease);
}
@keyframes nav-open {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
.nav-group__title {
  display: none;
}
.nav-group__list {
  display: grid;
  gap: 1px;
}
.nav-group__rule {
  height: 1px;
  margin: 6px 12px 6px 44px;
  background: rgba(255, 255, 255, 0.07);
}

.nav-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 10px 6px 44px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--panel-muted);
  transition:
    background-color var(--fast) var(--ease),
    color var(--fast) var(--ease);
}
.nav-sub:hover,
.nav-sub:focus-visible {
  background: var(--panel-hover);
  color: var(--panel-text);
  outline: none;
}
.nav-sub.is-active {
  background: var(--panel-active);
  color: var(--panel-text);
  font-weight: 600;
}
.nav-sub__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-empty {
  padding: 6px 12px 8px 44px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--panel-subtle);
}

/* badges */
.nav-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.nav-badge--beta {
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  background: #6d4aff;
  color: #fff;
}
.nav-badge--new {
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  background: #1f8a4c;
  color: #fff;
}
.nav-badge--upgrade {
  color: var(--panel-subtle);
}
.nav-sub:hover .nav-badge--upgrade {
  color: var(--panel-text);
}

/* ---- collapsed rail: groups become flyouts ---- */
@media (min-width: 992px) {
  .sidebar-collapsed .sidebar__rule {
    margin: 10px 8px;
  }
  .sidebar-collapsed .nav-group__chev {
    display: none;
  }
  .sidebar-collapsed .nav-group__panel,
  .sidebar-collapsed .nav-group__btn[aria-expanded="true"] + .nav-group__panel {
    display: none;
  }
  .sidebar-collapsed .nav-group.has-active > .nav-group__btn {
    background: var(--panel-active);
  }
  .sidebar-collapsed .nav-group.is-flyout > .nav-group__btn {
    background: var(--panel-hover);
    color: var(--panel-text);
  }

  .sidebar-collapsed .nav-group.is-flyout > .nav-group__panel {
    display: block;
    position: fixed;
    z-index: 110;
    left: calc(var(--sidebar-rail) + 6px);
    top: var(--fly-top, 80px);
    width: 250px;
    max-height: calc(100vh - 16px);
    overflow-y: auto;
    padding: 12px 8px;
    background: #1b2236;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    animation: pop var(--fast) var(--ease);
  }
  /* invisible bridge so the pointer can travel from icon to flyout */
  .sidebar-collapsed .nav-group.is-flyout > .nav-group__panel::before {
    content: "";
    position: absolute;
    left: -14px;
    top: 0;
    bottom: 0;
    width: 14px;
  }
  .sidebar-collapsed .nav-group.is-flyout .nav-group__title {
    display: block;
    padding: 4px 12px 8px;
    font-size: 15px;
    font-weight: 700;
    color: var(--panel-text);
  }
  .sidebar-collapsed .nav-group.is-flyout .nav-sub {
    padding-left: 12px;
  }
  .sidebar-collapsed .nav-group.is-flyout .nav-group__rule {
    margin-left: 12px;
  }
  .sidebar-collapsed .nav-group.is-flyout .nav-empty {
    padding-left: 12px;
  }
}

/* Text areas keep their size (no drag handle) */
textarea, textarea.input { resize: none; }

/* Native selects (forms, drawers, filters): always show the chevron.
   Same arrow as settings.css so every page looks the same. */
select.input {
  -webkit-appearance: none; appearance: none;
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
select.input[multiple] { background-image: none; padding-right: 14px; }

/* ==========================================================================
   Topbar fit on small phones
   .tb-btn--hide-* buttons also carry crm-d-flex (display:flex !important), which
   beat the plain display:none above, so Upgrade + Settings never hid and the
   tools pushed the page wider than the screen (sideways scroll on every page).
   ========================================================================== */
@media (max-width: 1199.98px) { .tb-btn--hide-lg.tb-btn--hide-lg { display: none !important; } }
@media (max-width: 767.98px)  { .tb-btn--hide-md.tb-btn--hide-md { display: none !important; } }
@media (max-width: 767.98px)  { .topbar__tools { min-width: 0; flex-shrink: 1; } }
@media (max-width: 359.98px) {
  .topbar { padding-left: 8px; padding-right: 8px; gap: 4px; }
  .topbar .tb-btn { width: 32px; height: 32px; }
  .account-btn { padding: 0 2px; }
  .account-btn > svg { display: none; }
}
