:root {
  color-scheme: light;
  --bg: #eef0ec;
  --panel: #ffffff;
  --panel-soft: #f8f9f5;
  --line: #d7d9d2;
  --line-strong: #b7bdb3;
  --text: #171a1f;
  --muted: #626a61;
  --accent: #236b58;
  --accent-dark: #16483b;
  --blue: #2f5f9f;
  --warn: #945900;
  --err: #a12424;
  --shadow: 0 12px 28px rgba(24, 28, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 14px;
  line-height: 1.25;
}

h4 {
  font-size: 13px;
  line-height: 1.25;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.topbar p,
.muted,
.subtle {
  color: var(--muted);
  font-size: 13px;
}

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

.status,
.mini {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.left-rail,
.main-rail {
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

form {
  display: grid;
  gap: 12px;
}

label,
fieldset {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #c6c9c0;
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(47, 95, 159, 0.45);
  outline-offset: 2px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.date-fields {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

body[data-date-mode="date"] .date-fields,
body[data-date-mode="range"] .date-fields {
  display: grid;
}

.date-field {
  display: none;
}

body[data-date-mode="date"] .date-single,
body[data-date-mode="range"] .date-range {
  display: grid;
}

.preset-bar,
.check-row,
.actions,
.selection-actions,
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

button,
.button-link {
  min-height: 36px;
  border: 1px solid #b9beb4;
  border-radius: 6px;
  background: #f8f9f6;
  color: var(--text);
  cursor: pointer;
}

button {
  padding: 7px 10px;
}

button:hover,
.button-link:hover {
  border-color: #90978d;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

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

button.primary:hover,
.primary-link:hover {
  background: var(--accent-dark);
  color: #fff;
  text-decoration: none;
}

.preset.active {
  border-color: var(--blue);
  background: #edf3ff;
  color: #173d73;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  margin-top: 4px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid #c6c9c0;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.check-pill input {
  width: auto;
  min-height: auto;
}

.format-field {
  max-width: 140px;
}

.source-list,
.list,
.detail-grid,
.run-list {
  display: grid;
  gap: 10px;
}

.empty {
  color: var(--muted);
  font-size: 13px;
}

.source-card,
.job-row,
.batch-row,
.run-card,
.creative-card,
.detail-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.source-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(128px, 180px) minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
}

.source-card.selected {
  border-color: rgba(35, 107, 88, 0.55);
  background: #f5faf7;
}

.card-select {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: auto;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 12px;
}

.card-select input {
  width: auto;
  min-height: auto;
}

.image-button {
  display: block;
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.image-button img,
.creative-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #e8ebe4;
  border: 1px solid #d8dbd4;
  border-radius: 6px;
}

.source-body {
  min-width: 0;
  padding-right: 4px;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  max-width: 100%;
  border: 1px solid #cfd3ca;
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.pill.ok {
  color: var(--accent-dark);
  border-color: #a8cabc;
}

.pill.err {
  color: var(--err);
  border-color: #e0abab;
}

.pill.warn {
  color: var(--warn);
  border-color: #e4c084;
}

.batch-row,
.job-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
}

.job-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.job-title-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.job-progress {
  display: grid;
  gap: 8px;
}

.job-progress-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 12px;
}

.source-progress-list {
  display: grid;
  gap: 6px;
}

.source-progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  border: 1px solid #d8dbd4;
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  font-size: 12px;
}

.source-progress-row strong {
  display: block;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.source-progress-row > span {
  color: var(--muted);
  white-space: nowrap;
}

.source-progress-row.source-running {
  border-color: #e1c17d;
  background: #fffaf0;
}

.source-progress-row.source-done {
  border-color: #a8cabc;
  background: #f5faf7;
}

.source-progress-row.source-failed {
  border-color: #e0abab;
  background: #fff8f8;
}

.error {
  margin-top: 8px;
  color: var(--err);
  font-size: 13px;
  overflow-wrap: anywhere;
}

a,
.button-link {
  color: var(--accent-dark);
  text-decoration: none;
  font-size: 13px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 7px 10px;
}

a:hover {
  text-decoration: underline;
}

.detail-summary {
  padding: 10px;
}

.run-card {
  padding: 12px;
}

.run-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.compare-grid {
  display: grid;
  grid-template-columns: minmax(140px, 210px) minmax(0, 1fr);
  gap: 12px;
}

.variant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.creative-card {
  padding: 8px;
  min-width: 0;
}

.creative-card h4 {
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.source-original {
  background: #f3f5ef;
}

.failed-card {
  min-height: 140px;
  background: #fff8f8;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 56px 18px 18px;
  background: rgba(9, 12, 15, 0.78);
}

.modal[hidden] {
  display: none;
}

.modal img {
  max-width: min(96vw, 1100px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.modal-close {
  position: fixed;
  top: 14px;
  right: 14px;
  border-color: rgba(255, 255, 255, 0.36);
  background: #fff;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar,
  .top-actions,
  .run-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar,
  .layout {
    padding: 12px;
  }

  .grid-2,
  .grid-3,
  .date-fields,
  .actions,
  .preset-bar,
  .source-card,
  .batch-row,
  .job-row,
  .compare-grid {
    grid-template-columns: 1fr;
  }

  .source-card {
    gap: 10px;
  }

  .format-field {
    max-width: none;
  }
}
