/* ==========================================================================
   SenPro reskin — application shell
   Sidebar (Sidebar.md) + top bar (TopBar.md) + main content area; on a
   phone the sidebar becomes a drawer (mobile.md).
   Markup: templates/snippets/shell_sidebar.html, shell_topbar.html, base.html
   ========================================================================== */

body.authenticated {
  padding-left: var(--sidebar-width);
  min-height: 100vh;
}
body.anonymous {
  padding-left: 0;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.sp-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  padding: var(--space-20) var(--space-14);
  background: var(--surface-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1030;
  transition: transform 0.25s ease;
  -webkit-overflow-scrolling: touch;
}

/* Logo lockup: 32px square mark + SENPRO wordmark */
.sp-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px var(--space-8) 18px;
  color: var(--ink);
  text-decoration: none;
}
.sp-brand:hover,
.sp-brand:focus {
  color: var(--ink);
  text-decoration: none;
}
.sp-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  display: block;
  flex-shrink: 0;
}
html[data-theme="dark"] .sp-brand-mark {
  box-shadow: 0 0 0 1px var(--border-strong); /* keeps the dark mark visible on a dark sidebar */
}
.sp-wordmark {
  font: var(--text-wordmark);
  letter-spacing: var(--text-wordmark-tracking);
  text-transform: uppercase;
  color: var(--ink);
}
.sp-brand .sp-brand-accent { /* auth pages' two-tone wordmark */
  color: var(--brand);
}
.sp-brand-logo {
  max-width: 180px;
  max-height: 48px;
  width: auto;
  height: auto;
  display: block;
}

/* Close button: only inside the phone drawer */
.sp-sidebar .sp-sidebar-close {
  display: none;
  position: absolute;
  top: 12px;
  right: 8px;
  color: var(--ink-muted);
}

/* Organisation switcher: surface-muted button with the org and a chevron */
.sp-org-switcher {
  margin-bottom: var(--space-16);
}
.sp-org-switcher .dropdown-toggle {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: var(--control-md);
  padding: 0 12px 0 14px !important;
  border-radius: var(--radius-md) !important;
  background: var(--surface-muted) !important;
  border: 0 !important;
  box-shadow: none !important;
  color: var(--ink) !important;
  font: var(--text-body);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}
.sp-org-switcher .dropdown-toggle .current-org {
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-org-switcher .dropdown-toggle::after {
  position: static;
  transform: rotate(45deg) translateY(-2px);
  margin-left: 8px;
  border: 0;
  border-right: 1.5px solid var(--ink-muted);
  border-bottom: 1.5px solid var(--ink-muted);
  width: 7px;
  height: 7px;
  content: "";
  flex-shrink: 0;
}
.sp-org-switcher .dropdown-menu {
  width: 100%;
  background: var(--surface-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-menu);
  padding: 6px !important;
  margin-top: 4px;
}
.sp-org-switcher .dropdown-menu li a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink) !important;
  font: var(--text-body-sm);
  background: transparent !important;
}
.sp-org-switcher .dropdown-menu li a:hover {
  background: var(--surface-hover) !important;
}
.sp-org-switcher .dropdown-menu li a .org-name {
  min-width: 0;
  overflow-wrap: anywhere;
}
.sp-org-switcher .dropdown-menu li a svg {
  flex-shrink: 0;
}
.sp-org-switcher .dropdown-menu .menu-label {
  display: block;
  padding: 6px 12px 4px;
  color: var(--ink-subtle);
  font: var(--text-caption);
}
.sp-org-switcher .dropdown-menu li a.active {
  color: var(--on-brand-soft) !important;
  background: var(--brand-soft) !important;
  font-weight: 600;
}

/* Navigation */
.sp-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sp-brand + .sp-nav {
  margin-top: 0;
}
.sp-org-switcher + .sp-nav {
  margin-top: 0;
}

.sp-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--nav-item);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font: var(--text-body);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
}
.sp-nav-item > svg {
  flex-shrink: 0;
}
.sp-nav-item > span:first-of-type {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-nav-item:hover,
.sp-nav-item:focus {
  color: var(--ink);
  background: var(--surface-hover);
  text-decoration: none;
}
.sp-nav-item.is-active,
.sp-nav-item.is-active:hover,
.sp-nav-item.is-active:focus {
  background: var(--brand-soft);
  color: var(--on-brand-soft);
  font-weight: 600;
}
.sp-nav-item.is-locked {
  color: var(--ink-subtle);
}
.sp-nav-item.is-locked:hover {
  background: var(--surface-hover);
}
.sp-nav-lock {
  flex-shrink: 0;
  color: var(--ink-subtle);
}
.sp-nav-item .sp-nav-hint {
  font: var(--text-caption);
  color: var(--ink-subtle);
  white-space: nowrap;
}
.sp-nav-item .sp-nav-badge {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--badge-alert);
  font-size: 0;
  flex-shrink: 0;
}
.sp-nav-item .sp-nav-badge:not(:empty) {
  display: inline-block;
}

/* Static section headings (Library, More, Business) */
.sp-nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sp-nav-caption {
  margin-top: var(--space-20);
  padding: 0 12px var(--space-6);
  font: var(--text-caption);
  color: var(--ink-subtle);
}

.sp-sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
  padding: var(--space-24) 12px 4px;
  font: var(--text-caption);
  color: var(--ink-subtle);
}
.sp-sidebar-footer-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
}
.sp-sidebar-footer-links a {
  font: var(--text-body-sm);
  color: var(--brand);
}
.sp-sidebar-footer-links a:hover {
  color: var(--brand-hover);
}
/* "Powered by SENPRO" when a custom logo replaces the lockup at the top */
.sp-powered-by {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding-top: var(--space-10);
  border-top: 1px solid var(--divider);
}
.sp-powered-by__lockup {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}
.sp-powered-by .sp-brand-mark {
  width: 24px;
  height: 24px;
}
.sp-sidebar-footer .sp-served-by {
  font: var(--text-caption);
  color: var(--ink-subtle);
  word-break: break-all;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

/* Sits at the top of the page and scrolls away with it (not sticky; Mike, 2026-10-05) */
.sp-topbar {
  position: relative;
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-16);
  height: var(--topbar-height);
  padding: 0 var(--space-24);
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
}
.sp-topbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.sp-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}
.sp-topbar .sp-brand {
  display: none;
  padding: 0;
}
.sp-topbar .sp-brand-mark {
  width: 28px;
  height: 28px;
}
.sp-topbar .sp-brand--anon {
  display: flex;
}
.sp-topbar .sp-brand--anon .sp-brand-mark {
  width: 32px;
  height: 32px;
}
.sp-topbar .sp-brand-logo {
  max-height: 32px;
  max-width: 140px;
}

.sp-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-md);
  height: var(--control-md);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink-secondary);
  cursor: pointer;
  position: relative;
  transition: background 0.12s ease, color 0.12s ease;
}
.sp-icon-btn:hover,
.sp-icon-btn:focus,
.sp-icon-btn.active {
  background: var(--surface-hover);
  color: var(--ink);
  text-decoration: none;
}
.sp-icon-btn--filled {
  background: var(--surface-page);
}
.sp-icon-btn svg {
  width: 20px;
  height: 20px;
}
.sp-hamburger {
  display: none;
  margin-left: -6px;
}

/* Theme toggle: show the sun in dark mode, the moon in light mode */
.sp-theme-toggle .sp-icon-sun { display: none; }
.sp-theme-toggle .sp-icon-moon { display: block; }
html[data-theme="dark"] .sp-theme-toggle .sp-icon-sun { display: block; }
html[data-theme="dark"] .sp-theme-toggle .sp-icon-moon { display: none; }

/* Unread count badges on bell / envelope (populated by existing JS) */
/* TopBar.md: a badge-alert pill pinned to the icon's top-right. It starts
   just right of the icon's centre and grows rightwards with the count, with a
   ring in the bar's colour so it never hides the icon's shape. The .count
   selectors also override css-v2's fixed 20px (15px on phones) circle. */
.sp-icon-btn .notif_count,
.sp-icon-btn .unread_count {
  display: none;
}
.sp-icon-btn .notif_count.count,
.sp-icon-btn .unread_count.count {
  display: block;
  position: absolute;
  top: 5px;
  left: 24px;
  right: auto;
  width: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--badge-alert);
  box-shadow: 0 0 0 2px var(--surface-card);
  color: var(--on-brand);
  font: var(--text-micro);
  line-height: 18px;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

/* Account avatar + menu */
.sp-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: 2px;
  border-radius: var(--radius-full);
  background: var(--avatar);
  color: var(--ink-secondary);
  font: var(--text-label);
  cursor: pointer;
  border: 0;
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
}
.sp-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sp-avatar:hover,
.sp-avatar:focus {
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--border-strong);
}
.sp-account .dropdown-toggle::after {
  display: none;
}

.sp-menu {
  min-width: 220px;
  margin-top: 10px;
  padding: 6px !important;
  background: var(--surface-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-menu);
  color: var(--ink);
  font: var(--text-body-sm);
  height: auto !important;
  right: 0;
  left: auto;
}
.sp-menu .sp-menu-heading {
  padding: 10px 12px 12px;
  margin: -6px -6px 6px;
  font: var(--text-label);
  color: var(--ink);
  border-bottom: 1px solid var(--divider);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.sp-menu .sp-menu-label {
  padding: 8px 12px 4px;
  font: var(--text-caption);
  color: var(--ink-subtle);
}
.sp-menu a,
.sp-menu .dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary) !important;
  font: var(--text-body-sm);
  font-weight: 500;
  background: transparent;
  text-decoration: none;
  white-space: nowrap;
}
.sp-menu a:hover,
.sp-menu .dropdown-item:hover {
  background: var(--surface-subtle);
  color: var(--ink) !important;
  text-decoration: none;
}
.sp-menu .sp-menu-divider {
  height: 1px;
  margin: 6px 0;
  background: var(--divider);
}
.sp-menu .sp-menu-upgrade {
  margin: 8px 6px 4px;
}
.sp-menu .sp-menu-upgrade a {
  display: flex;
  justify-content: center;
  min-height: var(--control-sm);
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--on-brand) !important;
  font-weight: 600;
}
.sp-menu .sp-menu-upgrade a:hover {
  background: var(--brand-hover);
}

/* Notifications popover (base.html #notifications_container, opened from the
   bell): 340px, a header, then one row per notification with an unread dot */
#notifications_container {
  position: absolute !important; /* under the bell at the top of the page, scrolling with it like the top bar */
  top: calc(var(--topbar-height) + 6px) !important;
  right: var(--space-24) !important;
  left: auto !important;
  width: 340px !important;
  max-width: calc(100vw - 32px) !important;
  height: auto !important;
  padding: 0 !important;
  margin: 0 !important;
  z-index: 1040 !important;
}
/* #id: beats css-v2's dark, full-height, always-scrolling #notifications_pane.
   jQuery slideDown sets display: block inline, so this stays block layout. */
#notifications_pane.sp-notif {
  height: auto;
  max-height: calc(100vh - var(--topbar-height) - 24px);
  overflow: hidden;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-menu);
  color: var(--ink);
  overflow: hidden;
}
.sp-notif__head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--divider);
  font: var(--text-body);
  font-weight: 700;
  color: var(--ink);
}
.sp-notif__trial {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) 18px;
  border-bottom: 1px solid var(--divider);
  background: var(--brand-soft);
  color: var(--on-brand-soft);
  font: var(--text-caption);
}
.sp-notif__trial a {
  flex-shrink: 0;
  color: var(--on-brand-soft);
  font-weight: 600;
  text-decoration: underline;
}
.sp-notif__list {
  max-height: 340px;
  overflow-y: auto;
}
.sp-notif__item {
  display: flex;
  gap: 10px;
  padding: var(--space-12) 18px;
  border-bottom: 1px solid var(--divider-row);
  color: var(--ink);
  text-decoration: none;
}
.sp-notif__item:last-child {
  border-bottom: 0;
}
.sp-notif__item:hover,
.sp-notif__item:focus-visible {
  background: var(--surface-subtle);
  color: var(--ink);
  text-decoration: none;
  outline: none;
}
/* Unread: a brand dot and a bolder title; read rows keep the space */
.sp-notif__dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: var(--radius-full);
  background: transparent;
}
.sp-notif__item.unread .sp-notif__dot {
  background: var(--brand);
}
.sp-notif__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.sp-notif__title {
  font: var(--text-body-sm);
  font-weight: 500;
  color: var(--ink);
}
.sp-notif__item.unread .sp-notif__title {
  font-weight: 600;
}
.sp-notif__detail {
  font: var(--text-caption);
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}
.sp-notif__time {
  font: var(--text-caption);
  color: var(--ink-subtle);
}
.sp-notif__empty {
  padding: var(--space-24) 18px;
  font: var(--text-body-sm);
  color: var(--ink-muted);
  text-align: center;
}

/* --------------------------------------------------------------------------
   Main content
   -------------------------------------------------------------------------- */

.sp-main {
  padding: var(--space-32) var(--space-40) var(--space-40);
  min-height: calc(100vh - var(--topbar-height));
}

/* One content width for every page (PageHeader.md, README "Layout"):
   header, toolbar and content share this wrapper, centred at page-max.
   To change alignment or width everywhere, edit these two declarations. */
.sp-page__inner {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
}
/* Exception: the client profile (header, tabs, Overview, Planner) and
   planners run the full width of the content area. Group pages are centred
   like the Clients page. */
.sp-page__inner:has(.client_bar:not(.print-show .client_bar)),
.sp-page__inner:has(.sp-planner),
.sp-page__inner:has(.planner-page) {
  max-width: none;
}
/* Bootstrap containers inside the wrapper no longer set their own width */
.sp-page__inner .container,
.sp-page__inner .container-fluid {
  width: 100%;
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}
/* List and card pages (Library, Consultations, Questionnaires, Services; each sets {% block main_class %}): room below
   the last item, so it can be scrolled up the screen and its ⋯ menu opens fully in view. Beats the phone padding. */
.sp-main.sp-main--list {
  padding-bottom: var(--page-end-space);
}
body.anonymous .sp-main {
  padding: 0;
  min-height: 0;
}

.wholeCont {
  min-height: 0;
}

/* Flash messages */
.messages_container .alert {
  margin-bottom: 20px;
}

/* Subscription overdue banner */
.sp-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--warning-soft);
  color: var(--on-warning-soft);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}
.sp-banner .btn {
  padding: 7px 14px;
}

/* Old footer is replaced by the sidebar footer */
.footerCont {
  display: none;
}

/* Old shell leftovers that some pages still reference */
.hamburger { display: none; }
#header.navbar { display: none; }

/* --------------------------------------------------------------------------
   Full-screen mode (client profile): hide sidebar + top bar
   -------------------------------------------------------------------------- */

body.sp-fullscreen {
  padding-left: 0;
}
body.sp-fullscreen .sp-sidebar,
body.sp-fullscreen .sp-topbar {
  display: none;
}
body.sp-fullscreen .sp-main {
  padding: 20px 24px;
}

/* --------------------------------------------------------------------------
   Responsive: the sidebar becomes a drawer below 1024px (mobile.md)
   -------------------------------------------------------------------------- */

.sp-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--scrim-overlay);
  z-index: 1029;
}

@media (max-width: 1023px) {
  body.authenticated {
    padding-left: 0;
  }
  .sp-sidebar {
    transform: translateX(-100%);
    width: min(288px, 86vw);
    border-right: 0;
  }
  body.sp-sidebar-open .sp-sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-modal);
  }
  body.sp-sidebar-open .sp-backdrop {
    display: block;
  }
  body.sp-sidebar-open {
    overflow: hidden;
  }
  .sp-sidebar .sp-sidebar-close {
    display: inline-flex;
  }
  .sp-hamburger {
    display: inline-flex;
  }
  .sp-topbar {
    padding: 0 12px;
  }
  .sp-topbar .sp-brand {
    display: flex;
  }
  /* Room for a count badge to grow right without reaching the next button's icon */
  .sp-topbar-right {
    gap: var(--space-4);
  }
  .sp-topbar-right .sp-avatar {
    margin-left: var(--space-6);
  }
  .sp-main {
    padding: 16px;
  }
  #notifications_container {
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: none !important;
    top: calc(var(--topbar-height) + 4px) !important;
  }
  .sp-menu {
    position: fixed !important;
    top: calc(var(--topbar-height) + 4px) !important;
    right: 8px !important;
    left: auto !important;
    transform: none !important;
  }
}

@media print {
  .sp-sidebar,
  .sp-topbar,
  .sp-backdrop,
  #notifications_container {
    display: none !important;
  }
  body.authenticated {
    padding-left: 0;
  }
  .sp-main {
    padding: 0;
  }
}
