/* Reset + typography ------------------------------------------------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font);
  font-size: 15px;
  line-height: var(--leading-normal);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 0.4rem; letter-spacing: -0.02em; }
h1 { font-size: var(--text-2xl); font-weight: 700; }

/* A single, consistent focus-visible treatment for every interactive element */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Fill the sidebar inset (no global content column). Form/lede widths stay local. */
.page {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: var(--space-6) var(--space-5) 4rem;
  flex: 1;
  min-width: 0;
}
.page.page--flush {
  padding: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.mainArea:has(.page--flush) {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.mainArea:has(.page--flush) .page.page--flush {
  flex: 1;
  min-height: 0;
}
.breadcrumb a.breadcrumbSection { color: var(--muted-foreground); text-decoration: none; }
.breadcrumb a.breadcrumbSection:hover { color: var(--foreground); text-decoration: none; }

/* App shell: persistent left sidebar + slim top bar ------------------ */
:root { --sidebar-w: 256px; --topbar-h: 3.5rem; }

.appShell { display: flex; align-items: stretch; min-height: 100vh; background: var(--background); }

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: 0 0.85rem 1rem;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 30;
  transition: background-color var(--motion-ui) var(--ease-standard);
}
/* Align with .topBar / breadcrumb row */
.sidebarHeader {
  flex: 0 0 auto;
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  margin-left: -0.85rem;
  margin-right: -0.85rem;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--sidebar-border);
}
.brandBlock {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brandMark {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--radius-md);
  background: var(--primary);
  display: grid;
  place-items: center;
  color: var(--primary-foreground);
  box-shadow: 0 2px 6px rgba(31, 107, 69, 0.25);
  flex-shrink: 0;
}
.brandMark svg { width: 0.95rem; height: 0.95rem; }
.brand {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--sidebar-text);
  text-decoration: none;
  display: block;
  line-height: 1.2;
}
.brand:hover { text-decoration: none; color: var(--sidebar-text); }

.envBadge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.45rem;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-border);
  color: var(--primary);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.pulseDot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 2px rgba(31, 107, 69, 0.2);
  animation: pulseDot 2s infinite;
}
@keyframes pulseDot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.workspaceSwitcher {
  padding: 0 0.15rem;
  flex: 0 0 auto;
}
.workspaceSwitcher form { display: block; }

/* Generic initial-letter avatar badge — reused for workspaces, members, etc. */
.avatar {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.68rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
  flex: 0 0 auto;
}
.avatar.avatar-lg { width: 1.75rem; height: 1.75rem; font-size: 0.8rem; border-radius: var(--radius-md); }

.sideNav { display: flex; flex-direction: column; gap: 1.25rem; flex: 1; min-height: 0; }
.navGroup { display: flex; flex-direction: column; gap: 0.12rem; }
.navLabel {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--sidebar-muted);
  padding: 0 0.6rem;
  margin-bottom: 0.35rem;
}
.navLink {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--sidebar-muted);
  font-weight: 500;
  font-size: 0.83rem;
  text-decoration: none;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-md);
  border: none;
  transition: all 0.15s var(--ease-standard);
}
.navLink svg { flex: 0 0 auto; opacity: 0.8; transition: transform 0.15s ease, opacity 0.15s ease; }
.navLink:hover {
  color: var(--sidebar-text);
  background: var(--sidebar-hover);
  text-decoration: none;
}
.navLink:hover svg { opacity: 1; transform: translateX(1px); }
.navLink.isActive {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
  font-weight: 600;
}
.navLink.isActive::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.35rem;
  bottom: 0.35rem;
  width: 3px;
  border-radius: 2px;
  background: var(--sidebar-active-indicator);
}
.navLink.isActive svg { opacity: 1; color: var(--sidebar-active-text); }

.sideNavFooter {
  margin-top: auto;
  margin-left: -0.85rem;
  margin-right: -0.85rem;
  padding: 0.85rem 0.85rem 0;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 0 0 auto;
}
.systemStatusRow {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.68rem;
  color: var(--sidebar-muted);
  font-weight: 500;
}
.systemStatusRow .statusDot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
}

.accountMenu { width: 100%; }
.accountMenuTrigger {
  padding: 0.45rem 0.5rem;
  gap: 0.6rem;
  align-items: center;
}
.accountMenuMeta {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.05rem;
  text-align: left;
}
.accountMenuName {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.accountMenuEmail {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--sidebar-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.accountMenuChevrons {
  width: 1rem;
  height: 1rem;
  transform: none !important;
}
.accountMenuHeader {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem 0.55rem;
}
.accountMenuPanel {
  min-width: 100%;
  width: max(100%, 14.5rem);
}
.accountMenuPanel .popoverSelectItem svg {
  flex: 0 0 auto;
  color: var(--muted-foreground);
}
.accountMenuPanel form { margin: 0; }

.themeToggleItem {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.themeToggleItem:hover { background: var(--muted); }
.themeToggleBadge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  background: var(--muted);
  color: var(--muted-foreground);
}

.mainArea { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--topbar-h);
  padding: 0 var(--space-5);
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--topbar-border);
  position: sticky;
  top: 0;
  z-index: 20;
  transition: background-color var(--motion-ui) var(--ease-standard);
}
.topBarLeft {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}
.topBarRight {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 0 0 auto;
}

.breadcrumb { display: flex; align-items: center; gap: 0.4rem; font-size: var(--text-sm); }
.breadcrumbSection { color: var(--muted-foreground); }
.breadcrumbSep { color: var(--border); font-size: 0.8rem; }
.breadcrumbPage { color: var(--foreground); font-weight: 600; }

/* Stripe-style Command Search Trigger button */
.cmdSearchBtn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted-foreground);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  width: 15.5rem;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.cmdSearchBtn:hover {
  border-color: var(--ring);
  color: var(--foreground);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.cmdSearchBtn span { flex: 1; text-align: left; }
.cmdKbd {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  background: var(--muted);
  border: 1px solid var(--border);
  color: var(--muted-foreground);
}

/* High-Quality CMDK Command Palette Modal System -------------------- */
.cmdKModal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: clamp(3rem, 12vh, 8rem);
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms cubic-bezier(0.16, 1, 0.3, 1), visibility 120ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, visibility;
}
.cmdKModal[hidden] {
  display: none !important;
}
.cmdKModal.isOpen {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  display: flex !important;
}
.cmdKOverlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateZ(0);
}
.cmdKPanel {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: color-mix(in srgb, var(--card) 96%, var(--background));
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  border-radius: 18px;
  box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  transform: scale(0.96) translateY(-8px);
  transition: transform 140ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
  z-index: 1;
}
.cmdKModal.isOpen .cmdKPanel {
  transform: scale(1) translateY(0);
}
.cmdKHeader {
  display: flex;
  align-items: center;
  padding: 0.95rem 1.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  gap: 0.75rem;
  background: var(--card);
}
.cmdKIcon {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--muted-foreground);
  flex-shrink: 0;
}
.cmdKInput {
  flex: 1;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: none !important;
  font-size: 1.05rem !important;
  color: var(--foreground) !important;
  padding: 0 !important;
  height: auto !important;
}
.cmdKInput::placeholder {
  color: var(--muted-foreground);
  opacity: 0.75;
}
.cmdKEscKey {
  padding: 0.18rem 0.45rem;
  border-radius: 6px;
  background: var(--muted);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted-foreground);
  cursor: pointer;
  user-select: none;
}
.cmdKBody {
  padding: 0.6rem;
  overflow-y: auto;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.cmdKSectionTitle {
  padding: 0.4rem 0.75rem 0.2rem;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cmdKList {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.cmdKItem {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  color: var(--foreground);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.cmdKItem:hover,
.cmdKItem.isSelected {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  text-decoration: none;
}
.cmdKItemIcon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 1rem;
  flex-shrink: 0;
  color: var(--muted-foreground);
}
.cmdKItem:hover .cmdKItemIcon,
.cmdKItem.isSelected .cmdKItemIcon {
  color: var(--primary);
}
.cmdKItemIcon svg {
  width: 1.1rem;
  height: 1.1rem;
  color: currentColor;
}
.cmdKItemTitle {
  flex: 1;
}
.cmdKItemMeta {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  font-weight: 400;
}
.cmdKItem.isSelected .cmdKItemMeta {
  color: var(--primary);
  opacity: 0.85;
}
.cmdKFooter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  background: color-mix(in srgb, var(--background) 95%, transparent);
  font-size: var(--text-xs);
  color: var(--muted-foreground);
}
.cmdKFooterHints {
  display: flex;
  gap: 0.85rem;
  align-items: center;
}
.cmdKFooterHints kbd {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.68rem;
  color: var(--foreground);
}
.cmdKFooterBranding {
  font-weight: 500;
}

.sidebarToggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.sidebarToggleIcon,
.sidebarToggleIcon::before,
.sidebarToggleIcon::after {
  display: block;
  width: 1.1rem;
  height: 2px;
  background: var(--foreground);
  border-radius: 2px;
}
.sidebarToggleIcon { position: relative; }
.sidebarToggleIcon::before, .sidebarToggleIcon::after { content: ""; position: absolute; left: 0; }
.sidebarToggleIcon::before { top: -5px; }
.sidebarToggleIcon::after { top: 5px; }

.sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 22, 0.4);
  z-index: 25;
}

/* HTMX partial-swap polish: fade instead of pop, everywhere in the app */
.htmx-swapping { opacity: 0; transition: opacity 0.12s ease-out; }
.htmx-settling { opacity: 1; }

@media (max-width: 860px) {
  .sidebarToggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.isOpen { transform: translateX(0); }
  .sidebarOverlay.isOpen { display: block; }
}

/* One global switch — every transition/animation site-wide collapses to
   near-instant instead of each component re-implementing the query. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
