/*
 * Universal app shell — persistent left sidebar + workspace switcher +
 * global search. Injected on every v1 page via app-shell.js.
 *
 * Existing pages keep their per-page header + content; the shell adds:
 *   • Fixed left sidebar (icon-only at 56px; expands to 220px on hover/click)
 *   • Pinned workspace switcher at the top of the sidebar
 *   • Global search overlay triggered by ⌘K (mac) / Ctrl+K (win) or click
 *   • Body left-margin reserved for the sidebar so existing layouts don't shift
 */

:root {
  --shell-collapsed: 56px;
  --shell-expanded: 240px;
  --shell-bg: hsl(220 14% 12%);
  --shell-fg: hsl(220 10% 88%);
  --shell-fg-muted: hsl(220 10% 60%);
  --shell-border: hsl(220 14% 20%);
  --shell-active: hsl(210 90% 55%);
  --shell-hover: hsl(220 14% 18%);
}

body {
  margin-left: var(--shell-collapsed);
  transition: margin-left 0.18s ease;
}
body.shell-expanded { margin-left: var(--shell-expanded); }

/* Sidebar ─────────────────────────────────────────────────────────────── */
#app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--shell-collapsed);
  background: var(--shell-bg);
  color: var(--shell-fg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: width 0.18s ease;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
}
#app-sidebar.expanded { width: var(--shell-expanded); }

.shell-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--shell-border);
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}
.shell-brand-mark {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, hsl(210 90% 55%), hsl(280 80% 60%));
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 13px;
}
.shell-brand-text {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-brand-text { opacity: 1; }

/* Workspace switcher */
.shell-workspace {
  padding: 10px 12px;
  border-bottom: 1px solid var(--shell-border);
  flex-shrink: 0;
}
.shell-workspace-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--shell-fg-muted);
  margin-bottom: 4px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-workspace-label { opacity: 1; }
.shell-workspace-current {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 5px;
  background: var(--shell-hover);
  color: var(--shell-fg);
  white-space: nowrap;
  overflow: hidden;
}
.shell-workspace-current:hover { background: hsl(220 14% 22%); }
.shell-workspace-icon {
  width: 22px; height: 22px;
  border-radius: 4px;
  background: hsl(210 90% 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.shell-workspace-name {
  font-weight: 600;
  font-size: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-workspace-name { opacity: 1; }
.shell-workspace-arrow {
  color: var(--shell-fg-muted);
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-workspace-arrow { opacity: 1; }

/* Workspace dropdown */
.shell-workspace-dropdown {
  position: absolute;
  top: 60px;
  left: 12px;
  width: 240px;
  max-height: 400px;
  background: hsl(220 14% 16%);
  border: 1px solid var(--shell-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow-y: auto;
  z-index: 110;
  padding: 4px;
}
.shell-workspace-dropdown.hidden { display: none; }
.shell-workspace-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--shell-fg);
  font-size: 12px;
}
.shell-workspace-option:hover { background: var(--shell-hover); }
.shell-workspace-option.active { background: hsl(210 90% 22%); color: white; }
.shell-workspace-option .meta { color: var(--shell-fg-muted); font-size: 10px; }

/* Search trigger */
.shell-search {
  padding: 8px 12px;
  flex-shrink: 0;
}
.shell-search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  background: var(--shell-hover);
  color: var(--shell-fg-muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}
.shell-search-trigger:hover { background: hsl(220 14% 22%); color: var(--shell-fg); }
.shell-search-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shell-search-text {
  flex: 1;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-search-text { opacity: 1; }
.shell-search-kbd {
  font-family: ui-monospace, monospace;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  background: hsl(220 14% 22%);
  border: 1px solid hsl(220 14% 28%);
  color: var(--shell-fg-muted);
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-search-kbd { opacity: 1; }

/* Nav */
.shell-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.shell-nav-section {
  margin-bottom: 12px;
}
.shell-nav-section-title {
  padding: 6px 16px 4px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--shell-fg-muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-nav-section-title { opacity: 1; }
.shell-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
  color: var(--shell-fg);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  border-left: 3px solid transparent;
  position: relative;
}
.shell-nav-item:hover { background: var(--shell-hover); color: white; }
.shell-nav-item.active {
  background: hsl(210 90% 22% / 0.5);
  border-left-color: var(--shell-active);
  color: white;
  font-weight: 600;
}
.shell-nav-icon {
  width: 18px; height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}
.shell-nav-label {
  flex: 1;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-nav-label { opacity: 1; }
.shell-nav-tooltip {
  /* Shown on hover when collapsed */
  display: none;
  position: absolute;
  left: calc(var(--shell-collapsed) + 4px);
  top: 50%;
  transform: translateY(-50%);
  background: hsl(220 14% 8%);
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 200;
}
#app-sidebar:not(.expanded) .shell-nav-item:hover .shell-nav-tooltip { display: block; }

/* User menu at bottom */
.shell-user {
  padding: 12px;
  border-top: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 12px;
}
.shell-user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: hsl(280 60% 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}
.shell-user-info {
  flex: 1;
  min-width: 0;
  opacity: 0;
  transition: opacity 0.15s 0.05s;
}
#app-sidebar.expanded .shell-user-info { opacity: 1; }
.shell-user-info .name { color: var(--shell-fg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shell-user-info .email { color: var(--shell-fg-muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Search overlay ──────────────────────────────────────────────────────── */
#shell-search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 20px 20px;
}
#shell-search-overlay.hidden { display: none; }
.shell-search-modal {
  width: 100%;
  max-width: 640px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 100px);
}
.shell-search-input-wrap {
  padding: 14px 18px;
  border-bottom: 1px solid hsl(220 14% 90%);
  display: flex;
  align-items: center;
  gap: 10px;
}
.shell-search-input-wrap input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  border: none;
  outline: none;
  background: transparent;
  color: hsl(222 84% 5%);
}
.shell-search-input-wrap .esc {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  background: hsl(220 14% 95%);
  border: 1px solid hsl(220 14% 88%);
  color: hsl(220 10% 40%);
}
.shell-search-results {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}
.shell-search-section {
  padding: 6px 0;
  border-top: 1px solid hsl(220 14% 95%);
}
.shell-search-section:first-child { border-top: none; }
.shell-search-section-title {
  padding: 4px 18px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(220 10% 50%);
  font-weight: 600;
}
.shell-search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  cursor: pointer;
  text-decoration: none;
  color: hsl(222 84% 5%);
  font-size: 13px;
}
.shell-search-result:hover, .shell-search-result.active {
  background: hsl(210 90% 96%);
}
.shell-search-result-icon {
  width: 24px; height: 24px;
  border-radius: 4px;
  background: hsl(220 14% 95%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}
.shell-search-result-body {
  flex: 1;
  min-width: 0;
}
.shell-search-result-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-search-result-meta {
  font-size: 11px;
  color: hsl(220 10% 50%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-search-empty {
  padding: 30px 20px;
  text-align: center;
  color: hsl(220 10% 50%);
  font-size: 13px;
  font-style: italic;
}
