:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #14151a;
  --muted: #666b78;
  --accent: #2f6feb;
  --danger: #d64545;
  --success: #2a9d5c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --panel: #1e2025;
    --border: #2c2f36;
    --text: #eceef2;
    --muted: #9198a8;
  }
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

header h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

header .spacer { flex: 1; }

select, input[type="text"], input[type="url"], input[type="password"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary.danger {
  color: var(--danger);
  border-color: var(--danger);
}

main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

#queueBanner {
  background: rgba(47,111,235,0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  min-width: 120px;
}
.stat .value { font-size: 22px; font-weight: 600; }
.stat .label { font-size: 12px; color: var(--muted); }

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

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

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

.card .media {
  width: 100%;
  max-height: 420px;
  min-height: 120px;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.card .media img, .card .media video {
  width: 100%;
  max-height: 420px;
  /* Show the whole creative at its real proportions instead of cropping it
     to a forced square — ad creative is rarely 1:1 and cropping hides copy
     baked into the image (prices, headlines, etc). */
  object-fit: contain;
}
.card .media .no-media {
  color: var(--muted);
  font-size: 13px;
  padding: 40px 0;
}
.card .media .media-count {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}
.card .media .carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.45);
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card .media .carousel-nav:hover { background: rgba(0,0,0,0.7); }
.card .media .carousel-nav.prev { left: 8px; }
.card .media .carousel-nav.next { right: 8px; }

.card .body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge.active { background: rgba(42,157,92,0.15); color: var(--success); }
.badge.inactive { background: rgba(214,69,69,0.15); color: var(--danger); }

.card .copy {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 100px;
  overflow-y: auto;
}

.card .meta {
  font-size: 12px;
  color: var(--muted);
}

.platform-icons {
  display: flex;
  gap: 4px;
}
.platform-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: white;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  cursor: default;
}

.card .landing {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
}
.card .headline { font-size: 14px; font-weight: 600; }
.card .description { font-size: 12px; color: var(--muted); }

.card .actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
}
.card .actions a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  padding: 8px;
  border-radius: 6px;
}
.card .actions a.primary { background: var(--accent); color: white; }
.card .actions a.secondary { border: 1px solid var(--border); color: var(--text); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

dialog#settings {
  border: none;
  border-radius: 10px;
  padding: 20px;
  background: var(--panel);
  color: var(--text);
  width: min(420px, 90vw);
}
dialog#settings label { display: block; font-size: 13px; margin: 10px 0 4px; }
dialog#settings .row { display: flex; gap: 8px; margin-top: 16px; }

dialog#addCompetitor { border: none; border-radius: 10px; padding: 20px; background: var(--panel); color: var(--text); width: min(480px, 90vw); }
dialog#addCompetitor label { display: block; font-size: 13px; margin: 10px 0 4px; }
dialog#addCompetitor .row { display: flex; gap: 8px; margin-top: 16px; }
dialog#addCompetitor code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

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