/* panel-editor.css — shared editor styles for the one-page and letter zine builders. */

.op-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 82px);
}

.op-sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 0.8rem;
  align-content: start;
}

/* Let button labels wrap instead of spilling out of a narrow sidebar. */
.controls-row-2 > *,
.controls-row-3 > *,
.seg-toggle > * {
  min-width: 0;
  white-space: normal;
  line-height: 1.15;
  text-align: center;
}

.op-sidebar section {
  background: var(--panel-bg);
  border: 1px solid #2a3642;
  border-radius: 10px;
  padding: 0.76rem;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.38);
}

.op-sidebar h2 {
  margin: 0 0 0.55rem;
  font-family: "Archivo Black", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.8rem;
}

.op-sidebar .controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.45rem;
}

.op-sidebar label {
  display: grid;
  gap: 0.24rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.op-sidebar select {
  width: 100%;
  min-width: 0;
}

/* Checkbox labels read as one line: [x] Draw Mode */
.op-sidebar label:has(> input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.op-editor-col {
  --editor-max: 640px;
  display: grid;
  /* One track exactly as wide as the column, so children's % widths
     resolve against the visible width instead of their own content. */
  grid-template-columns: minmax(0, 1fr);
  /* Without this the page strip (a scroll container) can be squeezed to 0 high. */
  grid-auto-rows: max-content;
  align-content: start;
  min-width: 0;
  gap: 0.55rem;
  justify-items: center;
  position: sticky;
  top: 82px;
  align-self: start;
  height: calc(100vh - 82px);
  overflow: auto;
}

.op-workspace-toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto auto auto;
  align-items: center;
  gap: 0.5rem;
  width: min(100%, var(--editor-max));
  padding: 0.35rem 0.45rem;
  border: 1px solid #334253;
  background: #1a2430;
}

.op-page-indicator {
  text-align: center;
  font-family: "Special Elite", monospace;
  font-size: 0.84rem;
  font-weight: 700;
  color: #d8e2ef;
}

.op-page-role {
  margin: 0;
  font-family: "Archivo Black", sans-serif;
  font-size: 0.86rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}

.op-page-frame {
  background: var(--stage-shell);
  border: 1px solid #2c3947;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.42);
  border-radius: 12px;
  padding: clamp(10px, 2vw, 18px);
  width: min(100%, var(--editor-max));
  display: grid;
  place-items: center;
}

/* Width and aspect-ratio are set from the page size by panel-editor.js. */
.op-stage {
  width: min(100%, 440px);
  aspect-ratio: 11 / 17;
  position: relative;
  background: #fff;
  border: 1px solid #324254;
  box-shadow: 0 0 0 4px #1a212a, 0 10px 24px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.op-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  touch-action: none;
  pointer-events: none; /* enabled only in draw mode */
}

/* Laid out at the logical page size and scaled to the displayed stage size,
   so item positions stay aligned with the drawing canvas at any screen width. */
.op-items-layer {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  pointer-events: auto;
  z-index: 1;
}

.op-safe-guide {
  position: absolute;
  border: 1px dashed rgba(10, 147, 150, 0.75);
  pointer-events: none;
  z-index: 4;
}

.op-safe-guide[hidden] { display: none; }

/* Page strip */
.op-panel-strip {
  --chip-h: 92px;
  position: relative;
  width: min(100%, var(--editor-max));
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  background: #1a2430;
  border: 1px solid #334253;
  padding: 0.45rem;
  border-radius: 0 0 8px 8px;
}

.op-panel-chip {
  flex: 0 0 auto;
  height: var(--chip-h);
  aspect-ratio: var(--page-aspect, 11 / 17);
  border: 2px solid var(--line);
  background: #151d26;
  font-size: 0.62rem;
  font-family: "Archivo Black", sans-serif;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  transition: border-color 80ms;
  padding: 2px;
  line-height: 1.2;
  color: var(--ink);
  position: relative;
  overflow: hidden;
  box-shadow: none;
}

.op-panel-chip:hover,
.op-panel-chip:active {
  transform: none;
}

.op-panel-chip.active {
  border-color: var(--accent);
  background: #1e2c3e;
}

.op-panel-chip .chip-thumb {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.85;
}

.op-panel-chip .chip-label {
  position: relative;
  z-index: 1;
  background: rgba(0, 0, 0, 0.55);
  padding: 1px 3px;
  font-size: 0.55rem;
  line-height: 1.3;
  text-align: center;
  white-space: pre-line;
}

/* Context controls */
.op-context {
  background: var(--context-bg);
}

.op-context[hidden] { display: none; }

/* Item styles */
.op-item {
  position: absolute;
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
}

.op-item[contenteditable="true"] {
  touch-action: auto;
  user-select: text;
  -webkit-user-select: text;
}

.op-item.selected {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.op-item.text {
  min-width: 60px;
  min-height: 20px;
  padding: 2px 4px;
  white-space: pre-wrap;
  cursor: move;
}

.op-item.text[contenteditable="true"] {
  cursor: text;
  outline: 2px solid var(--teal);
}

.op-item.image {
  cursor: move;
  overflow: hidden;
}

.op-item.image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.op-item.shape {
  cursor: move;
}

/* The long-text toolbar wraps to two rows in the narrow sidebar. */
.op-sidebar .long-text-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.op-sidebar .long-text-toolbar button {
  min-width: 0;
}

/* Flowed long text is laid out automatically; clicks pass through it. */
.op-item.richtext {
  pointer-events: none;
}

.op-item.shape.circle {
  border-radius: 999px;
}

.op-item.shape.triangle {
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.op-resize-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  background: #ff2e63;
  border: 2px solid #fff;
  cursor: nwse-resize;
  box-shadow: 0 0 0 2px #000;
  touch-action: none;
  z-index: 6;
}

/* Print / fold guide */
.fold-guide {
  width: min(100%, var(--editor-max));
  background: #141d26;
  border: 1px solid #2a3845;
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  display: grid;
  gap: 0.6rem;
}

.fold-guide h3 {
  margin: 0;
  font-family: "Archivo Black", sans-serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--teal);
}

.fold-guide-svg-wrap {
  width: 100%;
  border: 1px solid #2a3845;
  border-radius: 4px;
  overflow: hidden;
  background: #0f151d;
}

.fold-guide-svg-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 380px;
  margin: 0 auto;
}

.fold-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.fold-legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  color: #9db5cc;
}

.fold-legend-line {
  width: 28px;
  height: 2px;
}

.fold-steps {
  display: grid;
  gap: 0.25rem;
  padding-left: 1.2rem;
  margin: 0;
}

.fold-steps li {
  font-size: 0.73rem;
  color: #9db5cc;
  line-height: 1.55;
}

.fold-steps li strong {
  color: #c8d8e8;
}

.hint-strip {
  margin: 0;
  color: #dfe8f5;
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--acid);
  padding: 0.2rem 0.45rem;
  border: 1px solid #354252;
  width: min(100%, var(--editor-max));
  text-align: center;
}

.bg-color-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

.controls-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.controls-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

.controls-row-2 button,
.controls-row-3 button {
  font-size: 0.7rem;
  padding: 0.4rem 0.3rem;
}

/* Segmented toggle (e.g. Horizontal / Vertical) */
.seg-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.seg-toggle button {
  font-size: 0.7rem;
  padding: 0.4rem 0.3rem;
}

.seg-toggle button.active {
  background: var(--teal);
  color: #fff;
}

.setup-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: #b4c0cf;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.autosave-note {
  font-size: 0.68rem;
  color: #8fa3bc;
  text-align: center;
  margin: 0;
}

.autosave-note.warn {
  color: #ffcf70;
}

.guide-summary {
  margin: 0;
  font-size: 0.78rem;
  color: #d8e2ef;
}

.guide-warning {
  margin: 0;
  font-size: 0.74rem;
  color: #ffcf70;
  background: #3a2e12;
  border: 1px solid #6b5420;
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
}

.guide-warning[hidden] { display: none; }

.op-onboarding {
  width: min(100%, var(--editor-max));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: #14351f;
  border: 1px solid #2c6a44;
  color: #c4ecd2;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  font-size: 0.8rem;
}

.op-onboarding[hidden] { display: none; }

.op-onboarding button {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: #c4ecd2;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  min-height: auto;
}

#op-preview-dialog {
  width: min(520px, 94vw);
  border: 1px solid #3a4757;
  border-radius: 0;
  padding: 0;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.6);
}

#op-preview-dialog::backdrop { background: rgba(0, 0, 0, 0.62); }

.op-preview-shell {
  padding: 1rem;
  background: #161f29;
  color: var(--ink);
}

.op-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.op-preview-head h2 {
  margin: 0;
  font-family: "Archivo Black", sans-serif;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.op-flipbook-wrap {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 0.6rem;
}

.op-flipbook-page {
  width: 100%;
  aspect-ratio: var(--page-aspect, 11 / 17);
  max-height: 70vh;
  border: 1px solid #3a4757;
  background-color: #fff;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.45);
}

.op-flip-index {
  text-align: center;
  margin: 0.6rem 0 0;
  font-family: "Special Elite", monospace;
  font-size: 0.85rem;
}

.op-snap-guide {
  position: absolute;
  background: #ff2e63;
  opacity: 0.8;
  pointer-events: none;
  z-index: 9;
}

.op-snap-guide.v { width: 1px; top: 0; bottom: 0; left: 50%; }
.op-snap-guide.h { height: 1px; left: 0; right: 0; top: 50%; }

@media (max-width: 760px) {
  .op-layout {
    grid-template-columns: 1fr;
  }
  .op-editor-col {
    position: static;
    height: auto;
    overflow: visible;
  }
  .op-workspace-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Tablet: tighten sidebar, keep two columns */
@media (min-width: 761px) and (max-width: 1100px) {
  .op-layout {
    grid-template-columns: 230px 1fr;
    gap: 0.7rem;
    padding: 0.7rem;
  }
}

/* Narrower editors: page indicator gets its own row above the buttons. */
@media (max-width: 1100px) {
  .op-workspace-toolbar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .op-page-indicator {
    grid-column: 1 / -1;
    order: -1;
  }
  .op-workspace-toolbar button {
    min-width: 0;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
  }
}

/* Touch device enhancements (tablets) */
@media (pointer: coarse) {
  .op-resize-handle {
    width: 26px;
    height: 26px;
    right: -13px;
    bottom: -13px;
  }

  .op-sidebar button,
  .op-sidebar .file-upload,
  .op-workspace-toolbar button {
    min-height: 42px;
  }

  input[type="range"] {
    min-height: 30px;
  }

  input[type="color"] {
    min-width: 44px;
    min-height: 36px;
  }
}
