/* Promotion Image Generator (docs/04 S5, §3) */

:root {
  --bg-primary: #ffffff;
  --bg-panel: #f5f5f3;
  --text-primary: #333333;
  --text-secondary: #666666;
  --accent: #0b57d0;
  --danger: #c62828;
  --slot-outline: #8a9099;
  --border: #e0e0e0;
  --bar-height: 56px;
  --panel-width: 300px;
  --adjust-width: 320px;
}

body.pig {
  max-width: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
}

.pig h1,
.pig h2 {
  border-bottom: none;
  padding-bottom: 0;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Header bar */
.tool-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--bar-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.tool-logo img {
  display: block;
}

.tool-title {
  flex: 1;
  margin: 0;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-back {
  white-space: nowrap;
}

/* Three-pane layout, read in a Z: setup (left) → preview → adjust (right) (NFR-07) */
.tool-layout {
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr) var(--adjust-width);
  height: calc(100vh - var(--bar-height));
}

.panel {
  overflow-y: auto;
  background: var(--bg-primary);
}

.panel-setup {
  border-right: 1px solid var(--border);
}

.panel-adjust {
  border-left: 1px solid var(--border);
}

.panel-section {
  margin: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-section h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

fieldset {
  margin: 0 0 8px;
  padding: 0;
  border: none;
  min-width: 0;
}

legend {
  padding: 0;
  margin-bottom: 4px;
  font-weight: 600;
}

.text-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.text-group legend {
  padding: 0 4px;
  margin-bottom: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  min-width: 0;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}

.field > span,
.field-label {
  color: var(--text-secondary);
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field {
  flex: 1;
}

select,
input[type='number'],
input[type='text'],
textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid #b8bcc2;
  border-radius: 6px;
  font: inherit;
  color: inherit;
  background: #fff;
}

textarea {
  resize: vertical;
}

.size-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.size-row input[type='range'] {
  flex: 1;
  min-width: 0;
}

.size-row input[type='number'] {
  width: 68px;
}

.unit {
  color: var(--text-secondary);
}

.color-pair {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 8px;
}

.color-field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-field input[type='color'] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid #b8bcc2;
  border-radius: 6px;
  background: #fff;
}

.color-field input[type='text'] {
  width: 80px;
  font-family: ui-monospace, Consolas, monospace;
}

.color-field input[aria-invalid='true'] {
  border-color: var(--danger);
}

.heading-row legend {
  float: left;
  margin: 0 16px 0 0;
  line-height: 32px;
  font-size: 16px;
  font-weight: 700;
}

.radio-row label,
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 12px;
  min-height: 32px;
  cursor: pointer;
}

/* Layout thumbnails (UI4) */
.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 56px);
  gap: 10px;
  margin-bottom: 8px;
}

.thumb,
.direction {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #c9ccd1;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 150ms, box-shadow 150ms;
}

.thumb {
  width: 56px;
  height: 56px;
}

.thumb svg {
  width: 30px;
  height: 52px;
}

.thumb:hover,
.direction:hover {
  border-color: var(--accent);
}

.thumb[aria-pressed='true'],
.direction[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  background: #eef3fc;
}

.directions {
  display: flex;
  gap: 8px;
}

.direction {
  width: 44px;
  height: 36px;
  font-size: 18px;
  color: var(--text-primary);
}

/* Buttons (UI2) */
.actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}

.btn {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid #b8bcc2;
  border-radius: 6px;
  background: #fff;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  transition: background-color 150ms;
}

.btn:hover {
  background: #f0f0ee;
}

.btn-primary {
  flex: 1;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: #0947ab;
}

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Preview */
.preview-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-panel);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 24px 24px 0;
  display: grid;
  place-items: center;
}

.stage.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 8px;
}

.canvas-box {
  position: relative;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

.canvas-box canvas {
  display: block;
}

.overlays {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Slot overlays (UI5) */
.slot {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.slot.filled {
  cursor: pointer;
}

.slot.drop-target {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  background: rgba(11, 87, 208, 0.08);
}

.slot-add {
  width: 48px;
  height: 48px;
  border: 2px solid var(--slot-outline);
  border-radius: 50%;
  background: #fff;
  color: var(--text-primary);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.slot-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.slot-replace {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.slot-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms;
}

.slot:hover .slot-remove,
.slot:focus-within .slot-remove {
  opacity: 1;
}

/* Status line (UI6) */
.status {
  min-height: 21px;
  margin: 12px 24px 16px;
  text-align: center;
  color: var(--text-secondary);
}

.status.warning {
  color: var(--danger);
}

/* Footer */
.tool-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.tool-footer p {
  margin: 0 0 4px;
}

.tool-footer .ad-slot {
  max-width: 970px;
  margin: 0 auto 16px;
}

/* Dialog (UI3) */
.dialog {
  max-width: 400px;
  border: none;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Narrow screens: stack setup → preview → adjust (NFR-07) */
@media (max-width: 1023px) {
  .tool-layout {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }

  .panel {
    overflow: visible;
    border-right: none;
    border-left: none;
  }

  .preview-area {
    height: 75vh;
  }

  .stage {
    margin: 16px 16px 0;
  }

  .thumbs {
    grid-template-columns: repeat(auto-fill, 56px);
  }
}
