/* ─────────────────────────────────────────────────────────────
   BRAND VOICE ARCHITECTURE — DESIGN SYSTEM
   HSL token system mirrored from /opt/melvinos/client/src/index.css.
   Light, dark, and system modes. Inter + Space Grotesk + ui-monospace.
   ───────────────────────────────────────────────────────────── */

/* ── DARK MODE (default + explicit .dark on <html>) ────────── */
:root,
html.dark {
  --background:      222 47% 5%;
  --foreground:      210 40% 96%;
  --border:          217 32% 14%;
  --input:           217 32% 16%;

  --card:            220 40% 8%;
  --card-foreground: 210 40% 96%;
  --card-border:     217 32% 15%;

  --sidebar:         222 47% 6%;
  --sidebar-foreground: 210 40% 92%;
  --sidebar-border:  217 32% 12%;

  --popover:         220 40% 9%;
  --popover-foreground: 210 40% 96%;
  --popover-border:  217 32% 16%;

  --primary:         217 91% 60%;
  --primary-foreground: 222 47% 5%;
  --secondary:       220 40% 12%;
  --secondary-foreground: 210 40% 90%;
  --accent-violet:   262 83% 68%;

  --muted:           220 30% 12%;
  --muted-foreground: 215 20% 60%;
  --accent:          220 40% 14%;
  --accent-foreground: 210 40% 96%;

  --destructive:     0 84% 60%;
  --destructive-foreground: 210 40% 98%;
  --success:         142 71% 45%;
  --warn:            38 92% 50%;
  --ring:            217 91% 60%;

  --grid-line: rgba(110, 168, 255, 0.08);
  --glow-1: rgba(59, 130, 246, 0.18);
  --glow-2: rgba(168, 85, 247, 0.18);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Space Grotesk", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: ui-monospace, "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
  --radius: 12px;
  --radius-sm: 8px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.4), 0 12px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.5), 0 24px 40px rgba(0,0,0,0.3);

  --sidebar-w: 280px;
  --topbar-h: 56px;

  color-scheme: dark;
}

/* ── LIGHT MODE ───────────────────────────────────────────── */
html.light {
  --background:      210 20% 98%;
  --foreground:      222 47% 10%;
  --border:          210 30% 88%;
  --input:           210 30% 84%;

  --card:            0 0% 100%;
  --card-foreground: 222 47% 10%;
  --card-border:     210 30% 90%;

  --sidebar:         210 20% 96%;
  --sidebar-foreground: 222 47% 10%;
  --sidebar-border:  210 30% 86%;

  --popover:         0 0% 100%;
  --popover-foreground: 222 47% 10%;
  --popover-border:  210 30% 88%;

  --primary:         217 91% 55%;
  --primary-foreground: 0 0% 100%;
  --secondary:       210 20% 92%;
  --secondary-foreground: 222 47% 12%;
  --accent-violet:   262 83% 58%;

  --muted:           210 20% 90%;
  --muted-foreground: 215 15% 38%;
  --accent:          210 20% 86%;
  --accent-foreground: 222 47% 10%;

  --destructive:     0 84% 55%;
  --destructive-foreground: 0 0% 100%;
  --success:         142 71% 38%;
  --warn:            32 95% 44%;
  --ring:            217 91% 55%;

  --grid-line: rgba(59, 130, 246, 0.06);
  --glow-1: rgba(59, 130, 246, 0.12);
  --glow-2: rgba(168, 85, 247, 0.12);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.06), 0 12px 24px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.08), 0 24px 40px rgba(0,0,0,0.1);

  color-scheme: light;
}

/* ── SYSTEM MODE — resolve via OS when no explicit class set ─ */
@media (prefers-color-scheme: light) {
  html.system {
    --background:      210 20% 98%;
    --foreground:      222 47% 10%;
    --border:          210 30% 88%;
    --input:           210 30% 84%;
    --card:            0 0% 100%;
    --card-foreground: 222 47% 10%;
    --card-border:     210 30% 90%;
    --sidebar:         210 20% 96%;
    --sidebar-foreground: 222 47% 10%;
    --sidebar-border:  210 30% 86%;
    --popover:         0 0% 100%;
    --popover-foreground: 222 47% 10%;
    --popover-border:  210 30% 88%;
    --primary:         217 91% 55%;
    --primary-foreground: 0 0% 100%;
    --secondary:       210 20% 92%;
    --secondary-foreground: 222 47% 12%;
    --accent-violet:   262 83% 58%;
    --muted:           210 20% 90%;
    --muted-foreground: 215 15% 38%;
    --accent:          210 20% 86%;
    --accent-foreground: 222 47% 10%;
    --destructive:     0 84% 55%;
    --destructive-foreground: 0 0% 100%;
    --success:         142 71% 38%;
    --warn:            32 95% 44%;
    --ring:            217 91% 55%;
    --grid-line: rgba(59, 130, 246, 0.06);
    --glow-1: rgba(59, 130, 246, 0.12);
    --glow-2: rgba(168, 85, 247, 0.12);
    color-scheme: light;
  }
}

/* ── Reset + base ─────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  background: hsl(var(--background));
}
body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  min-height: 100dvh;
  transition: background-color 0.3s ease, color 0.2s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* iOS form-zoom prevention */
input, textarea, select, button { font-family: inherit; font-size: 16px; }
@media (min-width: 768px) { input, textarea, select, button { font-size: 14px; } }

/* ── Topbar (mobile-only) ─────────────────────────────────── */
.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding-top: max(env(safe-area-inset-top, 0px) + 10px, 12px);
  padding-bottom: 10px;
  padding-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
  padding-right: max(env(safe-area-inset-right, 0px) + 16px, 16px);
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--sidebar));
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--topbar-h);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand h1 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-icon { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; }
.topbar-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* ── Icon buttons ─────────────────────────────────────────── */
.icon-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: hsl(var(--foreground));
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover {
  background: hsl(var(--accent));
  border-color: hsl(var(--border));
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s, box-shadow 0.12s;
  white-space: nowrap;
  min-height: 38px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover {
  background: hsl(var(--accent));
  border-color: hsl(var(--ring) / 0.4);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--accent-violet)));
  border-color: transparent;
  color: hsl(var(--primary-foreground));
  font-weight: 600;
  box-shadow: 0 0 0 1px hsl(var(--primary) / 0.5), 0 4px 12px hsl(var(--primary) / 0.25);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.link {
  background: transparent;
  border: none;
  color: hsl(var(--primary));
  padding: 0;
  text-decoration: underline;
  min-height: auto;
}
.btn.danger { color: hsl(var(--destructive)); }
.btn.save-reqs { margin-top: 10px; }
/* Build buttons sit side-by-side and don't span the full card width on
 * desktop — they wrap on mobile via flex-wrap. */
.build-row { gap: 12px; flex-wrap: wrap; }
.build-row .btn {
  flex: 0 1 240px;
  padding: 12px 16px;
}

/* ── User pill + role badge ───────────────────────────────── */
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 12px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  max-width: 240px;
  overflow: hidden;
  background: hsl(var(--card));
}
.user-pill .email {
  color: hsl(var(--foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.user-pill .role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.12);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
  font-weight: 600;
}

/* ── Theme toggle ─────────────────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  padding: 2px;
  gap: 0;
}
.theme-toggle button {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: transparent;
  border: none;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.theme-toggle button:hover { color: hsl(var(--foreground)); }
.theme-toggle button.active {
  background: hsl(var(--background));
  color: hsl(var(--primary));
  box-shadow: var(--shadow-sm);
}
.theme-toggle svg { width: 14px; height: 14px; }

/* ── Main layout ──────────────────────────────────────────── */
/* Fixed-height layout so the sidebar and workspace each scroll
 * independently — sidebar nav stays visible while the workspace
 * content scrolls. */
#main {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid hsl(var(--sidebar-border));
  background: hsl(var(--sidebar));
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
}
/* Sidebar brand block — top of the sidebar, replaces the desktop topbar */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 6px;
  padding-top: max(env(safe-area-inset-top, 0px) + 16px, 18px);
  padding-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
  padding-right: max(env(safe-area-inset-right, 0px) + 16px, 16px);
  min-width: 0;
}
.sidebar-brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px hsl(var(--primary) / 0.18);
}
.sidebar-brand-text { min-width: 0; flex: 1; overflow: hidden; }
.sidebar-brand-text h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand-text h1 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: hsl(var(--foreground));
  line-height: 1.2;
}
.sidebar-brand-tagline {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  font-style: italic;
}
.sidebar-brand-tagline strong {
  font-style: normal;
  font-weight: 600;
  color: hsl(var(--foreground));
}
.sidebar-workspace {
  margin: 2px 16px 14px;
  margin-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}
.sidebar-section-label {
  font-family: var(--font-sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: hsl(var(--muted-foreground));
  margin: 6px 16px 8px;
  margin-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
}
.sidebar > .sidebar-cta {
  margin: 0 16px 14px;
  margin-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
  margin-right: max(env(safe-area-inset-right, 0px) + 16px, 16px);
}
.sidebar > .project-list {
  margin: 0 8px;
  padding-left: max(env(safe-area-inset-left, 0px) + 8px, 8px);
  padding-right: max(env(safe-area-inset-right, 0px) + 8px, 8px);
}
/* The CTA used to set width: 100%, but combined with the parent's 16px
 * left/right margins that produced a button wider than its container
 * (margins are outside the box). Switching to display: flex (block-level)
 * + no explicit width lets it fill the parent column safely. */
.sidebar-cta {
  display: flex;
  justify-content: center;
  padding: 10px 14px;
}
.project-list { list-style: none; padding: 0; margin: 0; flex: 1; min-width: 0; }
.project-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 6px 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  color: hsl(var(--sidebar-foreground));
  min-width: 0;
  overflow: hidden;
}
.project-list li:hover { background: hsl(var(--accent)); }
.project-list li.active {
  background: hsl(var(--accent));
  border-color: hsl(var(--border));
}
.project-list .project-row-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  overflow: hidden;
}
.project-list .name {
  font-weight: 500;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-list .meta {
  font-size: 11px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-row-del {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
  padding: 0;
}
.project-list li:hover .project-row-del,
.project-list li.active .project-row-del { opacity: 1; }
.project-row-del:hover {
  background: hsl(var(--destructive) / 0.12);
  color: hsl(var(--destructive));
}
/* On touch devices there's no hover — always show the delete affordance. */
@media (hover: none) {
  .project-row-del { opacity: 0.75; }
}

/* ── Mobile homepage accordion (Your projects) ────────────── */
.home {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.home-head h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.home-head .hint { margin: 0; }
.home-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.home-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--card-border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.home-card[open] {
  border-color: hsl(var(--primary) / 0.4);
  box-shadow: var(--shadow-md);
}
.home-card-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.home-card-summary::-webkit-details-marker { display: none; }
.home-card-summary:hover { background: hsl(var(--accent) / 0.5); }
.home-card-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.home-card-title strong {
  font-size: 15px;
  font-weight: 600;
  color: hsl(var(--foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.home-card-meta {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}
.home-card-chevron {
  color: hsl(var(--muted-foreground));
  transition: transform 0.18s ease-out;
  flex-shrink: 0;
}
.home-card[open] .home-card-chevron { transform: rotate(180deg); }
.home-card-body {
  padding: 0 16px 16px;
  border-top: 1px solid hsl(var(--border));
  padding-top: 14px;
}
.home-card-reqs {
  margin: 0 0 12px;
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  line-height: 1.55;
  white-space: pre-wrap;
}
.home-card-actions { margin: 0; }
.home-card-actions .btn { padding: 9px 14px; }

.sidebar-footer {
  margin-top: 12px;
  padding: 12px 16px;
  padding-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
  padding-right: max(env(safe-area-inset-right, 0px) + 16px, 16px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px) + 12px, 12px);
  border-top: 1px solid hsl(var(--sidebar-border));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Labeled theme toggle — Memos style. min-width: 0 on the grid + button so
 * the "System" label doesn't overflow a narrow sidebar. */
.sidebar-theme-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  min-width: 0;
  overflow: hidden;
}
.sidebar-theme-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 6px;
  border-radius: 999px;
  background: transparent;
  border: none;
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  min-width: 0;
  overflow: hidden;
}
.sidebar-theme-row button span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-theme-row button:hover { color: hsl(var(--foreground)); }
.sidebar-theme-row button.active {
  background: hsl(var(--background));
  color: hsl(var(--primary));
  box-shadow: var(--shadow-sm);
}
.sidebar-theme-row button svg { width: 12px; height: 12px; flex-shrink: 0; }

/* User pill is the dropdown trigger; sibling .user-menu is the popup.
 * The wrapper exists because nested <button> elements are illegal HTML —
 * the browser would auto-extract any <button> from inside another <button>,
 * causing the menu items to render flat in the sidebar. */
.user-menu-wrap {
  position: relative;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--card-border));
  border-radius: 10px;
  min-width: 0;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
}
.sidebar-user:hover { border-color: hsl(var(--ring) / 0.4); }
.sidebar-user .user-text { min-width: 0; flex: 1; }
.sidebar-user .chevron {
  color: hsl(var(--muted-foreground));
  flex-shrink: 0;
  transition: transform 0.15s;
}
.user-menu-wrap.open .sidebar-user .chevron { transform: rotate(180deg); }

.user-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: hsl(var(--popover));
  border: 1px solid hsl(var(--popover-border));
  border-radius: 10px;
  padding: 6px;
  box-shadow: var(--shadow-md);
  z-index: 60;
  display: none;
}
.user-menu-wrap.open .user-menu { display: block; }
.user-menu a,
.user-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: hsl(var(--foreground));
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.user-menu a:hover,
.user-menu button:hover { background: hsl(var(--accent)); }
.user-menu svg {
  color: hsl(var(--muted-foreground));
  flex-shrink: 0;
}
.user-menu .menu-sep {
  height: 1px;
  background: hsl(var(--border));
  margin: 4px 6px;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--accent-violet)));
  color: hsl(var(--primary-foreground));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.user-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.user-text strong {
  font-size: 13px;
  font-weight: 600;
  color: hsl(var(--foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-text span {
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Admin dashboard button — prominent, full-width */
.sidebar-admin-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: hsl(var(--primary) / 0.08);
  border: 1px solid hsl(var(--primary) / 0.25);
  border-radius: 10px;
  color: hsl(var(--primary));
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s;
}
.sidebar-admin-btn:hover {
  background: hsl(var(--primary) / 0.14);
}

/* Mini action row (kept for admin's Sign-out-only state, no longer used
 * on the main app — Sign out lives inside the user dropdown menu). */
.sidebar-actions-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.sidebar-actions-row.cols-2 { grid-template-columns: 1fr 1fr; }
.sidebar-mini-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  color: hsl(var(--foreground));
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.sidebar-mini-action:hover {
  background: hsl(var(--accent));
}
.sidebar-mini-action svg { color: hsl(var(--muted-foreground)); flex-shrink: 0; }

.sidebar-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
}
.sidebar-version {
  font-size: 10.5px;
  color: hsl(var(--muted-foreground));
  font-family: var(--font-mono);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: hsl(var(--background) / 0.7);
  backdrop-filter: blur(2px);
  z-index: 40;
}

.workspace {
  overflow-y: auto;
  height: 100vh;
  height: 100dvh;
  padding-top: max(env(safe-area-inset-top, 0px) + 28px, 28px);
  padding-left: max(env(safe-area-inset-left, 0px) + 28px, 28px);
  padding-right: max(env(safe-area-inset-right, 0px) + 28px, 28px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px) + 24px, 24px);
}
/* Constrain content width on wide displays so cards / build buttons
 * don't stretch to half a meter. Vertically pad sections for breathing
 * room (cards: margin-bottom is 16px; this adds more separation between
 * the major regions). */
.workspace > .project-view,
.workspace > .empty-state {
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
.workspace.empty { display: flex; align-items: center; justify-content: center; }
.empty-state { text-align: center; color: hsl(var(--muted-foreground)); max-width: 460px; padding: 16px; }
.empty-state h2 { color: hsl(var(--foreground)); font-weight: 600; margin: 0 0 8px; font-size: 18px; }

.project-header { margin-bottom: 18px; }
.project-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  color: hsl(var(--foreground));
  padding: 6px 8px;
  border-radius: 6px;
  width: 100%;
  letter-spacing: -0.01em;
}
.project-name:hover, .project-name:focus {
  border-color: hsl(var(--border));
  background: hsl(var(--card));
  outline: none;
}
.project-meta { color: hsl(var(--muted-foreground)); font-size: 12px; padding: 0 8px; }

/* ── Cards + form primitives ──────────────────────────────── */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--card-border));
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
}
.hint { color: hsl(var(--muted-foreground)); margin: 0 0 12px; font-size: 12.5px; }
.hint-list { padding-left: 18px; margin: 0 0 12px; }
.hint-list li { margin-bottom: 4px; }
.hint-list strong { color: hsl(var(--foreground)); }

textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
select {
  width: 100%;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  color: hsl(var(--foreground));
  padding: 12px 14px;
  resize: vertical;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.18);
}

/* Custom select chevron — works in both themes */
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 38px;
}

/* ── Dropzone ─────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed hsl(var(--border));
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  color: hsl(var(--muted-foreground));
  margin-bottom: 12px;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
  background: hsl(var(--card));
}
.dropzone.dragover {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.08);
}
.dropzone .file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone.uploading {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.08);
  pointer-events: none;
  opacity: 0.8;
}
.dropzone.uploading::after {
  content: "Uploading…";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: hsl(var(--primary));
}

/* ── Rows / inputs ────────────────────────────────────────── */
.row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.row input { flex: 1 1 200px; min-width: 0; }
.row .btn { flex-shrink: 0; }

.paste { margin-bottom: 8px; }
.paste summary { cursor: pointer; color: hsl(var(--muted-foreground)); padding: 6px 0; user-select: none; }
.paste input, .paste textarea { margin-top: 8px; }
.paste .add-text { margin-top: 8px; }

/* ── Source rows ──────────────────────────────────────────── */
.source-list { list-style: none; padding: 0; margin: 14px 0 0; }
.source-item {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px 12px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  margin-bottom: 6px;
  gap: 10px;
  flex-wrap: wrap;
}
.source-item > div:first-child { flex: 1 1 200px; min-width: 0; word-break: break-word; }
.source-item .name { font-weight: 500; }
.source-item .kind {
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 8px;
}
.source-item .status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.status.pending { background: hsl(var(--warn) / 0.15); color: hsl(var(--warn)); }
.status.extracted { background: hsl(var(--success) / 0.15); color: hsl(var(--success)); }
.status.failed { background: hsl(var(--destructive) / 0.15); color: hsl(var(--destructive)); }
.source-error {
  display: block;
  font-size: 11.5px;
  color: hsl(var(--destructive));
  margin-top: 4px;
  font-family: var(--font-mono);
  word-break: break-word;
}

/* ── Architecture results ─────────────────────────────────── */
.architectures { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.architecture {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 14px 16px;
}
.architecture h4 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.kind-tag {
  display: inline-block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.kind-tag.strategy { background: hsl(var(--primary) / 0.15); color: hsl(var(--primary)); }
.kind-tag.voice_profile { background: hsl(var(--accent-violet) / 0.18); color: hsl(var(--accent-violet)); }
.kind-tag.custom { background: hsl(var(--warn) / 0.18); color: hsl(var(--warn)); }
.build-manual-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 999px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}
.architecture .actions { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }
.architecture .meta {
  color: hsl(var(--muted-foreground));
  font-size: 11.5px;
  margin-bottom: 8px;
  display: flex; gap: 12px; flex-wrap: wrap;
}
.architecture pre {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  background: hsl(var(--background));
  padding: 14px;
  border-radius: 6px;
  font-size: 12.5px;
  max-height: 600px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  word-break: break-word;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: hsl(var(--background) / 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  padding: 16px;
  padding-top: max(env(safe-area-inset-top, 0px) + 16px, 16px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px) + 16px, 16px);
}
.modal.hidden { display: none; }
.modal-card {
  background: hsl(var(--popover));
  border: 1px solid hsl(var(--popover-border));
  border-radius: 14px;
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid hsl(var(--border));
  position: sticky;
  top: 0;
  background: hsl(var(--popover));
  z-index: 1;
}
.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
}
.modal-section { padding: 16px 20px; border-bottom: 1px solid hsl(var(--border)); }
.modal-section h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 14px;
}
.modal-footer {
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  position: sticky;
  bottom: 0;
  background: hsl(var(--popover));
  border-top: 1px solid hsl(var(--border));
  flex-wrap: wrap;
}
.modal-footer .row { gap: 8px; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: hsl(var(--muted-foreground)); margin-bottom: 4px; font-weight: 500; }
.radio {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  cursor: pointer;
  min-height: 38px;
  background: hsl(var(--card));
}
.radio input { margin: 0; width: 16px; height: 16px; accent-color: hsl(var(--primary)); }
.muted { color: hsl(var(--muted-foreground)); font-size: 12px; }
.test-result { margin-left: 10px; font-size: 12px; word-break: break-word; }
.test-result.ok { color: hsl(var(--success)); }
.test-result.err { color: hsl(var(--destructive)); }
.modal code {
  background: hsl(var(--secondary));
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid hsl(var(--border));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Docs page ────────────────────────────────────────────── */
.docs-workspace {
  padding-top: max(env(safe-area-inset-top, 0px) + 32px, 32px);
}
.docs-article {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.docs-article > header { margin-bottom: 32px; }
.docs-article > header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -0.015em;
}
.docs-lede {
  color: hsl(var(--muted-foreground));
  font-size: 15px;
  line-height: 1.55;
  margin: 0;
}
.docs-article section { margin-bottom: 36px; }
.docs-article section h2 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid hsl(var(--border));
}
.docs-article section h3 {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 18px 0 6px;
}
.docs-article p, .docs-article li {
  font-size: 14px;
  line-height: 1.6;
  color: hsl(var(--foreground));
}
.docs-article .hint {
  background: hsl(var(--accent));
  border-left: 3px solid hsl(var(--primary));
  padding: 10px 14px;
  border-radius: 6px;
  margin: 12px 0;
}
.docs-article ul, .docs-article ol { padding-left: 22px; }
.docs-article li { margin-bottom: 6px; }
.docs-article a {
  color: hsl(var(--primary));
  text-decoration: underline;
}
.docs-article code {
  background: hsl(var(--secondary));
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.docs-nav {
  list-style: none;
  padding: 0 8px;
  padding-left: max(env(safe-area-inset-left, 0px) + 8px, 8px);
  padding-right: max(env(safe-area-inset-right, 0px) + 8px, 8px);
  margin: 0;
  flex: 1;
}
.docs-nav li { list-style: none; }
.docs-nav a {
  display: block;
  padding: 7px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: hsl(var(--sidebar-foreground));
  font-size: 13px;
  text-decoration: none;
  transition: background 0.12s;
}
.docs-nav a:hover { background: hsl(var(--accent)); }

/* ── "Powered by C4 SaaS" footer ──────────────────────────── */
.powered-by {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: hsl(var(--muted-foreground));
  text-decoration: none;
  font-size: 11px;
  opacity: 0.75;
  transition: opacity 0.15s;
}
.powered-by:hover { opacity: 1; }
.powered-by img { border-radius: 4px; flex-shrink: 0; }
.powered-by-label { letter-spacing: 0.02em; }
.powered-by-name {
  color: hsl(var(--foreground));
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Auth pages ───────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
  padding-right: max(env(safe-area-inset-right, 0px) + 16px, 16px);
  padding-top: max(env(safe-area-inset-top, 0px) + 24px, 24px);
  padding-bottom: max(env(safe-area-inset-bottom, 0px) + 24px, 24px);
  background: hsl(var(--background));
  position: relative;
  overflow: hidden;
}

.auth-bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
  pointer-events: none;
}
.auth-bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
}
.auth-bg-glow-1 {
  top: 15%; left: 50%;
  width: 480px; height: 320px;
  background: var(--glow-1);
  transform: translateX(-50%);
}
.auth-bg-glow-2 {
  bottom: 0; right: 10%;
  width: 320px; height: 240px;
  background: var(--glow-2);
}

.auth-shell {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 1;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 4px;
}
.auth-brand-icon {
  border-radius: 14px;
  flex-shrink: 0;
  box-shadow: 0 6px 24px hsl(var(--primary) / 0.25);
}
.auth-brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
}
.auth-brand-sub {
  margin: 2px 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.auth-card {
  background: hsl(var(--card) / 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid hsl(var(--card-border));
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.auth-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid hsl(var(--border));
}
.auth-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: hsl(var(--primary));
  box-shadow: 0 0 0 4px hsl(var(--primary) / 0.15);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.15); }
}
.auth-eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: hsl(var(--muted-foreground));
}
.auth-hint {
  margin: -6px 0 16px;
  color: hsl(var(--muted-foreground));
  font-size: 12.5px;
}
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-submit { width: 100%; margin-top: 8px; padding: 12px 14px; justify-content: center; }
.auth-error {
  padding: 10px 12px;
  background: hsl(var(--destructive) / 0.12);
  color: hsl(var(--destructive));
  border: 1px solid hsl(var(--destructive) / 0.3);
  border-radius: 8px;
  font-size: 13px;
  word-break: break-word;
}
.auth-footer { display: flex; justify-content: center; padding-top: 4px; }

/* ── Mobile responsive ────────────────────────────────────── */
@media (max-width: 900px) {
  /* Mobile: show the topbar (brand + hamburger), hide the desktop sidebar
   * brand block since the topbar now carries the brand. */
  .topbar.mobile-only { display: flex; }
  .icon-btn.sidebar-toggle { display: inline-flex; }
  .brand h1 { font-size: 14px; }
  .sidebar .sidebar-brand,
  .sidebar .sidebar-workspace { display: none; }
  .sidebar > .sidebar-cta { margin-top: 14px; }

  /* On mobile the desktop fixed-height grid would clip the workspace.
   * Switch back to single column + auto-height so the page scrolls
   * naturally and the drawer can size itself to the viewport via
   * top+bottom anchors. */
  #main {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  .workspace {
    height: auto;
    min-height: calc(100dvh - var(--topbar-h));
    overflow: visible;
    padding-top: 18px;
    padding-left: max(env(safe-area-inset-left, 0px) + 16px, 16px);
    padding-right: max(env(safe-area-inset-right, 0px) + 16px, 16px);
    padding-bottom: max(env(safe-area-inset-bottom, 0px) + 18px, 18px);
  }

  /* Sidebar drawer: explicitly override desktop's 100vh height so the
   * drawer sits between the topbar and the home indicator instead of
   * extending below the viewport and hiding the footer. */
  .sidebar {
    position: fixed;
    top: calc(max(env(safe-area-inset-top, 0px) + 10px, 12px) + 10px + var(--topbar-h) - 12px);
    left: 0;
    bottom: 0;
    height: auto;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    z-index: 45;
    box-shadow: var(--shadow-lg);
    /* Keep its own scroll so a tall projects list doesn't overflow. */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
}

@media (min-width: 901px) {
  .topbar.mobile-only { display: none; }
}

@media (max-width: 540px) {
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .topbar-actions { gap: 4px; }
  .btn { padding: 9px 11px; }
  .card { padding: 14px; }
  .project-name { font-size: 18px; }
}
