:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #1a73e8;
  --good: #1e8e3e;
  --warn: #b8860b;
  --bad: #d93025;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-mark {
  height: 34px;
  width: auto;
  border-radius: 0;
  flex-shrink: 0;
  display: block;
}

header.topbar h1 {
  font-size: 17px;
  margin: 0;
}

header.topbar .sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 20px 24px 60px;
  align-items: start;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

.form-panel {
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.field .hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
}

.field input[type="text"],
.field input[type="url"],
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.field textarea { resize: vertical; min-height: 56px; }

.count {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  margin-top: 3px;
}

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

.thumb-box {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.thumb-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.thumb-box .empty-label { font-size: 9.5px; color: var(--muted); text-align: center; padding: 2px; }

.upload-row input[type="file"] { font-size: 12px; flex: 1; }

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.photo-thumbs-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 0;
}

.photo-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fafafa;
  overflow: hidden;
  flex-shrink: 0;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb-index {
  position: absolute;
  left: 3px;
  bottom: 3px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
}

.photo-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.photo-thumb-remove:hover { background: var(--bad); }

.focal-grid {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  grid-template-rows: repeat(3, 28px);
  gap: 4px;
  margin-top: 8px;
}

.focal-grid button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}

.focal-grid button.active {
  background: var(--accent);
  border-color: var(--accent);
}

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

.color-row input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  background: #fff;
}

.color-row input[type="text"] {
  width: 100px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: #a9c6f5; cursor: not-allowed; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }

.export-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.export-msg { font-size: 11.5px; color: var(--muted); min-height: 14px; }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.grid-section {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 2px;
  margin-top: 4px;
}
.grid-section:first-child { margin-top: 0; }

.weight-badge.static-badge {
  background: #eef0f3;
  color: var(--muted);
}

.preview-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.preview-head .muted { color: var(--muted); font-weight: 400; }

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

.preview-actions button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 5px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 13px;
}

.weight-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef0f3;
  color: var(--muted);
}
.weight-badge.good { background: #e6f4ea; color: var(--good); }
.weight-badge.warn { background: #fdf3dc; color: var(--warn); }
.weight-badge.bad  { background: #fce8e6; color: var(--bad); }

.preview-stage {
  margin: 16px auto;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.preview-stage iframe { display: block; }

/* ---------- saved campaigns ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, .5);
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  z-index: 100;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 { font-size: 15px; margin: 0; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); }

.modal-body {
  overflow-y: auto;
  padding: 12px 16px;
}

.empty-note {
  color: var(--muted);
  font-size: 13px;
  padding: 24px 8px;
  text-align: center;
}

.campaign-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
}

.campaign-row:last-child { border-bottom: none; }

.campaign-thumb {
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--border);
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
}

.campaign-thumb iframe { display: block; }

.campaign-info { flex: 1; min-width: 0; }

.campaign-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.campaign-date { font-size: 11.5px; margin-top: 2px; }

.campaign-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.campaign-actions button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.campaign-actions button.danger {
  color: var(--bad);
  border-color: #f3c9c5;
}
.campaign-actions button.danger:hover { background: #fce8e6; }
