/* Membrane Agency — Design Tokens */
:root {
  /* Neutrals — Linear-style 3-tier: sidebar / canvas / elevated
     sidebar (recessed chrome) -> canvas (off-white workspace) -> elevated (white cards) */
  --bg-sidebar: #f4f5f8;
  --bg: #f7f8f9;
  --bg-elevated: #ffffff;
  --bg-hover: rgba(15, 23, 31, 0.04);
  --bg-active: rgba(15, 23, 31, 0.06);
  --bg-pressed: rgba(15, 23, 31, 0.08);

  --border: rgba(15, 23, 31, 0.08);
  --border-strong: rgba(15, 23, 31, 0.14);
  --border-focus: oklch(0.55 0.10 180);

  --fg: #1a1f24;
  --fg-secondary: #5b6168;
  --fg-tertiary: #8a8f96;
  --fg-disabled: #b4b8bd;

  /* Accent — teal */
  --accent: oklch(0.55 0.10 180);
  --accent-hover: oklch(0.50 0.10 180);
  --accent-bg: oklch(0.96 0.02 180);
  --accent-border: oklch(0.85 0.05 180);

  /* Status */
  --success: oklch(0.62 0.13 150);
  --warning: oklch(0.72 0.13 80);
  --danger: oklch(0.58 0.18 25);

  /* Type */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-18: 18px;
  --fs-22: 22px;

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 12px;

  /* Shadows */
  --shadow-popover: 0 1px 2px rgba(15,23,31,0.04), 0 4px 12px rgba(15,23,31,0.08), 0 0 0 1px rgba(15,23,31,0.06);
  --shadow-modal: 0 8px 32px rgba(15,23,31,0.16), 0 0 0 1px rgba(15,23,31,0.08);

  /* Layout */
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 48px;
  --topbar-h: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  letter-spacing: -0.005em;
  overflow: hidden;
}
button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
input { font-family: inherit; font-size: inherit; color: inherit; }

/* App layout — Linear-style inset main pane */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
  background: var(--bg-sidebar);
}

/* ========== SIDEBAR ========== */
.sidebar {
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  user-select: none;
  padding-top: 8px;
}

/* Theme switcher (temporary) */
.theme-switcher { position: relative; padding: 6px 8px; border-top: 1px dashed var(--border); }
.theme-trigger {
  width: 100%; display: flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 8px;
  border-radius: var(--r-md);
  font-size: 11px; color: var(--fg-secondary);
}
.theme-trigger:hover { background: var(--bg-hover); color: var(--fg); }
.theme-swatches { display: inline-flex; gap: 0; flex-shrink: 0; }
.theme-swatch-sm {
  width: 8px; height: 14px; display: inline-block;
  border: 1px solid rgba(15,23,31,0.1);
  margin-right: -1px;
}
.theme-swatch-sm:first-child { border-radius: 2px 0 0 2px; }
.theme-swatch-sm:last-child { border-radius: 0 2px 2px 0; }
.theme-label {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; text-align: left;
  font-feature-settings: 'tnum'; font-weight: 500;
}
.theme-popover {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 8px; right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-popover);
  padding: 6px;
  z-index: 50;
}
.theme-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: var(--r-sm);
  font-size: 12px; color: var(--fg);
}
.theme-item:hover { background: var(--bg-hover); }
.theme-item[data-active="true"] { background: var(--accent-bg); }
.theme-pair {
  display: inline-flex; flex-shrink: 0;
  border-radius: 4px; overflow: hidden;
  border: 1px solid rgba(15,23,31,0.1);
  width: 28px; height: 16px;
}
.theme-pair-sb { width: 10px; height: 100%; display: inline-block; }
.theme-pair-bg { flex: 1; height: 100%; display: inline-block; }
.theme-name { flex: 1; text-align: left; }

.ws-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  height: 44px;
  position: relative;
}
.ws-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 4px 6px 4px 4px;
  border-radius: var(--r-md);
  height: 28px;
}
.ws-trigger:hover { background: var(--bg-hover); }
.ws-mark {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: linear-gradient(135deg, oklch(0.55 0.10 180), oklch(0.45 0.10 200));
  display: grid;
  place-items: center;
  color: white;
  font-weight: 600;
  font-size: 11px;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
.ws-name {
  font-size: var(--fs-13);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  text-align: left;
}
.ws-chev { color: var(--fg-tertiary); flex-shrink: 0; }

.collapse-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  color: var(--fg-tertiary);
  flex-shrink: 0;
}
.collapse-btn:hover { background: var(--bg-hover); color: var(--fg-secondary); }

/* Sidebar nav */
.nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-section-label {
  font-size: var(--fs-11);
  font-weight: 500;
  color: var(--fg-tertiary);
  letter-spacing: 0.02em;
  padding: 12px 8px 4px;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 28px;
  padding: 0 8px;
  border-radius: var(--r-md);
  color: var(--fg-secondary);
  font-size: var(--fs-13);
  font-weight: 500;
  width: 100%;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--fg); }
.nav-item[data-active="true"] {
  background: var(--bg-active);
  color: var(--fg);
  font-weight: 600;
}
.nav-item .icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--fg-tertiary); }
.nav-item:hover .icon, .nav-item[data-active="true"] .icon { color: var(--fg-secondary); }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .badge {
  font-size: var(--fs-11);
  color: var(--fg-tertiary);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.nav-item .kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-tertiary);
  opacity: 0;
  transition: opacity 100ms;
}
.nav-item:hover .kbd { opacity: 1; }

/* (Collapse + expand-rail behavior removed — sidebar is fixed-width Linear-style.) */
.collapse-btn, .expand-rail-btn { display: none !important; }

/* Account */
.account {
  padding: 6px;
  position: relative;
}
.acc-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 4px 6px 4px 4px;
  border-radius: var(--r-md);
}
.acc-trigger:hover { background: var(--bg-hover); }
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, oklch(0.65 0.10 30), oklch(0.55 0.13 15));
  color: white;
  font-size: 10px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  letter-spacing: 0;
}
.acc-text { display: flex; flex-direction: column; flex: 1; min-width: 0; align-items: flex-start; line-height: 1.25; }
.acc-name {
  font-size: var(--fs-13);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: left;
}
.acc-meta {
  font-size: var(--fs-11);
  color: var(--fg-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: left;
}
.acc-cog {
  color: var(--fg-tertiary);
  width: 22px;
  height: 22px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.acc-cog:hover { background: var(--bg-pressed); color: var(--fg-secondary); }

/* ========== MAIN ========== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  margin: 8px 8px 8px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15,23,31,0.04);
}
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px 0 16px;
  gap: 8px;
  flex-shrink: 0;
}
.crumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-13);
  flex: 1;
  min-width: 0;
}
.crumb {
  padding: 3px 6px;
  border-radius: var(--r-sm);
  color: var(--fg-secondary);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.crumb:hover { background: var(--bg-hover); color: var(--fg); }
.crumb.current { color: var(--fg); font-weight: 500; }
.crumb-sep { color: var(--fg-tertiary); font-size: 12px; user-select: none; }
.crumb .icon { width: 14px; height: 14px; color: var(--fg-tertiary); }

/* Content */
.content {
  flex: 1;
  overflow: auto;
  padding: 32px 40px;
}

/* Skeleton */
.skeleton-page { max-width: 920px; }
.sk {
  background: linear-gradient(90deg, rgba(15,23,31,0.05) 0%, rgba(15,23,31,0.09) 50%, rgba(15,23,31,0.05) 100%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.6s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.sk-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sk-h1 { height: 28px; width: 240px; margin-bottom: 12px; }
.sk-sub { height: 14px; width: 380px; margin-bottom: 28px; }
.sk-toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.sk-pill { height: 26px; border-radius: 13px; }
.sk-circle { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; }
.sk-line { height: 12px; }

/* ========== POPOVER (workspace switcher) ========== */
.popover {
  position: absolute;
  top: 44px;
  left: 8px;
  width: 264px;
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-popover);
  padding: 6px;
  z-index: 50;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  pointer-events: none;
  transform-origin: top left;
  transition: opacity 120ms, transform 120ms;
}
.popover[data-open="true"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.pop-label {
  font-size: var(--fs-11);
  color: var(--fg-tertiary);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 6px 8px 4px;
}
.pop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--r-md);
  text-align: left;
  font-size: var(--fs-13);
}
.pop-item:hover { background: var(--bg-hover); }
.pop-item .check { color: var(--accent); margin-left: auto; }
.pop-divider { height: 1px; background: var(--border); margin: 4px 0; }
.pop-meta { font-size: var(--fs-11); color: var(--fg-tertiary); }
.pop-stack { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.pop-stack .name { font-weight: 500; }

/* Account popover */
.acc-popover {
  position: absolute;
  bottom: 56px;
  left: 8px;
  width: 240px;
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-popover);
  padding: 6px;
  z-index: 50;
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  pointer-events: none;
  transform-origin: bottom left;
  transition: opacity 120ms, transform 120ms;
}
.acc-popover[data-open="true"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.acc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.acc-header .name { font-weight: 600; font-size: var(--fs-13); }
.acc-header .email { font-size: var(--fs-11); color: var(--fg-tertiary); }

/* ========== CMD+K ========== */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 31, 0.32);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.cmdk-overlay[data-open="true"] { display: flex; }
.cmdk {
  width: 560px;
  max-width: calc(100vw - 32px);
  background: var(--bg-elevated);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: cmdk-in 140ms cubic-bezier(0.2, 0, 0, 1);
}
@keyframes cmdk-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.cmdk-input {
  width: 100%;
  height: 48px;
  padding: 0 16px 0 44px;
  border: none;
  outline: none;
  font-size: var(--fs-15);
  background: transparent;
  border-bottom: 1px solid var(--border);
}
.cmdk-input::placeholder { color: var(--fg-tertiary); }
.cmdk-search-icon {
  position: absolute;
  left: 16px;
  top: 16px;
  color: var(--fg-tertiary);
  pointer-events: none;
}
.cmdk-input-wrap { position: relative; }
.cmdk-list { max-height: 360px; overflow-y: auto; padding: 6px; }
.cmdk-section-label {
  font-size: var(--fs-11);
  color: var(--fg-tertiary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 8px 8px 4px;
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  font-size: var(--fs-13);
  text-align: left;
  color: var(--fg);
}
.cmdk-item[data-active="true"] { background: var(--bg-active); }
.cmdk-item .icon { color: var(--fg-tertiary); }
.cmdk-item[data-active="true"] .icon { color: var(--fg-secondary); }
.cmdk-item .ctx { color: var(--fg-tertiary); margin-left: auto; font-size: var(--fs-12); }
.cmdk-empty { padding: 24px; text-align: center; color: var(--fg-tertiary); font-size: var(--fs-13); }
.cmdk-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
  font-size: var(--fs-11);
  color: var(--fg-tertiary);
}
.kbd-key {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-secondary);
  margin: 0 2px;
}

/* Tooltip on collapsed nav */
.tooltip {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  background: #1a1f24;
  color: white;
  font-size: var(--fs-12);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms 200ms;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tooltip .kbd-key {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7);
}
.app[data-collapsed="true"] .nav-item:hover .tooltip { opacity: 1; }
.app:not([data-collapsed="true"]) .tooltip { display: none; }
