/* ═══════════════════════════════════════════════════════════════════
   Admin Breadcrumbs — thin top bar with back arrow + crumb trail.
   Designed restrained, Contra-style: muted by default, single weight,
   last segment slightly darker. No heavy chrome; the trail earns its
   space from whitespace + crisp separators, not boxes or shadows.
   ═══════════════════════════════════════════════════════════════════ */
.admin-breadcrumbs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 2rem 0;
  margin: 0;
}

.admin-breadcrumbs__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.admin-breadcrumbs__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9999px;
  color: oklch(var(--bc) / 0.55);
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.admin-breadcrumbs__back:hover {
  background: oklch(var(--bc) / 0.06);
  color: oklch(var(--bc));
  transform: translateX(-1px);
}

.admin-breadcrumbs__back:active {
  transform: translateX(-2px);
}

.admin-breadcrumbs__back svg {
  width: 1rem;
  height: 1rem;
  stroke-width: 1.75;
}

.admin-breadcrumbs__divider {
  width: 1px;
  height: 1rem;
  background: oklch(var(--bc) / 0.12);
  flex-shrink: 0;
}

.admin-breadcrumbs__trail {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  line-height: 1;
  min-width: 0;
  overflow: hidden;
  letter-spacing: -0.003em;
}

.admin-breadcrumbs__crumb {
  color: oklch(var(--bc) / 0.45);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.12s ease;
  padding: 0.25rem 0;
}

.admin-breadcrumbs__crumb:hover {
  color: oklch(var(--bc) / 0.9);
}

.admin-breadcrumbs__crumb--current {
  color: oklch(var(--bc) / 0.9);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.admin-breadcrumbs__sep {
  color: oklch(var(--bc) / 0.22);
  font-weight: 300;
  user-select: none;
  flex-shrink: 0;
  font-size: 0.875rem;
  line-height: 1;
}

.admin-breadcrumbs__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* When breadcrumbs are present, tighten the top of the main content so the
   bar and the page title form a cohesive header stack instead of double
   vertical padding. */
.admin-breadcrumbs + .admin-main__content {
  padding-top: 1.25rem;
}

@media (max-width: 768px) {
  .admin-breadcrumbs {
    padding: 0.875rem 1rem 0;
    gap: 0.5rem;
  }
  .admin-breadcrumbs__trail {
    font-size: 0.75rem;
    gap: 0.375rem;
  }
  .admin-breadcrumbs + .admin-main__content {
    padding-top: 0.875rem;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Admin Layout — sidebar navigation + main content area
   ═══════════════════════════════════════════════════════════════════ */

/* ── Client-page tabs ──
   DaisyUI's default tab-active is too subtle against the cream theme.
   Make the active tab visually distinct: bolder text, primary-colored
   underline, tighter hover feedback on inactive tabs. */
[role="tablist"].tabs.tabs-border .tab {
  color: oklch(var(--bc) / 0.55);
  transition: color 0.1s, border-color 0.1s;
  border-bottom: 2px solid transparent;
}
[role="tablist"].tabs.tabs-border .tab:hover {
  color: oklch(var(--bc) / 0.85);
}
[role="tablist"].tabs.tabs-border .tab.tab-active {
  color: oklch(var(--p));
  border-bottom-color: oklch(var(--p));
}

/* ── Sidebar ── */
.admin-sidebar {
  width: 13.5rem;
  min-height: 100vh;
  background: oklch(var(--b1));
  border-right: 1px solid oklch(var(--bc) / 0.08);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.15s ease;
}

.admin-sidebar--collapsed {
  width: 3.75rem;
}

.admin-sidebar__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0.75rem 0.75rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.06);
}

.admin-sidebar__logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  flex: 1;
  min-width: 0;
}

.admin-sidebar__logo-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  background: transparent;
  border: 2px solid oklch(var(--p));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
}

.admin-sidebar__logo-text {
  font-size: 1rem;
  font-weight: 700;
  color: oklch(var(--bc));
  white-space: nowrap;
}

.admin-sidebar__toggle {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: oklch(var(--bc) / 0.5);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s, transform 0.15s ease;
}

.admin-sidebar__toggle:hover {
  background: oklch(var(--bc) / 0.06);
  color: oklch(var(--bc));
}

.admin-sidebar__toggle svg {
  width: 1rem;
  height: 1rem;
}

/* ── Nav sections ── */
.admin-sidebar__nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.admin-sidebar__section {
  padding: 0.5rem 0;
}

.admin-sidebar__section-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: oklch(var(--bc) / 0.4);
  padding: 0.25rem 0.9rem 0.35rem;
  white-space: nowrap;
}

.admin-sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: oklch(var(--bc) / 0.7);
  padding: 0.4rem 0.9rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.admin-sidebar__link:hover {
  background: oklch(var(--bc) / 0.04);
  color: oklch(var(--bc));
}

.admin-sidebar__link--active {
  background: oklch(var(--p) / 0.08);
  color: oklch(var(--p));
  border-left-color: oklch(var(--p));
  font-weight: 600;
}

.admin-sidebar__link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

.admin-sidebar__link-icon svg {
  width: 100%;
  height: 100%;
}

.admin-sidebar__link-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-sidebar__link-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.4rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  color: oklch(var(--pc));
  background: oklch(var(--p));
}

/* ── Footer ── */
.admin-sidebar__footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid oklch(var(--bc) / 0.06);
}

.admin-sidebar__online-toggle-wrap {
  margin-bottom: 0.75rem;
}

.admin-sidebar__online-toggle-wrap form.button_to {
  margin: 0;
}

.admin-sidebar__online-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background 0.1s;
  cursor: pointer;
  border: none;
}

.admin-sidebar__online-toggle--online {
  background: oklch(var(--su) / 0.2);
  color: oklch(var(--su));
}

.admin-sidebar__online-toggle--offline {
  background: oklch(var(--bc) / 0.08);
  color: oklch(var(--bc) / 0.6);
}

.admin-sidebar__online-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 9999px;
  background: oklch(var(--bc) / 0.3);
  flex-shrink: 0;
}

.admin-sidebar__online-dot--on {
  background: oklch(var(--su));
  animation: admin-sidebar-pulse 2s ease-in-out infinite;
}

@keyframes admin-sidebar-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.admin-sidebar__online-hint {
  margin-left: auto;
  font-size: 0.7rem;
  opacity: 0.6;
  white-space: nowrap;
}

.admin-sidebar__back-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: oklch(var(--bc) / 0.5);
  text-decoration: none;
}

.admin-sidebar__back-link:hover {
  color: oklch(var(--bc));
}

.admin-sidebar__back-arrow {
  flex-shrink: 0;
}

/* ── Collapsed state ── */
.admin-sidebar--collapsed .admin-sidebar__logo-text,
.admin-sidebar--collapsed .admin-sidebar__section-label,
.admin-sidebar--collapsed .admin-sidebar__link-label,
.admin-sidebar--collapsed .admin-sidebar__online-label,
.admin-sidebar--collapsed .admin-sidebar__online-hint,
.admin-sidebar--collapsed .admin-sidebar__back-label {
  display: none;
}

.admin-sidebar--collapsed .admin-sidebar__toggle {
  transform: rotate(180deg);
}

.admin-sidebar--collapsed .admin-sidebar__header {
  flex-direction: column;
  gap: 0.5rem;
  /* Match the expanded header's horizontal padding so the logo icon's
     X position stays identical in both states — the brand anchor shouldn't
     drift sideways during the collapse transition. */
  padding: 1rem 0.75rem 0.75rem;
  align-items: flex-start;
}

.admin-sidebar--collapsed .admin-sidebar__logo {
  /* Pin the logo icon to the left edge (same as expanded), not centered. */
  justify-content: flex-start;
}

.admin-sidebar--collapsed .admin-sidebar__toggle {
  align-self: center;
}

.admin-sidebar--collapsed .admin-sidebar__section {
  padding: 0.35rem 0;
}

.admin-sidebar--collapsed .admin-sidebar__link {
  justify-content: center;
  padding: 0.5rem 0;
  border-left: none;
  border-right: 3px solid transparent;
}

.admin-sidebar-tooltip {
  position: fixed;
  z-index: 50;
  transform: translate(0.125rem, -50%);
  padding: 0.35rem 0.55rem;
  border-radius: 0.375rem;
  background: oklch(var(--bc) / 0.92);
  color: oklch(var(--b1));
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 0.5rem 1rem oklch(var(--bc) / 0.12);
}

.admin-sidebar--collapsed .admin-sidebar__link--active {
  border-left: none;
  border-right-color: oklch(var(--p));
}

.admin-sidebar--collapsed .admin-sidebar__link-badge {
  position: absolute;
  transform: translate(0.75rem, -0.5rem);
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.3rem;
  font-size: 0.6rem;
}

.admin-sidebar--collapsed .admin-sidebar__footer {
  padding: 0.75rem 0.5rem;
}

.admin-sidebar--collapsed .admin-sidebar__online-toggle {
  justify-content: center;
  padding: 0.5rem;
}

.admin-sidebar--collapsed .admin-sidebar__back-link {
  justify-content: center;
}

/* ── Main content area ── */
.admin-main {
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  overflow-y: auto;
}

.admin-main__content {
  padding: 2rem;
}

/* ── Dashboard stats ── */
.admin-dashboard__stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.admin-dashboard__stat-card {
  background: oklch(var(--b1));
  border: 1px solid oklch(var(--bc) / 0.06);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.admin-dashboard__stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: oklch(var(--bc));
}

.admin-dashboard__stat-label {
  font-size: 0.8rem;
  color: oklch(var(--bc) / 0.5);
  margin-top: 0.15rem;
}

.admin-dashboard__stat-detail {
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.4);
  margin-top: 0.35rem;
}

/* ── Mobile: collapse sidebar to top bar ── */
@media (max-width: 768px) {
  body.min-h-screen.flex {
    flex-direction: column;
  }

  .admin-sidebar,
  .admin-sidebar--collapsed {
    width: 100%;
    min-height: auto;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid oklch(var(--bc) / 0.08);
  }

  .admin-sidebar__toggle {
    display: none;
  }

  .admin-sidebar__nav {
    display: flex;
    overflow-x: auto;
    padding: 0.5rem;
    gap: 0.25rem;
  }

  .admin-sidebar__section {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
  }

  .admin-sidebar__section-label {
    display: none;
  }

  .admin-sidebar__link {
    white-space: nowrap;
    padding: 0.35rem 0.75rem;
    border-left: none;
    border-radius: 9999px;
    font-size: 0.75rem;
  }

  .admin-sidebar__link--active {
    border-left: none;
  }

  .admin-sidebar__footer {
    display: none;
  }

  .admin-main__content {
    padding: 1rem;
  }

  /* Mobile falls back to a horizontal top bar, so the desktop-collapsed
     icon-only styling shouldn't apply. Restore the pill + label layout
     regardless of whether the user previously collapsed the sidebar on
     desktop. */
  .admin-sidebar--collapsed .admin-sidebar__header {
    flex-direction: row;
    padding: 1rem 0.75rem 0.75rem;
  }

  .admin-sidebar--collapsed .admin-sidebar__logo {
    justify-content: flex-start;
  }

  .admin-sidebar--collapsed .admin-sidebar__logo-text,
  .admin-sidebar--collapsed .admin-sidebar__link-label {
    display: inline;
  }

  .admin-sidebar--collapsed .admin-sidebar__link {
    justify-content: flex-start;
    padding: 0.35rem 0.75rem;
    border-right: none;
  }

  .admin-sidebar--collapsed .admin-sidebar__link-badge {
    position: static;
    transform: none;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.4rem;
    font-size: 0.7rem;
  }

  .admin-sidebar--collapsed .admin-sidebar__section {
    padding: 0;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Brain Chat Fullscreen
   Overlay the brain chat card on top of the viewport. Toggled by a
   Stimulus controller; state lives only on the element + body, so
   chat history + input stay alive across toggles.
   ═══════════════════════════════════════════════════════════════════ */
.brain-chat--fullscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  margin: 0 !important;
  border-radius: 0;
  border-left: none;
  border-right: none;
  padding: 0.75rem clamp(1rem, 5vw, 3rem);
  background: var(--cream-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tighten internal spacing so the chat transcript gets as much vertical
   real estate as possible when overlaid fullscreen. */
.brain-chat--fullscreen > .flex.items-start {
  margin-bottom: 0.5rem;
}
.brain-chat--fullscreen .brain-chat-card__messages {
  margin-bottom: 0.5rem;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}
.brain-chat--fullscreen #brain-chat-form p {
  margin-top: 0.25rem;
}

/* Lock underlying page scroll while the overlay is open */
.brain-chat-fullscreen-body {
  overflow: hidden;
}

/* Expand messages area to fill available height when overlaid */
.brain-chat--fullscreen .brain-chat-card__messages {
  max-height: none !important;
  flex: 1 1 auto;
  min-height: 0;
}

/* Swap the expand/collapse icon + label on state change */
.brain-chat--fullscreen .brain-chat-card__expand-icon,
.brain-chat--fullscreen .brain-chat-card__expand-label {
  display: none;
}
.brain-chat--fullscreen .brain-chat-card__collapse-icon,
.brain-chat--fullscreen .brain-chat-card__collapse-label {
  display: inline-flex;
}
.brain-chat-card__collapse-label {
  display: none;
}
