:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #657085;
  --line: #dbe1ea;
  --paper: #f6f8fb;
  --panel: #ffffff;
  --accent: #136f63;
  --accent-strong: #0d554b;
  --warm: #f6b851;
  --danger: #b33d2e;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(140deg, rgba(19, 111, 99, 0.11), transparent 32%),
    linear-gradient(28deg, rgba(246, 184, 81, 0.18), transparent 34%),
    var(--paper);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 390px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel,
.preview-column {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 225, 234, 0.9);
  box-shadow: 0 18px 50px rgba(23, 34, 51, 0.08);
}

.controls-panel {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 22px;
  border-radius: 8px;
}

.brand-row {
  display: flex;
  gap: 14px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.25rem;
  line-height: 1.2;
}

.brand-row p,
.preview-toolbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-stack {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

fieldset {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.quick-brief-panel {
  border: 1px solid rgba(19, 111, 99, 0.18);
  border-radius: 8px;
  background: #f3faf8;
  padding: 12px;
}

legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 7px;
  color: #344055;
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 111, 99, 0.15);
}

textarea {
  resize: vertical;
}

input[type="file"] {
  padding: 8px;
}

.toggle-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.preview-column {
  min-width: 0;
  padding: 20px;
  border-radius: 8px;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.preview-toolbar h2 {
  font-size: 1.2rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.left-buttons {
  justify-content: flex-start;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  border-color: #b7c1cf;
  background: #f9fbfd;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button[aria-busy="true"] {
  cursor: wait;
  opacity: 0.72;
}

button[aria-busy="true"]::after {
  content: "";
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.12em;
  animation: spin 0.8s linear infinite;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 9px;
  border-radius: 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
}

.icon-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-button[aria-busy="true"] svg {
  animation: spin 0.9s linear infinite;
}

.status-line {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

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

.background-status {
  flex: 1 1 100%;
  min-height: 20px;
  text-align: right;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.primary-button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.canvas-frame {
  display: grid;
  min-height: 420px;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #edf1f6 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f6 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f6 75%);
  background-color: #f9fbfd;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
  padding: 18px;
}

canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 760px);
  max-height: 70vh;
  box-shadow: 0 16px 42px rgba(23, 34, 51, 0.22);
}

.template-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.template-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.template-card[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 111, 99, 0.13);
}

.template-card strong {
  font-size: 0.92rem;
}

.template-card span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.caption-panel {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.caption-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.caption-header h2 {
  font-size: 1rem;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .controls-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 620px) {
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row {
    justify-content: stretch;
  }

  .button-row button {
    flex: 1 1 150px;
  }

  .canvas-frame {
    min-height: 280px;
    padding: 10px;
  }
}
