:root {
  --sidebar-width: 260px;
  --sidebar-min-width: 220px;
  --sidebar-max-width: 420px;
  --sidebar-collapsed-width: 76px;
}
.shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.topbar {
  display: grid;
  grid-template-columns: minmax(var(--sidebar-min-width), 300px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.25rem;
  min-height: 76px;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.12);
}
.topbar-brand, .topbar-spacer { min-width: 0; }
.topbar-brand { display: flex; align-items: center; }
.topbar-brand .brand { justify-content: flex-start; }
.workspace-row {
  display: flex;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  width: clamp(var(--sidebar-min-width), var(--sidebar-width), var(--sidebar-max-width));
  flex: 0 0 clamp(var(--sidebar-min-width), var(--sidebar-width), var(--sidebar-max-width));
  display: flex; flex-direction: column;
  gap: 1.6rem; padding: 1.5rem 1.2rem; border-right: 1px solid var(--line);
  background: var(--surface); position: relative; height: 100%; overflow: auto;
  z-index: 50; transition: width 0.2s ease, flex-basis 0.2s ease, padding 0.2s ease;
}
.sidebar-menu-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; min-width: 0; }
.sidebar-menu-title {
  color: var(--muted-light); font-size: 0.72rem; font-weight: 800;
  letter-spacing: 0.1em; text-transform: uppercase;
}
.sidebar-resizer {
  position: relative; z-index: 60; flex: 0 0 12px; width: 12px; height: 100%;
  cursor: col-resize; touch-action: none; background: transparent;
}
.sidebar-resizer::before {
  content: ""; position: absolute; top: 1.5rem; bottom: 1.5rem; left: 50%; width: 2px;
  border-radius: 999px; background: var(--line); transform: translateX(-50%); transition: background 0.18s ease, box-shadow 0.18s ease;
}
.sidebar-resizer:hover::before, .sidebar-resizer:focus-visible::before, body.sidebar-resizing .sidebar-resizer::before {
  background: var(--cyan); box-shadow: 0 0 12px var(--cyan-glow);
}
body.sidebar-resizing, body.sidebar-resizing * { user-select: none !important; cursor: col-resize !important; }
.brand, .page-head, .panel-head, .doc-top, footer { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
.brand { gap: 0.85rem; text-decoration: none; color: inherit; cursor: pointer; user-select: none; transition: transform 0.15s ease; }
.brand:hover { transform: scale(1.02); }
.brand-copy { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }
.brand small { color: var(--muted); font-size: 0.75rem; }
.brand-mark {
  width: 42px; height: 42px; border-radius: var(--radius);
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: white; font-weight: 800; font-size: 1.1rem;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.4rem; }
.nav-icon { flex: 0 0 1.25rem; text-align: center; line-height: 1; }
.nav-label { min-width: 0; }
.sidebar-ai-box {
  display: grid; gap: 0.7rem; margin-top: auto; padding: 0.9rem;
  border: 1px solid rgba(34, 211, 238, 0.24); border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(34, 211, 238, 0.09), rgba(79, 70, 229, 0.1));
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.16);
}
.sidebar-ai-head { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.sidebar-ai-icon {
  display: grid; place-items: center; flex: 0 0 1.8rem; width: 1.8rem; height: 1.8rem;
  border: 1px solid rgba(34, 211, 238, 0.34); border-radius: 7px;
  color: var(--cyan); background: rgba(34, 211, 238, 0.12); font-size: 1rem;
}
.sidebar-ai-copy { display: grid; gap: 0.08rem; min-width: 0; }
.sidebar-ai-kicker { margin: 0; color: var(--cyan); font-size: 0.62rem; font-weight: 800; letter-spacing: 0.08em; }
.sidebar-ai-copy strong { overflow: hidden; color: var(--text); font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-ai-current {
  min-height: 2.1em; margin: 0; color: var(--muted-light); font-size: 0.72rem; line-height: 1.45;
  overflow-wrap: anywhere;
}
.sidebar-ai-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem; }
.sidebar-ai-action {
  display: flex; align-items: center; justify-content: flex-start; gap: 0.35rem; min-width: 0;
  padding: 0.5rem 0.45rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--muted-light); background: rgba(2, 6, 23, 0.22); cursor: pointer;
  font-size: 0.72rem; text-align: left; transition: all 0.18s ease;
}
.sidebar-ai-action:hover { border-color: var(--cyan); color: var(--text); background: rgba(34, 211, 238, 0.14); }
.sidebar-ai-action:focus-visible { outline: 3px solid rgba(34, 211, 238, 0.35); outline-offset: 1px; }
.sidebar-ai-action > span:first-child { flex: 0 0 auto; color: var(--cyan); font-size: 0.85rem; }
.sidebar-ai-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item, .ghost-button, .primary-button, .filter, .link-button, .tool-btn {
  cursor: pointer; border: 0; font-weight: 500; transition: all 0.18s ease;
}
.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.75rem 0.95rem; border-radius: var(--radius);
  color: var(--muted); background: transparent; text-align: left;
  font-size: 0.92rem;
}
.nav-item:hover { color: var(--text); background: rgba(148, 163, 184, 0.08); }
.nav-item.active {
  color: white; background: linear-gradient(135deg, rgba(79, 70, 229, 0.3), rgba(34, 211, 238, 0.15));
  box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.4), 0 4px 12px rgba(79, 70, 229, 0.2);
  font-weight: 600;
}
.shell main { flex: 1; min-width: 0; min-height: 0; overflow: auto; padding: 1.5rem 2rem; }
.page-head { margin-bottom: 1.25rem; }
.page-head-actions { display: flex; align-items: center; gap: 0.5rem; }
.auth-field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; font-weight: 600; }
.auth-field input { min-width: 8rem; }
.eyebrow { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--cyan); }
h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.25; }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); }
h2 { font-size: 1.15rem; margin-bottom: 0.35rem; }
.primary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.65rem 1.2rem; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--blue), var(--blue-hover));
  color: white; font-weight: 600; font-size: 0.88rem; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}
.primary-button:hover {
  background: linear-gradient(135deg, var(--blue-hover), #4338ca);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5); transform: translateY(-1px);
}
.primary-button:active { transform: translateY(0); }
.primary-button:disabled, .ghost-button:disabled {
  opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none;
}
.primary-button:disabled:hover, .ghost-button:disabled:hover {
  background: linear-gradient(135deg, var(--blue), var(--blue-hover));
  box-shadow: none; transform: none;
}
.ghost-button:disabled:hover { background: rgba(148, 163, 184, 0.09); }
.ghost-button, .filter {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  background: rgba(148, 163, 184, 0.09); color: var(--muted-light);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.48rem 0.85rem; font-size: 0.82rem;
}
.ghost-button:hover, .filter:hover {
  background: rgba(148, 163, 184, 0.18); color: var(--text); border-color: var(--line-strong);
}
.link-button {
  background: none; color: var(--cyan); font-size: 0.84rem; text-decoration: none; padding: 0.2rem 0.4rem;
}
.link-button:hover { text-decoration: underline; }
.icon-button {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.06); color: var(--text); cursor: pointer;
  display: grid; place-items: center; transition: all 0.18s ease;
}
.icon-button:hover { background: rgba(148, 163, 184, 0.16); border-color: var(--cyan); color: var(--cyan); }
.sidebar-toggle { flex: 0 0 auto; width: 32px; height: 32px; font-size: 0.78rem; }
.sidebar.is-collapsed {
  width: var(--sidebar-collapsed-width); flex-basis: var(--sidebar-collapsed-width); min-width: 0;
  padding: 0.8rem 0.45rem; gap: 1rem; overflow-x: hidden;
}
.sidebar.is-collapsed .sidebar-menu-head { justify-content: center; }
.sidebar.is-collapsed .sidebar-menu-title,
.sidebar.is-collapsed .nav-label { display: none; }
.sidebar.is-collapsed nav { width: 100%; }
.sidebar.is-collapsed .nav-item { justify-content: center; gap: 0; padding: 0.75rem 0.2rem; min-height: 44px; font-size: 1.05rem; }
.sidebar.is-collapsed .nav-icon { flex-basis: auto; }
.sidebar.is-collapsed .sidebar-ai-box { padding: 0.55rem 0.35rem; gap: 0.5rem; }
.sidebar.is-collapsed .sidebar-ai-copy,
.sidebar.is-collapsed .sidebar-ai-current,
.sidebar.is-collapsed .sidebar-ai-label { display: none; }
.sidebar.is-collapsed .sidebar-ai-head { justify-content: center; }
.sidebar.is-collapsed .sidebar-ai-actions { grid-template-columns: 1fr; }
.sidebar.is-collapsed .sidebar-ai-action { justify-content: center; padding: 0.55rem 0.2rem; font-size: 1rem; }
.sidebar.is-collapsed + .sidebar-resizer { width: 8px; flex-basis: 8px; cursor: default; pointer-events: none; }
.sidebar.is-collapsed + .sidebar-resizer::before { display: none; }
.section { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 900px) {
  .shell { display: flex; flex-direction: column; height: 100dvh; max-height: 100dvh; }
  .topbar {
    display: flex; flex: 0 0 auto; gap: 0.75rem; min-height: 64px;
    padding: 0.65rem 0.8rem;
  }
  .topbar-spacer { flex: 1 1 auto; }
  .topbar .brand strong { font-size: 1rem; }
  .topbar .brand small { display: none; }
  .workspace-row { flex: 1 1 auto; overflow: hidden; }
  .sidebar { position: relative; width: auto; flex: 0 0 auto; height: auto; max-height: 220px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-resizer { display: none; }
  .shell main { padding: 1rem; }
  .sidebar.is-collapsed { width: auto; flex-basis: auto; padding: 0.65rem 0.7rem; gap: 0.45rem; overflow-x: visible; }
  .sidebar.is-collapsed .sidebar-menu-head { justify-content: flex-start; }
  .sidebar.is-collapsed .sidebar-toggle { align-self: center; width: 32px; height: 32px; }
  .sidebar.is-collapsed .sidebar-menu-title,
  .sidebar.is-collapsed .nav-label { display: flex; }
  .sidebar.is-collapsed nav { width: auto; }
  .sidebar.is-collapsed .nav-item { justify-content: flex-start; gap: 0.65rem; padding: 0.75rem 0.95rem; min-height: 0; font-size: 0.92rem; }
  .sidebar-ai-box { margin-top: 0; width: 100%; }
  .sidebar-ai-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sidebar-ai-action { justify-content: center; }
  .sidebar-ai-label { display: inline; }
  .sidebar.is-collapsed .sidebar-ai-box { padding: 0.65rem 0.7rem; }
  .sidebar.is-collapsed .sidebar-ai-copy,
  .sidebar.is-collapsed .sidebar-ai-current,
  .sidebar.is-collapsed .sidebar-ai-label { display: inline; }
  .sidebar.is-collapsed .sidebar-ai-head { justify-content: flex-start; }
  .sidebar.is-collapsed .sidebar-ai-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sidebar.is-collapsed .sidebar-ai-action { justify-content: center; padding: 0.5rem 0.35rem; font-size: 0.72rem; }
}
