/* ───────────────────────────────────────────────────────────────────
   agent-shell.css — optional overlay + optional live-log side panel.

   Prior versions of this file imposed a full split-pane "command shell"
   on every admin page (status bar, stream log, canvas, command prompt
   at the bottom). That was too prominent. Now it's one thing: a
   Cmd+K command palette (a real IDE affordance) plus a small
   collapsible activity log for pages that have streaming work.

   Form styles, cards, buttons etc. come from admin.css + design-system.
   Nothing here overrides those — it only adds.
   ─────────────────────────────────────────────────────────────────── */

/* ─── Optional top-of-main status strip ─────────────────────────── */

.shell-grid {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.shell-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}

.shell-status-brand {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.shell-status-brand::before {
  content: "$";
  margin-right: 0.4rem;
  color: var(--accent);
}

.shell-status-state {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 2px 8px;
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-transform: lowercase;
}
.shell-status-state::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
}
.shell-status-state[data-state="draft"]::before     { background: var(--text-muted); }
.shell-status-state[data-state="ready"]::before     { background: var(--accent); }
.shell-status-state[data-state="deploying"]::before { background: var(--signal); animation: pulse-signal 1.5s infinite; }
.shell-status-state[data-state="live"]::before      { background: var(--ok); }
.shell-status-state[data-state="error"]::before     { background: var(--danger); }
.shell-status-state[data-state="ready"]     { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-ring); }
.shell-status-state[data-state="deploying"] { color: var(--signal); background: var(--signal-soft); border-color: rgba(249,115,22,.28); }
.shell-status-state[data-state="live"]      { color: var(--ok);     background: var(--ok-soft);     border-color: rgba(52,211,153,.28); }
.shell-status-state[data-state="error"]     { color: var(--danger); background: var(--danger-soft); border-color: rgba(248,113,113,.28); }

.shell-status-meta {
  color: var(--text-muted);
  display: flex;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
}
.shell-status-meta > * {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-status-actions { display: flex; gap: 0.375rem; }

/* ─── Canvas (main content) ─────────────────────────────────────── */

.shell-canvas {
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
  flex: 1;
}
.builder-canvas { max-width: 760px; }

/* ─── Optional activity log — collapsed by default ─────────────── */

.shell-stream {
  background: #050506;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text-dim);
  max-height: 180px;
  overflow-y: auto;
  padding: 0.625rem 1.25rem;
  display: none;
}
.shell-grid[data-stream-open="true"] .shell-stream { display: block; }

.stream-line {
  display: grid;
  grid-template-columns: 1.2em 1fr;
  gap: 6px;
  padding: 1px 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.stream-line[data-role="user"]    { color: var(--text); }
.stream-line[data-role="agent"]   { color: var(--accent); }
.stream-line[data-role="tool"]    { color: var(--purple); }
.stream-line[data-role="system"]  { color: var(--text-muted); }
.stream-line[data-level="done"]   { color: var(--ok); }
.stream-line[data-level="warn"]   { color: var(--warn); }
.stream-line[data-level="error"]  { color: var(--danger); }
.stream-icon { color: inherit; opacity: 0.7; font-weight: 500; user-select: none; }
.stream-meta { color: var(--text-muted); font-size: 0.6875rem; margin-left: 0.4em; }

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
}
.thinking-indicator::before {
  content: "▋";
  animation: shell-blink 1s steps(2, start) infinite;
}
@keyframes shell-blink { to { visibility: hidden; } }

/* ─── Retired: command-bar at the bottom. Hidden; functionality  ─
     lives in the Cmd+K palette. Kept as display:none so any pages
     still rendering the markup don't blow out the layout. */
.shell-command { display: none; }

/* ─── Command palette (global Cmd+K) ──────────────────────────── */

.command-palette {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
.command-palette[hidden] { display: none; }

.command-palette-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 8, 0.7);
  backdrop-filter: blur(6px);
}
.command-palette-dialog {
  position: relative;
  width: min(560px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-hov);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--accent-ring);
  overflow: hidden;
}
.command-palette-input {
  width: 100%;
  padding: 0.875rem 1.125rem;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.command-palette-input:focus { box-shadow: none; }
.command-palette-list {
  list-style: none;
  margin: 0;
  padding: 0.375rem 0;
  max-height: 45vh;
  overflow-y: auto;
}
.command-palette-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1.125rem;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--text);
}
.command-palette-item:hover,
.command-palette-item[aria-selected="true"] {
  background: var(--accent-soft);
}
.command-palette-item-name  {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.72rem;
}
.command-palette-item-label { color: var(--text); flex: 1; padding: 0 0.75rem; }
.command-palette-item-hint  {
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-family: var(--font-mono);
}
.command-palette-empty {
  padding: 1.125rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.command-palette-footer {
  padding: 0.5rem 1.125rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  display: flex;
  gap: 0.875rem;
}

/* ── Topbar user pill ──────────────────────────────────────────
   Populated by agent-shell.js hydrateTopbarUser() after CombobAuth
   resolves. Sits on the far right of the shared topbar so every
   page shows the signed-in user + sign-out without each page
   rendering its own .user-pill. */
.topbar-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
}
.topbar-user-pill strong {
  font-weight: 600;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user-pill .topbar-signout {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0 4px;
  font-family: inherit;
}
.topbar-user-pill .topbar-signout:hover { color: var(--text); }

/* ── Topbar user dropdown + profile modal ────────────────────────
   Injected by agent-shell.js::toggleUserMenu() / ensureProfileModal().
   Kept here so the markup (which lives in JS) can rely on design-
   system tokens without shipping inline style attributes. */
.topbar-user-menu {
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 4px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  font-size: 0.82rem;
}
.topbar-user-menu[hidden] { display: none; }
.topbar-user-menu-item {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}
.topbar-user-menu-item:hover { background: var(--bg-elev); }

.topbar-caret { font-size: 0.88rem; line-height: 1; padding: 0 4px; }

/* ── Profile modal ─────────────────────────────────────────────── */
.profile-modal-overlay {
  position: fixed; inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.profile-modal-overlay[hidden] { display: none; }
.profile-modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  padding: 22px 24px;
  width: 100%;
  max-width: 420px;
  color: var(--text);
  font-family: var(--font-sans);
}
.profile-modal-box h3 { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.profile-modal-intro {
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.5;
  margin-bottom: 14px;
}
.profile-modal-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.profile-modal-input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
}
.profile-modal-input:focus { border-color: var(--accent); }
.profile-modal-err {
  color: var(--danger);
  font-size: 0.78rem;
  padding: 6px 10px;
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.profile-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ─── Slim topbar (post-sidebar layout) ──────────────────────────
   The segmented app-switcher + user pill moved out of the topbar
   and into the sidebar. The topbar now just hosts an optional
   context label on the left and Cmd+K + page-specific actions on
   the right. .dc-topbar-context takes the leading flex so the
   right-side group pins to the far end. */
.dc-topbar-slim .dc-topbar-context {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

/* ─── Global app layout: left sidebar + main ─────────────────────
   Applied site-wide (demos, videos, voice, admin). Pages that opt
   in wrap their body content in <div class="app-layout"> and
   <main class="app-main">, and include templates/_sidebar.html.
   The slim topbar can be included above the grid or omitted
   entirely — sidebar brand stands in for it. */

.app-layout {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-areas: "sidebar main";
  min-height: 100vh;
}
.app-sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.app-main {
  grid-area: main;
  overflow-y: auto;
  min-width: 0;
}

.sidebar-brand {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
}
.sidebar-brand-link:hover { color: var(--text); text-decoration: none; }
.sidebar-brand-mark {
  width: 22px; height: 22px;
  background: var(--accent);
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand-mark img { width: 14px; height: 14px; display: block; }

.sidebar-nav {
  flex: 1;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.sidebar-section { display: flex; flex-direction: column; gap: 1px; }

/* The section title is both the section heading AND the "Library" link
   for that app. Styled small-caps and muted so it reads as a header;
   hover/active states give it clickability cues without turning it
   into a nav-item look-alike. */
.sidebar-section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px 6px;
  margin: 0;
}
a.sidebar-section-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color .12s, background .12s;
}
a.sidebar-section-link:hover {
  color: var(--text);
  background: var(--bg-elev);
  text-decoration: none;
}
a.sidebar-section-link.active {
  color: var(--text);
  background: var(--bg-elev);
  box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar-section-label { flex: 1; min-width: 0; }
.sidebar-section-count {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.6875rem;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--bg-elev);
}

/* Recent-items list inside each section. Populated by
   agent-shell.js::hydrateSidebarRecents; items map to demo / project /
   voice rows and link into that record's detail page. */
.sidebar-recent { display: flex; flex-direction: column; gap: 1px; padding: 2px 0 4px; }
.sidebar-recent-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.625rem 0.3rem 1.5rem; /* extra left indent so recents sit under the header */
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.78rem;
  transition: background .12s, color .12s;
  min-width: 0;
}
.sidebar-recent-item:hover { color: var(--text); background: var(--bg-elev); text-decoration: none; }
.sidebar-recent-item .ri-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.sidebar-recent-item .ri-dot {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 0.6rem;
}
.sidebar-recent-empty {
  padding: 0.3rem 0.625rem 0.3rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-style: italic;
}
.sidebar-recent-more {
  padding: 0.25rem 0.625rem 0.25rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.72rem;
}
.sidebar-recent-more:hover { color: var(--text); text-decoration: none; }

/* Action + guide: visually distinct from recents — aligned with
   section title, subtle icon, same .nav-item chrome. */
.app-sidebar .nav-item.sidebar-action { margin-top: 2px; }
.app-sidebar .nav-item.sidebar-guide {
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.3rem 0.625rem;
}
.app-sidebar .nav-item.sidebar-guide .nav-icon { font-size: 0.75rem; }

.app-sidebar .nav-item.sidebar-subnav {
  padding: 0.3rem 0.625rem 0.3rem 1.5rem;
  font-size: 0.78rem;
}

/* Reuse existing .nav-item / .nav-icon rules from admin.css when
   admin.css is loaded; otherwise, provide the same styles here so
   the sidebar looks identical on pages that don't include admin.css. */
.app-sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.625rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: background .12s, color .12s, box-shadow .12s;
}
.app-sidebar .nav-item:hover { color: var(--text); background: var(--bg-elev); }
.app-sidebar .nav-item.active {
  color: var(--text);
  background: var(--bg-elev);
  box-shadow: inset 2px 0 0 var(--accent);
}
.app-sidebar .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.app-sidebar .nav-item.active .nav-icon { color: var(--accent); }

/* Sidebar footer — anchors the Cmd+K search trigger at the bottom. The
   user profile pill moved back to the topbar-right per design request,
   so this row is search-only. */
.sidebar-footer {
  padding: 10px 10px 14px;
  border-top: 1px solid var(--border);
}
.sidebar-search {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.76rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: color .12s, border-color .12s;
}
.sidebar-search:hover { color: var(--text); border-color: var(--border-hov); }
.sidebar-search-icon { color: var(--text-muted); }
.sidebar-search kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 1px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
}

/* Mobile: collapse sidebar above the main content rather than hiding
   the nav outright. Pages that want different behavior can override. */
@media (max-width: 800px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "sidebar" "main";
  }
  .app-sidebar {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav { gap: 8px; }
}
