/* Manual Cross-Stitch Designer — layout & controls.
   Reuses the CSS variables and button/badge styles from styles.css + tools.css. */

.designer-section { padding: 26px 0 40px; }
.designer-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 250px;
  gap: 18px;
  align-items: start;
}

.ds-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius, 12px);
  box-shadow: var(--shadow, 0 4px 20px rgba(0,0,0,.05));
}
.ds-block { padding: 16px; border-bottom: 1px solid var(--line); }
.ds-block:last-child { border-bottom: 0; }
.ds-block h3 { margin: 0 0 12px; font-size: .95rem; font-weight: 800; }
.ds-hint { margin: 8px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }

.ds-row { margin-bottom: 10px; }
.ds-row label { display: flex; justify-content: space-between; font-size: .82rem; font-weight: 600; margin-bottom: 5px; }
.ds-row label span { color: var(--brand); }
.ds-row input[type="number"] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: .9rem; }
.ds-row input[type="range"] { width: 100%; }
.ds-full { width: 100%; }

.ds-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.ds-tool {
  padding: 10px 6px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; cursor: pointer; font-size: .82rem; font-weight: 700; color: var(--text);
}
.ds-tool:hover { border-color: var(--brand); }
.ds-tool.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.ds-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.ds-actions .btn:last-child { grid-column: 1 / -1; }
.ds-actions .btn { padding: 9px 6px; font-size: .8rem; }
.ds-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ds-seg button { padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font-size: .78rem; font-weight: 700; color: var(--muted); }
.ds-seg button:hover { border-color: var(--brand); }
.ds-seg button.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.ds-check { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: .84rem; font-weight: 600; cursor: pointer; }
.ds-check input { accent-color: var(--brand); }

.ds-palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-height: 300px; overflow-y: auto; padding-right: 4px; }
.ds-swatch {
  aspect-ratio: 1; border: 2px solid #fff; border-radius: 7px; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line); position: relative;
}
.ds-swatch:hover { transform: scale(1.08); }
.ds-swatch.on { box-shadow: 0 0 0 2px var(--brand); z-index: 1; }
.ds-current {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  padding: 8px; border-radius: 9px; background: var(--brand-soft); font-size: .8rem; font-weight: 700;
}
.ds-current .chip { width: 20px; height: 20px; border-radius: 5px; box-shadow: 0 0 0 1px var(--line); flex: none; }

.ds-stage {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius, 12px);
  box-shadow: var(--shadow, 0 4px 20px rgba(0,0,0,.05)); padding: 16px;
}
.ds-stage-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.ds-viewtoggle { font-size: .82rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.ds-canvas-wrap {
  overflow: auto; max-height: 70vh; background: #fafafa; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; display: flex; justify-content: center; align-items: flex-start;
}
#dsCanvas { background: #fff; touch-action: none; cursor: crosshair; image-rendering: pixelated; max-width: 100%; height: auto; }
.ds-export { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ds-export .btn { flex: 1 1 auto; font-size: .85rem; }

.ds-thread-wrap { max-height: 460px; overflow-y: auto; }

/* Side panels: stay below the sticky header and scroll on their own,
   so the canvas stays put while browsing controls or the color palette. */
.designer-layout > .ds-panel:first-child,
.designer-layout > .ds-threads {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.designer-layout > .ds-threads {
  max-height: calc(100vh - var(--header-h) - 32px);
}
/* The control panel starts below the page hero, so a full-viewport max-height
   pushes its scrollbar off screen. Cap it to the room actually left below it. */
.designer-layout > .ds-panel:first-child {
  max-height: max(120px, calc(100vh - 460px));
}
.designer-layout > .ds-panel:first-child::-webkit-scrollbar,
.designer-layout > .ds-threads::-webkit-scrollbar { width: 8px; }
.designer-layout > .ds-panel:first-child::-webkit-scrollbar-thumb,
.designer-layout > .ds-threads::-webkit-scrollbar-thumb { background: #d8d2c9; border-radius: 8px; }
.designer-layout > .ds-panel:first-child::-webkit-scrollbar-thumb:hover,
.designer-layout > .ds-threads::-webkit-scrollbar-thumb:hover { background: var(--brand); }

.ds-thread-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.ds-thread-table th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); color: var(--muted); font-weight: 700; }
.ds-thread-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ds-swatch-mini { display: inline-block; width: 14px; height: 14px; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); vertical-align: middle; margin-right: 5px; }

@media (max-width: 1080px) {
  .designer-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .ds-threads { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .designer-layout { grid-template-columns: 1fr; }
  .ds-tools { grid-template-columns: repeat(4, 1fr); }
  .ds-palette { grid-template-columns: repeat(10, 1fr); }
  .designer-layout > .ds-panel:first-child,
  .designer-layout > .ds-threads { position: static; max-height: none; overflow-y: visible; }
}
