.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--app-bg);
}

.topbar {
  position: relative;
  z-index: var(--z-topbar);
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(240px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--surface-glass-2);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(18px);
}

.topbar__brand,
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar__actions {
  justify-content: flex-end;
}

.topbar__menu-button {
  display: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand__logo {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(119, 104, 246, 0.95), rgba(155, 139, 255, 0.92)),
    var(--color-primary);
  color: white;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(119, 104, 246, 0.28);
}

.brand__text {
  display: grid;
  gap: 0.05rem;
  min-width: 0;
}

.brand__name {
  font-size: 1rem;
  line-height: 1.15;
}

.brand__subtitle {
  color: var(--color-muted);
  font-size: 0.78rem;
  line-height: 1.1;
}

.mode-switcher {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  max-width: 100%;
  padding: 0.25rem;
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--surface-glass-muted);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34);
  scrollbar-width: none;
}

.mode-switcher::-webkit-scrollbar {
  display: none;
}

.sidebar {
  position: relative;
  z-index: var(--z-sidebar);
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-height: 0;
  padding: var(--space-5);
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
  background: var(--surface-glass-3);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(18px);
}

.sidebar__section {
  display: grid;
  gap: var(--space-4);
}

.sidebar__section--tip {
  margin-top: auto;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(119, 104, 246, 0.08), rgba(255, 255, 255, 0.82)),
    var(--color-surface);
}

.sidebar__header {
  display: grid;
  gap: var(--space-1);
}

.sidebar__header h2 {
  font-size: 1rem;
  line-height: 1.25;
}

.sidebar-tip {
  color: var(--color-text-soft);
  font-size: 0.9rem;
}

.workspace {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  padding: var(--space-3);
  gap: var(--space-2);
  background: var(--app-bg);
}

.workspace__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--workspace-chrome-height);
}

.workspace__title {
  margin-top: 0.05rem;
  font-size: clamp(1.05rem, 1.35vw, 1.45rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.workspace__meta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.inspector {
  position: fixed;
  top: calc(var(--topbar-height) + var(--space-5));
  right: var(--space-5);
  z-index: var(--z-floating);

  display: flex;
  flex-direction: column;

  width: min(var(--inspector-width), calc(100vw - 2rem));
  max-height: calc(100vh - var(--topbar-height) - 2.5rem);

  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--surface-glass-1);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
}

.inspector__header {
  flex: 0 0 auto;

  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);

  padding: var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.inspector__header h2 {
  margin-top: 0.1rem;
  font-size: 1.05rem;
}

.inspector__body {
  flex: 1 1 auto;
  min-height: 0;

  padding: var(--space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.inspector__body::-webkit-scrollbar {
  width: 10px;
}

.inspector__body::-webkit-scrollbar-track {
  background: transparent;
}

.inspector__body::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: var(--radius-full);
  background: rgba(37, 37, 32, 0.18);
  background-clip: content-box;
}

.inspector__body::-webkit-scrollbar-thumb:hover {
  background: rgba(37, 37, 32, 0.28);
  background-clip: content-box;
}

html[data-theme="dark"] .inspector__body::-webkit-scrollbar-thumb {
  background: rgba(245, 241, 232, 0.2);
  background-clip: content-box;
}

html[data-theme="dark"] .inspector__body::-webkit-scrollbar-thumb:hover {
  background: rgba(245, 241, 232, 0.32);
  background-clip: content-box;
}

html[data-theme="dark"] .sidebar {
  box-shadow: inset -1px 0 0 rgba(245, 241, 232, 0.08);
}

html[data-theme="dark"] .sidebar__section--tip {
  background:
    linear-gradient(135deg, var(--accent-tint), rgba(25, 28, 32, 0.78)),
    var(--surface-glass-4);
  border-color: var(--color-border);
}

.modal-root,
.toast-root,
.context-menu-root,
.command-palette-root {
  position: fixed;
  z-index: var(--z-modal);
  pointer-events: none;
}

.toast-root {
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: var(--z-toast);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .mode-switcher {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: stretch;
  }

  .topbar {
    height: auto;
    min-height: var(--topbar-height);
    padding-block: var(--space-2);
  }

  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar__actions {
    justify-self: end;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    width: min(var(--sidebar-width), 86vw);
    max-width: 22rem;
    transform: translateX(-105%);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-lg);
  }

  .app-shell.is-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .topbar__menu-button {
    display: inline-grid;
  }

  .workspace {
    grid-column: 1;
    padding: var(--space-2);
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .topbar__actions .ghost-button:not(:first-child) {
    display: none;
  }

  .workspace__header {
    align-items: center;
    flex-direction: row;
  }

  .inspector {
    top: auto;
    right: var(--space-3);
    bottom: var(--space-3);
    left: var(--space-3);
    width: auto;
    max-height: min(62vh, 34rem);
    border-radius: var(--radius-lg);
  }

  .inspector__header,
  .inspector__body {
    padding: var(--space-4);
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: var(--space-2);
  }

  .mode-switcher {
    justify-self: stretch;
  }

  .brand__subtitle {
    display: none;
  }

  .topbar__actions .ghost-button {
    display: none;
  }

  .topbar__actions .primary-button {
    display: none;
  }

  .workspace {
    padding: var(--space-2);
  }

  .workspace__meta {
    font-size: 0.8rem;
  }
}
