/* The fill creator: the shapes tab, and the Patterns tab's Generate and Upload views */

/* Back button inside the creator. It keeps the room above it that the Patterns tab's first heading
   has, and the height of the buttons beside it; a short screen gives both to the view under it. */
#fillCreator {
  --creator-bar-room: 10px;
  --creator-bar-height: 44px;
}

/* The fill picker's short window (fill-picker.css). */
@media (max-height: 700px) {
  #fillCreator {
    --creator-bar-room: 0px;
    --creator-bar-height: auto;
  }
}

.fill-creator-bar {
  display: none;
  justify-content: space-between;
  gap: 8px;
  margin: var(--creator-bar-room) 0 8px;
}

.fill-creator-bar button {
  align-items: center;
  gap: 6px;
  min-height: var(--creator-bar-height);
  padding: 6px 12px;
  border: 1px solid var(--line-3);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--ink-6);
  font-size: 0.85em;
  cursor: pointer;
  transition: background-color 0.15s;
}

@media (hover: hover) {
  .fill-creator-bar button:hover {
    background: var(--line-1);
  }
}

/* Generate and Upload open from the Patterns tab's lists, so they have a way back to them. */
#fillCreator:is([data-mode="generate"], [data-mode="upload"]) > .fill-creator-bar {
  display: flex;
  align-items: center;
}


#materialUpload {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

/* The drop zone keeps the room under it that every view keeps under its buttons; while cropping,
   the crop buttons carry that room themselves. */
#fillCreator:not([data-cropping]) #materialUpload {
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}

/* The creator fills its tab, and the preview takes what the controls leave, so a short phone gets
   a small preview rather than a scroll to reach the Use button. */
.fill-creator-column {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
}

#fillCreatorForm {
  gap: 8px;
}

#colorModal:not([data-creator-preview]) #fillCreatorForm {
  flex: none;
}

#fillCreator:not([data-mode="pattern"]) .pattern-only {
  display: none;
}

#fillCreator:not([data-pattern-type="stripes"]) #patternRotationField {
  display: none;
}

#fillPreview {
  position: relative;
  flex: 1 1 64px;
  min-height: 64px;
}

/* Over the empty preview while a generation runs, so nothing here moves the form. */
/* From the top, since the foot can cover the preview's lower part on a short phone. */
#generationWaitNote {
  position: absolute;
  inset: 0;
  z-index: 1;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-start;
  overflow: auto;
  padding: 8px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
}

#generationWaitNote p {
  margin: 0;
  font-style: italic;
}

.preview-svg {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border: 3px solid var(--ink-black);
  border-radius: 5px;
}

/* An empty frame waiting for a result shouldn't read as the strongest thing on the screen. */
#colorModal[data-creator-empty] #fillPreviewSection .preview-svg {
  border-color: var(--line-3);
}

.fill-controls {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

/* One row per color, so each row's buttons go straight to that color. */
.pattern-fields {
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
}

.pattern-fields label,
.pattern-color-label {
  font-size: 0.9em;
  text-align: left;
  white-space: nowrap;
}

/* Leaves room for its longest type beside the chevron on the narrowest tab. */
#patternType {
  grid-column: 2 / -1;
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  padding-right: 1.5em;
  border-radius: 4px;
}

.pattern-paint-brands {
  min-height: 44px;
  margin: 0;
  padding-inline: 10px;
  white-space: nowrap;
}

.pattern-color-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  padding: 3px 12px 3px 3px;
  border: 1px solid var(--line-4);
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--ink);
  cursor: pointer;
}

.fill-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 0.9em;
  text-align: left;
}

.fill-field label {
  white-space: nowrap;
}

.fill-field-rest {
  grid-column: span 2;
}

/* Size has the row to itself, beside Rotation only on the type that has one. */
#fillCreator:not([data-mode="pattern"][data-pattern-type="stripes"]) .fill-field-wide {
  grid-column: 1 / -1;
}

.pattern-color-slot {
  flex: 1 1 0;
  box-sizing: border-box;
  min-width: 0;
  height: 100%;
  border: 1px solid var(--line-4);
  border-radius: 3px;
}

/* The tools at the top, then the preview with Size and Use at its foot, all fitting without a
   scroll. The preview takes what the tab leaves. */
#fillPreviewSection {
  container: fill-preview / size;
  flex: 1 1 0;
  min-height: 0;
}

#fillPreviewSection[hidden] {
  display: none;
}

.fill-preview-layout {
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-sizing: border-box;
  height: 100%;
  padding-bottom: 8px;
}

#fillCreator[data-mode="pattern"] #fillCreatorForm {
  gap: 12px;
}

.fill-preview-layout .fill-controls {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.fill-preview-layout .fill-field-rest {
  grid-column: auto;
}

/* Too short to stack: the preview goes beside the controls. */
@container fill-preview (max-height: 200px) {
  .fill-preview-layout {
    display: grid;
    grid-template-columns: minmax(100px, 45%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "preview controls"
      "preview actions";
    gap: 4px 12px;
  }

  #fillPreview {
    grid-area: preview;
    min-height: 0;
  }

  /* Too narrow beside the preview for Size and Rotation to share a line. */
  .fill-preview-layout .fill-controls {
    grid-area: controls;
    grid-template-columns: minmax(0, 1fr);
    align-self: end;
  }

  .fill-preview-layout .fill-picker-actions {
    grid-area: actions;
  }
}

/* Shorter still: each label sits beside its slider, for the two to fit above Use. */
@container fill-preview (max-height: 140px) {
  .fill-preview-layout {
    grid-template-columns: 80px minmax(0, 1fr);
  }

  .fill-preview-layout .fill-field {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .fill-preview-layout .fill-field label {
    flex: none;
  }
}

/* Paint Brands: the paint tools in place of the form, until a paint is picked or Back is tapped. */
#patternPaintView {
  container: paint-view / inline-size;
  position: relative;
  display: none;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
}

#fillCreator[data-view="paints"] #patternPaintView,
#colorModal.is-searching #patternPaintView {
  display: flex;
}

#fillCreator[data-view="paints"] .creator-form-part,
#colorModal.is-searching .creator-form-part {
  display: none;
}

/* The room at the bar's end is for the brands menu, which sits over it (#patternPaintSlot .paint-toolbar). */
#patternPaintView .fill-creator-bar {
  --brand-menu-room: 170px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 44px;
  padding-right: var(--brand-menu-room);
  white-space: nowrap;
}

#patternPaintsTitle {
  margin: 0;
  font-size: 1em;
}

#patternPaintSlot {
  flex: 1 1 0;
  min-height: 0;
}

/* Only the brands menu comes along, so it takes the end of the bar's line rather than one of its own. */
#patternPaintSlot .paint-toolbar {
  position: absolute;
  top: var(--creator-bar-room);
  right: 0;
  padding: 0;
}

/* Narrow, Back shows its arrow only, so the title and the brands menu's label keep one line. */
@container paint-view (max-width: 400px) {
  #patternPaintsBack .back-label {
    display: none;
  }
}

.upload-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--danger);
  font-size: 0.85em;
}

/* Fills what the tab leaves, so Crop and Use Image stay in reach under it. */
#editingContainer {
  position: relative;
  flex: 1 1 0;
  box-sizing: border-box;
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--line-4);
}

#imageContainer {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#imageContainer img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  max-height: 100%;
}

.drop-zone {
  box-sizing: border-box;
  flex: 1 1 0;
  width: 100%;
  min-height: 120px;
  padding: 16px 20px;
  border: 2px dotted var(--ink-1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-1);
  text-align: center;
  border-radius: 10px;
  cursor: pointer;
}

/* The fill picker's phone sheet (fill-picker.css). The zone grows into whatever the view leaves; its
   floor is low enough for Make your own to stay on screen under it. */
@media (max-width: 768px), (max-height: 500px) {
  .drop-zone {
    min-height: 72px;
  }
}

.drop-zone.dragover {
  border-color: var(--ink-black);
  color: var(--ink-black);
}

#uploadFileSpan {
  color: var(--ui-accent);
  text-decoration: underline;
  cursor: pointer;
}

@media (hover: hover) {
  #uploadFileSpan:hover {
    text-decoration: underline;
  }
}

#cropControls {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  gap: 8px;
}

/* How far each tap area reaches past what it draws (the `tap-area` rule in tokens.css). */
.pattern-color-pick { --tap-x: -3px; }
.fill-creator-bar button { --tap-x: var(--tap-to-size); --tap-bottom: -11px; }
