/* Orles — full de estils
   Paleta monocroma, sense ombres pesades ni degradats. */

:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --ink: #141414;
  --ink-soft: #5c5c58;
  --ink-faint: #8d8d87;
  --line: #e0e0dc;
  --line-strong: #c9c9c3;
  --focus: #141414;
  --radius: 4px;
  --panel-w: 310px;
  --topbar-h: 56px;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }

/* ---------- Barra superior ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand h1 {
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-mark {
  width: 16px;
  height: 16px;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 6px 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 10px 0 / 6px 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 0 11px / 6px 5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 10px 11px / 6px 5px no-repeat;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.status {
  color: var(--ink-faint);
  font-size: 12px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Estructura ---------- */

.layout {
  position: relative;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
  height: calc(100% - var(--topbar-h));
}

.panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.group {
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
}

.group:last-child { border-bottom: 0; }

.group h2 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 14px;
}

/* ---------- Controls ---------- */

.field {
  display: block;
  margin-bottom: 12px;
  border: 0;
  padding: 0;
}

.field > span,
.check > span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.field output {
  float: right;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

input[type="text"],
select {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  appearance: none;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

input[type="text"]:focus-visible,
select:focus-visible,
button:focus-visible,
input[type="range"]:focus-visible,
input[type="color"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  height: 18px;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--line-strong);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--ink);
}

input[type="range"]::-moz-range-track { height: 1px; background: var(--line-strong); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border: 0; border-radius: 50%; background: var(--ink);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  cursor: pointer;
}

.check > span { margin: 0; color: var(--ink); }

.check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--ink);
  margin: 0;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented label {
  padding: 7px 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.segmented label + input + label { border-left: 1px solid var(--line-strong); }
.segmented input:checked + label { background: var(--ink); color: #fff; }
.segmented input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: -2px; }

.btn {
  height: 32px;
  padding: 0 12px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: #f0f0ed; }
.btn:active { background: #e6e6e2; }

.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #2c2c2c; }
.btn-primary:active { background: #000; }

.btn-quiet { border-color: transparent; color: var(--ink-soft); }
.btn-quiet:hover { border-color: var(--line-strong); }

.btn-block { width: 100%; }

.btn-icon { width: 32px; padding: 0; font-size: 15px; line-height: 1; }

.row { margin-bottom: 8px; }
.row:last-child { margin-bottom: 0; }
.row-split { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.hint {
  margin: 0 0 12px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-faint);
}

.counter { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------- Fons: mostres de color i estampats ---------- */

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 6px;
}

.swatch {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--swatch, #fff);
  cursor: pointer;
}

.swatch:hover { transform: scale(1.08); }

.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink);
}

.swatch-custom {
  overflow: hidden;
  background: conic-gradient(#f3b4b4, #f6e3a8, #b9e2c0, #b3d4f0, #d6c2ef, #f3b4b4);
}

.swatch-custom::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  color: var(--ink);
  pointer-events: none;
}

.swatch-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.swatch-custom:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }

.swatch-custom.is-custom { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink); }
.swatch-custom.is-custom::after { content: none; }

/* Desplegable amb miniatures (estampats i senefes) */

.picker { position: relative; }

.picker-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  padding: 4px 10px 4px 4px;
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}

.picker-toggle:hover { border-color: var(--ink-faint); }
.picker-toggle[aria-expanded="true"] { border-color: var(--ink); }

.picker-toggle canvas {
  flex: none;
  width: 58px;
  height: 30px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.picker-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.picker-chevron {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: -4px;
  border-right: 1.5px solid var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  transform: rotate(45deg);
  transition: transform 0.15s ease, margin 0.15s ease;
}

.picker-toggle[aria-expanded="true"] .picker-chevron { transform: rotate(-135deg); margin-top: 4px; }

.picker-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 380px;
  overflow-y: auto;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.picker-group {
  margin: 2px 0 6px;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.picker-grid:last-child { margin-bottom: 0; }

.pattern {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 4px 4px 5px;
  font: inherit;
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}

.pattern canvas {
  display: block;
  width: 100%;
  height: 32px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.pattern span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pattern:hover { border-color: var(--ink-faint); }

.pattern[aria-checked="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  color: var(--ink);
}

.pattern:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- Escenari ---------- */

.stage {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    repeating-conic-gradient(#efefec 0% 25%, var(--bg) 0% 50%) 0 0 / 18px 18px;
}

.stage-inner { position: relative; line-height: 0; }

#sheet {
  border: 1px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  touch-action: none;
  cursor: default;
}

#sheet.is-grabbable { cursor: grab; }
#sheet.is-grabbing { cursor: grabbing; }

/* Nansa per intercanviar fotos: apareix a la cantonada de la foto sota el punter. */
.swap-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--handle, 26px);
  height: var(--handle, 26px);
  display: grid;
  place-items: center;
  padding: 0;
  color: #fff;
  background: rgba(20, 20, 20, 0.82);
  border: 1.5px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: move;
  touch-action: none;
  transition: transform 0.12s ease, background 0.12s ease;
}

.swap-handle svg { width: 62%; height: 62%; }

.swap-handle:hover,
.swap-handle:focus-visible {
  background: #141414;
  transform: scale(1.12);
  outline: none;
}

.is-swapping,
.is-swapping * { cursor: grabbing !important; }

.is-swapping .swap-handle { opacity: 0; }

.dropzone {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--ink);
  background: rgba(244, 244, 242, 0.88);
  font-size: 13px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* ---------- Fitxa de la fotografia ---------- */

.inspector {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: 248px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.09);
}

.inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.inspector-head strong { font-size: 12px; font-weight: 600; }

.inspector .hint { margin-bottom: 10px; }

.inspector-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.inspector-actions + .inspector-actions { margin-top: 6px; }
.inspector-actions-split { display: flex; align-items: center; justify-content: space-between; }
.order { display: flex; gap: 6px; }

/* ---------- Superposició ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(244, 244, 242, 0.8);
  z-index: 10;
}

.overlay-box {
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

[hidden] { display: none !important; }

/* ---------- Adaptació a pantalles estretes ---------- */

@media (max-width: 860px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .stage { min-height: 70vh; padding: 16px; }
  .inspector { position: fixed; right: 12px; bottom: 12px; left: 12px; width: auto; }
}
