/* Design Studio editor. Uses global.css tokens only. */

.studio-page {
  padding: 0;
  max-width: none;
}

.studio {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  background: var(--color-bg-alt);
}

.studio__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--container-pad);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.studio__title {
  font-size: var(--text-lg);
  font-weight: var(--font-extrabold);
  color: var(--color-brand);
  margin: 0;
}

.studio__header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-left: auto;
}

.studio__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.studio__workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.studio__canvas-wrap {
  flex: 1;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm);
  overflow: hidden;
  touch-action: none;
  background: var(--color-bg);
}

.studio__canvas-inner {
  position: relative;
  max-width: 100%;
  max-height: 100%;
}

.studio__canvas-inner svg {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
}

.studio__view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  overflow: hidden;
}

.studio__view-btn {
  padding: 0.4rem 0.75rem;
  border: none;
  background: var(--color-bg);
  color: var(--color-body);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  cursor: pointer;
}

.studio__view-btn.is-active {
  background: var(--color-brand);
  color: var(--color-white);
}

.studio__view-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.studio__wrap-note {
  font-size: var(--text-sm);
  color: var(--color-meta);
  padding: var(--space-xs) var(--container-pad);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.studio__panels {
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  max-height: 50vh;
  overflow: auto;
}

.studio__panel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-bg);
  z-index: 2;
}

.studio__tab {
  flex: 1 1 auto;
  min-width: 4.5rem;
  padding: 0.65rem 0.5rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-body);
  cursor: pointer;
}

.studio__tab.is-active {
  color: var(--color-brand);
  border-bottom-color: var(--color-accent);
}

.studio__tab:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.studio__panel {
  padding: var(--space-md) var(--container-pad);
}

.studio__panel[hidden] {
  display: none !important;
}

.studio-picker__groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.studio-picker__group-title {
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  color: var(--color-brand);
  margin: 0 0 var(--space-sm);
}

.studio-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-sm);
}

.studio-picker__tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.studio-picker__tile:hover,
.studio-picker__tile:focus-visible {
  border-color: var(--color-brand);
  outline: none;
}

.studio-picker__tile.is-selected {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent);
}

.studio-picker__tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: var(--color-bg-alt);
  border-radius: 0;
}

.studio-picker__label {
  padding: var(--space-xs);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-brand);
}

.studio-picker__price {
  padding: 0 var(--space-xs) var(--space-xs);
  font-size: var(--text-xs);
  color: var(--color-meta);
}

.studio-colors {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-md);
}

.studio-colors__chip {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  cursor: pointer;
  padding: 0;
}

.studio-colors__chip.is-selected {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 2px var(--color-accent);
}

.studio-colors__chip:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.studio-layer-list {
  list-style: none;
  margin: 0 0 var(--space-md);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.studio-layer-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-alt);
  cursor: pointer;
}

.studio-layer-list__item.is-selected {
  border-color: var(--color-accent);
  background: var(--color-bg);
}

.studio-layer-list__item.has-error {
  border-color: var(--color-accent);
}

.studio-layer-list__name {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--color-brand);
}

.studio-layer-list__actions {
  display: flex;
  gap: 0.25rem;
}

.studio-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  border-radius: var(--radius-btn);
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.studio-btn--primary {
  background: var(--color-accent);
  color: var(--color-white);
}

.studio-btn--secondary {
  background: var(--color-brand);
  color: var(--color-white);
}

.studio-btn--ghost {
  background: transparent;
  color: var(--color-brand);
  border: 1px solid var(--color-border);
}

.studio-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.studio-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.studio-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
}

.studio-field {
  margin-bottom: var(--space-sm);
}

.studio-field label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-brand);
  margin-bottom: 0.25rem;
}

.studio-field input[type="text"],
.studio-field input[type="email"],
.studio-field textarea,
.studio-field select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  font-family: var(--font-family);
  font-size: var(--text-base);
}

.studio-field textarea {
  min-height: 4.5rem;
  resize: vertical;
}

.studio-inks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.studio-inks__swatch {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  cursor: pointer;
  padding: 0;
}

.studio-inks__swatch.is-selected {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 2px var(--color-accent);
}

.studio-font-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 10rem;
  overflow: auto;
}

.studio-font-list__item {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  background: var(--color-bg);
  cursor: pointer;
  font-size: var(--text-base);
}

.studio-font-list__item.is-selected {
  border-color: var(--color-accent);
}

.studio-issues {
  list-style: none;
  margin: 0;
  padding: 0;
}

.studio-issues__item {
  padding: var(--space-xs) 0;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-border);
}

.studio-issues__item--error {
  color: var(--color-accent);
}

.studio-issues__item--warn {
  color: var(--color-body);
}

.studio-library-tabs {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
}

.studio-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: var(--space-xs);
  max-height: 12rem;
  overflow: auto;
}

.studio-library-grid button {
  padding: var(--space-xs);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-alt);
  cursor: pointer;
}

.studio-library-grid button img,
.studio-library-grid button svg {
  width: 100%;
  height: 48px;
  object-fit: contain;
}

.studio-meter {
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.25rem;
}

.studio-meter__fill {
  height: 100%;
  background: var(--color-brand);
  transition: width 0.2s ease, background 0.2s ease;
}

.studio-meter__fill.is-warn {
  background: #f9a825;
}

.studio-meter__fill.is-bad {
  background: var(--color-accent);
}

.studio-dialog {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  background: rgba(33, 33, 33, 0.45);
}

.studio-dialog[hidden] {
  display: none !important;
}

.studio-dialog__card {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: var(--space-lg);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.studio-dialog__title {
  margin: 0 0 var(--space-sm);
  font-size: var(--text-xl);
  color: var(--color-brand);
}

.studio-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-md);
}

.studio-dialog__preview img {
  width: 100%;
  border-radius: var(--radius-sm);
}

.studio-status {
  font-size: var(--text-xs);
  color: var(--color-meta);
}

/* The handle element is the invisible touch target; the small visible dot is
   drawn beside it in canvas.js. Painting the target made each handle a large
   white disc that hid short text. */
.studio-handle {
  fill: transparent;
  stroke: none;
  cursor: grab;
}

@media (max-width: 768px) {
  .studio__panels {
    max-height: none;
  }

  .studio__canvas-wrap {
    min-height: 240px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .studio-picker__tile,
  .studio-meter__fill {
    transition: none;
  }
}

/* Picker action bar (desktop CC review, 2026-09-19): color + Start stay in reach. */
.studio-picker { padding-bottom: 7rem; }
.studio-picker__bar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-sm);
  margin-top: var(--space-md); padding: var(--space-sm);
  padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
  background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 0.06);
}
.studio-picker__bar .studio-picker__group-title { margin: 0 0 .4rem; font-size: var(--text-sm); }

/* Desktop: canvas and controls side by side (desktop CC review, 2026-09-19).
   Stacked, the canvas filled the screen and every control sat below the fold,
   so each edit meant scrolling between the shirt and the text box. */
@media (min-width: 960px) {
  .studio__workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    align-items: start;
  }
  .studio__workspace > :not(.studio__panels) { grid-column: 1; }
  .studio__panels {
    grid-column: 2;
    grid-row: 1 / span 4;
    position: sticky;
    top: 0;
    max-height: calc(100vh - 140px);
    border-top: 0;
    border-left: 1px solid var(--color-border);
  }
  .studio__canvas-wrap {
    height: calc(100vh - 210px);
    min-height: 420px;
  }
}

/* Phones: the canvas gets most of the screen; panels scroll below it. */
@media (max-width: 768px) {
  .studio__canvas-wrap { min-height: 58vh; }
}

/* Way back to the simple path, for someone who only has a photo. */
.studio-alt { margin: 0; padding: var(--space-xs) var(--container-pad); font-size: var(--text-sm); color: var(--color-body); background: var(--color-bg); border-bottom: 1px solid var(--color-border); }
.studio-alt a { color: var(--color-brand); font-weight: var(--font-semibold); }

/* global.css caps paragraph width for reading; this line is a full-width bar. */
.studio-alt { max-width: none; }

/* ─── Header parts shared by both layouts (2026-09-19) ─────────────────── */
.studio__viewbar {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem var(--container-pad);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.studio__sm { display: none; }
.studio__back { margin-right: var(--space-xs); }

/* ─── Phones: an app-style editor ─────────────────────────────────────────
   Full screen while editing, so the product is always in view: a compact top
   bar, the canvas filling the middle, and the panels as a bottom sheet over a
   tab bar. Tapping the open tab again folds the sheet away. The canvas
   redraws to fit whatever the sheet leaves (ResizeObserver in canvas.js).
   Andy, 2026-09-19: "really need to work on the mobile design". */
@media (max-width: 768px) {
  html.studio-app-mode,
  html.studio-app-mode body { overflow: hidden; overscroll-behavior: none; }

  .studio.studio--editing {
    position: fixed;
    inset: 0;
    z-index: 150;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
  }

  .studio--editing .studio__header {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  .studio--editing .studio__title,
  .studio--editing #studioSaveStatus { display: none; }
  .studio--editing .studio__header-actions { flex-wrap: nowrap; gap: 6px; align-items: center; }
  .studio--editing .studio__header .studio-btn { min-height: 40px; padding: 0 12px; font-size: 0.85rem; white-space: nowrap; }
  .studio--editing #studioUndo,
  .studio--editing #studioRedo,
  .studio--editing .studio__back { width: 40px; padding: 0; font-size: 1.15rem; }
  .studio--editing .studio__lg { display: none; }
  .studio--editing .studio__sm { display: inline; }

  .studio--editing .studio__body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .studio--editing .studio__workspace { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; position: relative; }
  .studio--editing .studio__wrap-note { margin: 0; padding: 4px 12px; font-size: 0.75rem; }

  /* Product / Flat floats over the canvas corner instead of taking a row. */
  .studio--editing .studio__viewbar {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    padding: 0;
    background: none;
    border: 0;
  }

  .studio--editing .studio__canvas-wrap {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto !important;
    padding: 8px;
  }

  .studio--editing .studio__panels {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    max-height: none;
    overflow: visible;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
    box-shadow: 0 -6px 18px rgb(0 0 0 / 0.06);
  }
  .studio--editing .studio__panel {
    order: 1;
    max-height: 42vh;
    max-height: 42dvh;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 12px 14px;
  }
  .studio--editing .studio__panels.is-sheet-closed .studio__panel { display: none !important; }
  .studio--editing .studio__panels.is-sheet-closed { box-shadow: none; }

  /* The tab bar sits at the bottom, clear of the home indicator. */
  .studio--editing .studio__panel-tabs {
    order: 2;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    border-top: 1px solid var(--color-border);
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .studio--editing .studio__tab {
    min-height: 52px;
    padding: 0 2px;
    font-size: 0.78rem;
    font-weight: 700;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .studio--editing .studio__tab.is-active { color: var(--color-brand); box-shadow: inset 0 3px 0 var(--color-accent); }
  .studio--editing .studio__panels.is-sheet-closed .studio__tab.is-active { color: inherit; box-shadow: none; }

  /* Fonts scroll sideways instead of stacking eight rows tall. */
  .studio--editing .studio-font-list { display: flex; flex-direction: row; max-height: none; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
  .studio--editing .studio-font-list > * { flex: 0 0 auto; width: auto; white-space: nowrap; }
  .studio--editing .studio-field { margin-bottom: 12px; }
}
