/* ==========================================================================
   REFERENCE ONLY — TrnkeyAI Command Center chrome layout (PLAN.MD A0.14)

   Layout styles for the left rail / topbar / footer user menu / chat FAB
   defined in chrome-snippet.html. Consumes assets/css/tokens.css and
   assets/css/components.css — every color here is var(--token); the
   source app's original two-tone rail palette is retired, this surface
   uses --card-solid / dark tokens with --primary as the sole accent.
   Never linked from a shipped page directly except via the copied
   <link> tag inside chrome-snippet.html once pasted into a real page.
   ========================================================================== */

/* ---------- Shell ---------- */
.cc-shell {
  display: flex;
  min-height: 100vh;
}

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

.cc-content {
  flex: 1;
  padding: 1.5rem;
}

/* ---------- Rail ---------- */
.cc-rail {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--card-solid);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.2s ease;
  z-index: 50;
}

html[data-cc-sidebar="collapsed"] .cc-rail {
  width: 64px;
}

html[data-cc-sidebar="collapsed"] .cc-nav-group-label,
html[data-cc-sidebar="collapsed"] .cc-rail-brand-text {
  display: none;
}

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

html[data-cc-sidebar="collapsed"] .cc-rail-header {
  justify-content: center;
}

html[data-cc-sidebar="collapsed"] .cc-rail-collapse {
  transform: rotate(180deg);
}

html[data-cc-sidebar="collapsed"] .cc-nav-item {
  justify-content: center;
  padding-left: 0.75rem;
}

html[data-cc-sidebar="collapsed"] .cc-nav-item.is-active {
  padding-left: calc(0.75rem - 3px);
}

html[data-cc-sidebar="collapsed"] .cc-user-trigger {
  justify-content: center;
}

.cc-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}

.cc-rail-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  text-decoration: none;
  color: var(--foreground);
}

.cc-rail-logo {
  height: 36px;
  width: auto;
  flex-shrink: 0;
}

.cc-rail-brand-text {
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-rail-collapse {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.15s ease;
}

.cc-rail-collapse:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.cc-rail-collapse svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* ---------- Nav groups ---------- */
.cc-rail-nav {
  flex: 1;
  padding: 0.75rem 0;
}

.cc-nav-group + .cc-nav-group {
  margin-top: 0.75rem;
}

.cc-nav-group-label {
  padding: 0 1rem;
  margin-bottom: 0.375rem;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}

.cc-nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.cc-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-left: 3px solid transparent;
  color: var(--foreground);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.cc-nav-item:hover {
  background: var(--secondary);
}

.cc-nav-item.is-active {
  border-left-color: var(--primary);
  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%);
}

.cc-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.cc-nav-icon svg {
  width: 100%;
  height: 100%;
}

.cc-nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-nav-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  /* D20 precedent: light theme's white-on-destructive pair measured 3.8:1
     (below the 4.5:1 minimum) — deepened toward --foreground here rather
     than darkening the --destructive token itself, which drives components
     across all 66 pages. Dark theme already cleared 4.5:1, so it's restored
     to full brand saturation below rather than darkened blindly too. */
  background: color-mix(in srgb, var(--destructive) 70%, var(--foreground) 30%);
  color: var(--primary-foreground);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
}

html[data-theme="dark"] .cc-nav-badge {
  background: var(--destructive);
}

html[data-cc-sidebar="collapsed"] .cc-nav-badge {
  position: absolute;
  top: 0.25rem;
  right: 0.375rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.2rem;
  font-size: 0.625rem;
}

/* ---------- Footer / user menu ---------- */
.cc-rail-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 0.625rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.cc-user-menu {
  position: relative;
  flex: 1;
  min-width: 0;
}

.cc-user-trigger {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
}

.cc-user-trigger::-webkit-details-marker {
  display: none;
}

.cc-user-trigger:hover,
.cc-user-menu[open] .cc-user-trigger {
  background: var(--secondary);
}

.cc-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.cc-user-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.cc-user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-user-role {
  font-size: var(--text-xs);
  color: var(--muted);
}

.cc-user-dropdown {
  position: absolute;
  left: 0;
  right: -0.5rem;
  bottom: calc(100% + 0.5rem);
  min-width: 12rem;
  padding: 0.375rem;
  z-index: 60;
}

.cc-user-dropdown a,
.cc-user-dropdown button {
  all: unset;
  box-sizing: border-box;
  display: flex;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border-radius: 6px;
  font-size: var(--text-sm);
  color: var(--foreground);
  cursor: pointer;
}

.cc-user-dropdown a:hover,
.cc-user-dropdown button:hover {
  background: var(--secondary);
}

.cc-user-dropdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.3rem 0.25rem;
}

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

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

.cc-theme-toggle svg {
  width: 1.125rem;
  height: 1.125rem;
}

.cc-theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .cc-theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .cc-theme-toggle .icon-moon { display: inline-flex; }

/* ---------- Topbar ---------- */
.cc-topbar {
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-solid);
  position: sticky;
  top: 0;
  z-index: 40;
}

.cc-topbar-menu {
  all: unset;
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  color: var(--foreground);
  cursor: pointer;
}

.cc-topbar-menu svg {
  width: 1.25rem;
  height: 1.25rem;
}

.cc-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;
}

/* ---------- Chat FAB + drawer ---------- */
.cc-chat-fab {
  all: unset;
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 3.25rem;
  height: 3.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  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);
  z-index: 70;
}

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

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

.cc-chat-fab svg {
  width: 1.5rem;
  height: 1.5rem;
}

.cc-chat-drawer {
  position: fixed;
  right: 1.5rem;
  bottom: 5.5rem;
  width: min(24rem, calc(100vw - 3rem));
  max-height: min(32rem, calc(100vh - 8rem));
  display: flex;
  flex-direction: column;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 8px 24px rgba(15, 23, 42, 0.08),
    0 2px 6px rgba(15, 23, 42, 0.04);
  transform-origin: bottom right;
  transform: translateY(0.75rem) scale(0.96);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.18s ease, opacity 0.18s ease, visibility 0.18s;
  z-index: 71;
}

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

.cc-chat-drawer.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.cc-chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cc-chat-drawer-title {
  font-size: var(--text-sm);
  font-weight: 600;
}

.cc-chat-drawer-close {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}

.cc-chat-drawer-close:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.cc-chat-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .cc-rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px !important;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .cc-rail.is-mobile-open {
    transform: translateX(0);
  }

  html[data-cc-sidebar="collapsed"] .cc-nav-group-label,
  html[data-cc-sidebar="collapsed"] .cc-rail-brand-text {
    display: initial;
  }

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

  .cc-rail-collapse {
    display: none;
  }

  .cc-topbar-menu {
    display: inline-flex;
  }

  .cc-mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s;
    z-index: 49;
  }

  .cc-mobile-backdrop.is-open {
    opacity: 1;
    visibility: visible;
  }

  .cc-content {
    padding: 1rem;
  }

  .cc-chat-fab {
    right: 1rem;
    bottom: 1rem;
  }

  .cc-chat-drawer {
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    bottom: 4.75rem;
  }
}
