/* TrnkeyAI Sales Portal — chrome layout (PLAN.MD A0.13). REFERENCE-ONLY markup lives
   in chrome-snippet.html; this file is the real, shipped stylesheet every Sales Portal
   page links. Layout only — every color/spacing value is var(--token) from tokens.css,
   never a literal, per DESIGN.MD §8 / R18. Source of truth: DESIGN.MD §5 (Sales Portal
   row) + PLAN.MD §A.4 (13-item nav) + §A.9 (wordmark brand). */

:root {
  --sp-sidebar-w: 220px;
  --sp-sidebar-w-collapsed: 60px;
  --sp-topbar-h: 64px;
}

/* ==========================================================================
   Shell — sidebar + main column
   ========================================================================== */

.sp-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sp-sidebar {
  flex-shrink: 0;
  width: var(--sp-sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1rem 0.625rem;
  border-right: 1px solid var(--border);
  background: var(--card-solid);
  transition: width 0.2s ease;
  z-index: 50;
}

.sp-sidebar[data-collapsed="true"] {
  width: var(--sp-sidebar-w-collapsed);
}

/* Stacked, not side-by-side: the collapse toggle sits on its own row above
   the wordmark row, so the two never compete for the sidebar's ~190px of
   horizontal room (the wordmark text alone needs most of that budget). */
.sp-sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.25rem 0.375rem 1rem;
  min-width: 0;
}

.sp-sidebar[data-collapsed="true"] .sp-sidebar-brand {
  align-items: center;
}

.sp-sidebar[data-collapsed="true"] .trnkey-wordmark__text {
  display: none;
}

/* Visually hidden, not display:none: the icon (aria-hidden) carries no
   name, so this label is the link's only accessible name. Clipping keeps
   it in the accessibility tree while taking no space in the rail. */
.sp-sidebar[data-collapsed="true"] .sp-nav-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

/* The wordmark markup is copied verbatim from shared/brand/wordmark-snippet.html
   (its own inline styles are untouched); these rules only constrain it to the
   sidebar's available width so long product names ellipsize instead of
   overflowing under the topbar. */
.sp-sidebar-brand .trnkey-wordmark {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.sp-sidebar-brand .trnkey-wordmark__text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--text-sm);
}

.sp-hamburger {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}

.sp-hamburger:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.sp-hamburger--mobile {
  display: none;
}

/* ---- primary nav ---- */

.sp-nav ul {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.sp-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
  border-radius: 8px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.sp-nav-item:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.sp-nav-item.is-active {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  /* text darkened toward --foreground to clear 4.5:1 on the tinted background
     (measured 4.01:1 light / 4.06:1 dark as pure --primary) without touching
     the --primary brand token itself; one mix ratio works in both themes since
     --foreground already flips to the correct dark/light extreme per theme. */
  color: color-mix(in srgb, var(--primary) 75%, var(--foreground) 25%);
}

.sp-nav-icon {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
}

.sp-sidebar[data-collapsed="true"] .sp-nav-item {
  justify-content: center;
  padding: 0.5rem;
}

/* ==========================================================================
   Main column — topbar + page content
   ========================================================================== */

.sp-main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sp-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--sp-topbar-h);
  padding: 0.75rem 1.25rem;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}

.sp-page-title {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-right: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-upload-badge {
  white-space: nowrap;
}

/* ---- campaign multi-select ---- */

.sp-campaign-select {
  position: relative;
}

.sp-campaign-select-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
}

.sp-campaign-select-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  width: 16rem;
  max-width: calc(100vw - 2rem);
  max-height: 20rem;
  overflow-y: auto;
  padding: 0.5rem;
  /* display:none (not visibility:hidden) so the closed panel is removed from
     layout and cannot contribute to document scrollWidth on narrow viewports;
     `display` is added to the transition via allow-discrete + @starting-style
     so the open animation still plays in supporting browsers (close is
     instant, which is an acceptable trade for never occupying layout). */
  display: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, display 0.15s allow-discrete;
  z-index: 45;
}

@starting-style {
  .sp-campaign-select-panel.is-open {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.sp-campaign-select-panel.is-open {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.sp-campaign-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  border-radius: 6px;
  font-size: var(--text-sm);
}

.sp-campaign-option:hover {
  background: var(--secondary);
}

.sp-campaign-select-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.375rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

/* ---- timezone toggle pill ---- */

.sp-tz-toggle {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--foreground);
  cursor: pointer;
  white-space: nowrap;
}

.sp-tz-toggle:hover {
  background: var(--secondary);
}

/* ---- alerts bell ---- */

.sp-alerts-bell {
  all: unset;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}

.sp-alerts-bell:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.sp-alerts-count {
  position: absolute;
  top: 0.125rem;
  right: 0.125rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  font-size: 0.625rem;
  line-height: 1rem;
}

.sp-alerts-panel {
  width: 20rem;
  max-height: 24rem;
  overflow-y: auto;
  padding: 0.75rem;
}

.sp-alerts-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.sp-alert-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem;
  border-radius: 8px;
}

.sp-alert-row + .sp-alert-row {
  margin-top: 0.25rem;
}

.sp-alert-row[data-read="false"] {
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}

.sp-alert-title {
  font-size: var(--text-xs);
  font-weight: 500;
}

.sp-alert-meta {
  font-size: var(--text-xs);
  color: var(--muted);
}

/* ---- theme toggle / user chip / sign out ---- */

.sp-theme-toggle {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}

.sp-theme-toggle:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.sp-user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.sp-user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.sp-user-name {
  font-size: var(--text-xs);
  font-weight: 500;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Push-enable banner
   ========================================================================== */

.sp-push-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.75rem 1.25rem 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--primary) 6%, var(--card-solid));
  font-size: var(--text-sm);
}

.sp-push-banner[hidden] {
  display: none;
}

.sp-push-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ==========================================================================
   Chat drawer trigger (FAB)
   ========================================================================== */

.sp-chat-fab {
  all: unset;
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 55;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  cursor: pointer;
  box-shadow:
    0 8px 24px rgba(15, 23, 42, 0.08),
    0 2px 6px rgba(15, 23, 42, 0.04);
}

[data-theme="dark"] .sp-chat-fab {
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.2);
}

.sp-chat-fab:hover {
  background: var(--primary-dark);
}

#spChatDrawer .drawer-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#spChatDrawer .chat-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#spChatDrawer .chat-thread {
  flex: 1;
  min-height: 0;
}

/* ==========================================================================
   Page content wrapper (used by page atoms around their own <main>)
   ========================================================================== */

.sp-content {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 960px) {
  /* Off-canvas by default, independent of [data-collapsed] — that attribute
     is the desktop expand/collapse preference (persisted under
     trnkey-sp-sidebar) and must never decide mobile visibility, otherwise a
     fresh load (or a persisted desktop "expanded" preference) leaves a fixed
     220px sidebar sitting over the page. Mobile visibility is driven solely
     by .sp-sidebar--mobile-open, a non-persisted class toggled only by the
     mobile hamburger (#spSidebarToggleMobile). */
  .sp-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sp-sidebar-w);
    transform: translateX(-100%);
    box-shadow:
      0 8px 24px rgba(15, 23, 42, 0.08),
      0 2px 6px rgba(15, 23, 42, 0.04);
    transition: transform 0.2s ease;
  }

  [data-theme="dark"] .sp-sidebar {
    box-shadow:
      0 8px 24px rgba(0, 0, 0, 0.35),
      0 2px 6px rgba(0, 0, 0, 0.2);
  }

  .sp-sidebar.sp-sidebar--mobile-open {
    transform: translateX(0);
  }

  /* Neutralize the desktop "collapsed rail" styling: on mobile the sidebar
     is always full width with labels visible when open, regardless of the
     persisted desktop collapse state. */
  .sp-sidebar[data-collapsed="true"] {
    width: var(--sp-sidebar-w);
  }

  .sp-sidebar[data-collapsed="true"] .sp-sidebar-brand {
    align-items: flex-start;
  }

  .sp-sidebar[data-collapsed="true"] .trnkey-wordmark__text {
    display: inline;
  }

  /* Undo the desktop-collapsed clip: mobile always shows labels when the
     sidebar is open, regardless of the persisted desktop collapse state. */
  .sp-sidebar[data-collapsed="true"] .sp-nav-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: 0;
    padding: 0;
    margin: 0;
    display: inline;
  }

  .sp-sidebar[data-collapsed="true"] .sp-nav-item {
    justify-content: flex-start;
    padding: 0.5rem 0.625rem;
  }

  .sp-hamburger--mobile {
    display: inline-flex;
  }

  .sp-sidebar .sp-hamburger:not(.sp-hamburger--mobile) {
    display: none;
  }
}

@media (max-width: 720px) {
  .sp-topbar {
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }

  .sp-page-title {
    order: -1;
    width: 100%;
    margin-right: 0;
  }

  .sp-user-name {
    display: none;
  }
}
