:host {
  --builder-sidebar-width: 280px;
  display: block;
}

.project-editor-layout {
  display: grid;
  grid-template-columns: var(--builder-sidebar-width) 1fr;
  align-items: start;
  min-height: 100vh;
  background: var(--bg-secondary);
}

.project-editor-layout__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 30;
  display: none;
}

.project-editor-layout__sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: var(--space-md);
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  z-index: 40;
}

.project-editor-layout__brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm);
  margin-bottom: var(--space-md);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-weight: var(--font-weight-bold, 700);
  text-decoration: none;

  &:hover {
    background: var(--bg-tertiary);
  }

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
}

.project-editor-layout__dashboard-link {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm);
  margin-bottom: var(--space-md);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--font-size-sm, 0.8125rem);
  text-decoration: none;

  &:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
  }

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
}

.project-editor-layout__content {
  min-width: 0;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.project-editor-layout__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
}

.project-editor-layout__menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
}

.project-editor-layout__heading {
  flex: 1 1 auto;
  min-width: 0;
}

.project-editor-layout__breadcrumb {
  ol {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    margin: 0 0 4px;
    padding: 0;
    font-size: var(--font-size-xs, 0.75rem);
    color: var(--text-light);
  }

  li {
    display: flex;
    align-items: center;
  }

  a {
    color: var(--text-light);
    text-decoration: none;

    &:hover {
      color: var(--primary-color);
      text-decoration: underline;
    }

    &:focus-visible {
      outline: 2px solid var(--primary-color);
      outline-offset: 2px;
    }
  }

  [aria-current='page'] {
    color: var(--text-secondary);
  }
}

.project-editor-layout__breadcrumb-sep {
  margin: 0 var(--space-xs);
}

.project-editor-layout__title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);

  h1 {
    margin: 0;
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: var(--font-weight-bold, 700);
    color: var(--text-primary);
  }
}

.project-editor-layout__badge {
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-semibold, 600);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.project-editor-layout__badge--draft {
  background: color-mix(in srgb, var(--warning-color) 15%, transparent);
  color: var(--warning-color);
}

.project-editor-layout__badge--published {
  background: color-mix(in srgb, var(--success-color) 15%, transparent);
  color: var(--success-color);
}

.project-editor-layout__badge--modified {
  background: color-mix(in srgb, var(--primary-color) 10%, transparent);
  color: var(--primary-color);
}

.project-editor-layout__description {
  margin: var(--space-xs) 0 0;
  font-size: var(--font-size-lg, 1rem);
  color: var(--text-secondary);
  max-width: 65ch;
}

.project-editor-layout__help-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: var(--font-weight-medium, 500);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;

  &:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
  }

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
}

.project-editor-layout__help {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
  padding: var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);

  h2 {
    margin: 0 0 4px;
    font-size: var(--font-size-xs, 0.75rem);
    font-weight: var(--font-weight-bold, 700);
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--text-light);
  }

  p {
    margin: 0;
    font-size: var(--font-size-lg, 1rem);
    color: var(--text-secondary);
  }
}

.project-editor-stack {
  display: grid;
  gap: 16px;

  > * {
    animation: project-editor-section-in 220ms ease-out both;
  }
}

@keyframes project-editor-section-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .project-editor-stack > * {
    animation: none;
  }
}

.project-editor-section-actions {
  display: flex;
  justify-content: flex-end;
}

.project-editor-work-area {
  display: grid;
  gap: 16px;
  align-items: start;
}

.project-editor-work-area--with-preview {
  grid-template-columns: minmax(0, 1fr) 280px;
}

@media (max-width: 960px) {
  .project-editor-work-area--with-preview {
    grid-template-columns: minmax(0, 1fr);
  }
}

.project-editor-live-preview {
  position: sticky;
  top: var(--space-md, 1rem);
  padding: var(--space-md, 1rem);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg, 10px);
  background: var(--bg-primary);
}

.project-editor-live-preview__title {
  margin: 0 0 var(--space-xs, 0.25rem);
  font-size: var(--font-size-base, 0.875rem);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary);
}

.project-editor-layout__search {
  display: block;
  margin-bottom: var(--space-md, 1rem);
}

.project-editor-live-preview__hint {
  margin: 0 0 var(--space-sm, 0.5rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary);
}

.project-editor-empty {
  min-height: 240px;
  display: grid;
  place-items: center;
}

/* Tablet: icon-only collapsed sidebar */
@media (max-width: 1023px) and (min-width: 768px) {
  .project-editor-layout.project-editor-layout {
    grid-template-columns: 72px 1fr;
  }

  .project-editor-layout__sidebar {
    padding: var(--space-sm);
  }

  .project-editor-layout__brand {
    justify-content: center;

    span:last-child:not(.pi) {
      display: none;
    }
  }
}

/* Mobile: drawer */
@media (max-width: 767px) {
  .project-editor-layout.project-editor-layout {
    grid-template-columns: 0 1fr;
  }

  .project-editor-layout__menu-toggle {
    display: inline-flex;
  }

  .project-editor-layout__content {
    padding: var(--space-md);
  }

  .project-editor-layout__sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--builder-sidebar-width), 84vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }

  .project-editor-layout--drawer-open {
    .project-editor-layout__sidebar {
      transform: translateX(0);
    }

    .project-editor-layout__backdrop {
      display: block;
    }
  }

  .project-editor-layout__header {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .project-editor-layout__sidebar {
    transition: none;
  }
}
