/**
 * Editor shell UX — sticky nav, clear cards, mobile-first.
 * Keeps Scripty's dark theme; focuses on flow & readability.
 */

body.editor-shell {
  padding-top: 0 !important;
  padding-bottom: max(24px, env(safe-area-inset-bottom)) !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  max-width: none;
  width: 100%;
  overflow-x: clip;
  color: #eee;
}

.editor-shell .star-field {
  pointer-events: none;
  opacity: 0.35;
}

.editor-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 12px max(20px, env(safe-area-inset-right)) 12px
    max(20px, env(safe-area-inset-left));
  background: rgba(10, 12, 18, 0.94);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.editor-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: #f4f1ff;
  min-width: 0;
}

.editor-topbar .navbar-logo {
  height: 64px;
  width: auto;
  display: block;
  flex-shrink: 0;
  border-radius: 10px;
}

.editor-brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.editor-brand-name {
  font-size: 1.45rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.editor-brand-tag {
  font-size: 0.78rem;
  color: #9aa0ab;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.editor-topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.editor-topbar-nav .nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  color: #c8ccd6;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 550;
  border: 1px solid transparent;
}

.editor-topbar-nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.editor-topbar .navbar-profile {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #eee;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  background: rgba(255, 255, 255, 0.04);
  min-height: 44px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.editor-topbar .navbar-profile:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
}

.editor-topbar .navbar-profile img,
.editor-topbar .navbar-profile .avatar-fallback {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.editor-topbar .navbar-profile .avatar-fallback {
  display: grid;
  place-items: center;
  background: #3a2a55;
  font-weight: 700;
  font-size: 0.85rem;
}

.editor-topbar .navbar-profile span {
  font-size: 0.86rem;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-wrap {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px max(12px, env(safe-area-inset-left)) 28px
    max(12px, env(safe-area-inset-right));
  box-sizing: border-box;
  overflow-x: clip;
}

.editor-step {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(18, 20, 28, 0.72);
}

.editor-step-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #b7b0d8;
  font-weight: 650;
}

.editor-step-label .step-num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(212, 196, 255, 0.16);
  color: #e6dcff;
  font-size: 0.72rem;
}

.editor-step h2,
.editor-step h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 650;
  color: #f0ecff;
}

.editor-step .hint {
  margin: 0 0 12px;
  font-size: 0.84rem;
  color: #9aa0ab;
  line-height: 1.45;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: stretch;
}

/* Left stack (PDF + notes) matches right AI box height */
.editor-source-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.editor-source-col form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.editor-source-col .editor-file {
  flex-shrink: 0;
}

.editor-source-col .editor-field {
  flex: 1 1 auto;
  min-height: 180px;
  height: 100%;
  resize: vertical;
}

.editor-source-col .editor-actions {
  margin-top: auto;
  padding-top: 12px;
  flex-shrink: 0;
}

.editor-custom .category-grid {
  grid-template-columns: 1fr 1fr;
  grid-auto-flow: row;
}

.editor-custom .category-grid > * {
  min-width: 0;
}

.editor-custom .formula-size-field {
  width: 100%;
  margin-bottom: 4px;
}

.editor-field {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  padding: 12px;
  font: inherit;
  outline: none;
  resize: vertical;
}

.editor-field:focus {
  border-color: rgba(212, 196, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(212, 196, 255, 0.12);
}

.editor-file {
  width: 100%;
  margin-bottom: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  padding: 12px;
  color: #ddd;
  background: rgba(0, 0, 0, 0.18);
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.editor-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: #eee;
  color: #111;
  font-weight: 650;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
}

.editor-btn.secondary {
  background: transparent;
  color: #eee;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.editor-btn:hover {
  filter: brightness(1.05);
}

.editor-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, 0.95fr);
  gap: 16px;
  align-items: start;
}

.editor-paper-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.editor-paper-wrap .page-container {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.editor-paper-wrap .page-a {
  margin-left: auto;
  margin-right: auto;
  max-width: 100%;
  width: min(400px, 100%);
  height: auto;
  aspect-ratio: 8.3 / 11.7;
}

.editor-custom {
  min-width: 0;
}

.editor-custom details.custom-panel {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  padding: 4px 10px 10px;
  margin-bottom: 10px;
}

.editor-custom details.custom-panel > summary {
  cursor: pointer;
  list-style: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 650;
  color: #e8e4ff;
  user-select: none;
}

.editor-custom details.custom-panel > summary::-webkit-details-marker {
  display: none;
}

.editor-custom details.custom-panel > summary::after {
  content: '▸';
  margin-left: auto;
  opacity: 0.7;
  transition: transform 0.15s ease;
}

.editor-custom details.custom-panel[open] > summary::after {
  transform: rotate(90deg);
}

.editor-custom fieldset {
  margin-top: 10px;
}

.editor-generate-bar {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-top: 16px;
  padding: 8px 0 4px;
}

.editor-generate-bar .generate-image-button,
.editor-generate-bar .button {
  min-width: min(280px, 100%);
  min-height: 48px;
  font-size: 1rem;
}

.draft-modal {
  padding: max(16px, env(safe-area-inset-top)) 16px
    max(16px, env(safe-area-inset-bottom));
}

.draft-modal-card {
  width: min(420px, 100%);
}

.draft-modal-actions {
  flex-wrap: wrap;
}

.draft-modal-actions .button {
  flex: 1 1 auto;
  min-height: 44px;
}

@media (max-width: 900px) {
  .editor-grid,
  .editor-workspace,
  .editor-shell .display-flex.responsive-flex.output-grid {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .editor-source-col .editor-field {
    flex: none;
    min-height: 160px;
    height: auto;
  }

  .editor-custom .category-grid {
    grid-template-columns: 1fr 1fr;
  }

  .editor-shell .customization-col {
    padding: 0 !important;
    width: 100%;
  }

  .editor-shell .page-container-super {
    width: 100%;
  }

  .editor-topbar {
    min-height: 68px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .editor-topbar .navbar-logo {
    height: 56px;
  }

  .editor-brand {
    gap: 10px;
  }

  .editor-brand-name {
    font-size: 1.28rem;
  }

  .editor-brand-tag {
    display: none;
  }

  .editor-topbar-nav .nav-link.desktop-only {
    display: none;
  }

  .editor-topbar .navbar-profile span {
    display: none;
  }

  .editor-topbar .navbar-profile {
    padding: 3px;
  }

  .editor-shell .star-field {
    display: none;
  }

  .editor-topbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .editor-shell .page-a {
    width: min(400px, calc(100vw - 48px));
    height: calc(11.7 * min(400px, calc(100vw - 48px)) / 8.3);
  }

  .editor-custom fieldset {
    padding: 12px 10px;
  }

  .editor-custom .category-grid {
    gap: 8px;
  }
}

@media (max-width: 520px) {
  .editor-step {
    padding: 14px 12px;
    border-radius: 12px;
  }

  .editor-wrap {
    padding-top: 12px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .editor-shell .page-a {
    width: min(360px, calc(100vw - 40px));
    height: calc(11.7 * min(360px, calc(100vw - 40px)) / 8.3);
  }

  .editor-custom .category-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 901px) {
  /* Desktop: keep custom panels open by default via HTML open attr */
  .editor-custom details.custom-panel {
    padding-top: 8px;
  }
}
