:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #69707d;
  --line: #dfe3ea;
  --accent: #c8324b;
  --accent-2: #256f6b;
  --warn: #a06416;
  --bad: #a83b3b;
  --good: #24734f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  background: #181a1f;
  color: #fff;
  padding: 18px 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 6px 8px 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #e8b24b);
}

.brand small {
  display: block;
  color: #aeb4c0;
  margin-top: 2px;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 18px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-label {
  padding: 0 10px 2px;
  color: #858d9b;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
}

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

button.is-loading::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: button-spin 0.7s linear infinite;
}

button.is-success {
  border-color: #87c69a;
  color: #24743b;
  background: #f2fbf5;
}

button.is-error {
  border-color: #e6a2a2;
  color: #9f1d1d;
  background: #fff7f7;
}

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

button.danger {
  border-color: #f3b8b8;
  color: #9f1d1d;
  background: #fff7f7;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border-color: transparent;
  background: transparent;
  color: #c8ced8;
  text-align: left;
  padding: 10px 10px 10px 12px;
}

.nav.active, .nav:hover {
  background: #282b33;
  color: #fff;
}

.nav b {
  min-width: 28px;
  min-height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #242730;
  color: #aeb5c2;
  font-size: 12px;
  font-weight: 800;
}

.nav.active b {
  background: #fff;
  color: #1d2027;
}

.sidebar-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid #2b2f38;
}

.side-action {
  grid-column: 1 / -1;
  min-height: 38px;
  border-color: #353a45;
  background: #242832;
  color: #f5f7fa;
}

.side-action:hover {
  background: #303542;
}

.sidebar-foot div {
  min-height: 58px;
  border: 1px solid #2b2f38;
  border-radius: 8px;
  padding: 10px;
  background: #20232a;
}

.sidebar-foot span {
  display: block;
  color: #9ca4b2;
  font-size: 12px;
}

.sidebar-foot strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
}

main {
  margin-left: 244px;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

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

.account-filter {
  min-width: 220px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
p, small { color: var(--muted); }

.view { display: none; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric { padding: 16px; }
.metric strong { display: block; font-size: 26px; margin-top: 8px; }

.panel { padding: 18px; }
.space-top { margin-top: 16px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 12px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two { grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); }

.form {
  display: grid;
  gap: 12px;
  align-content: start;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { grid-template-columns: 18px 1fr; align-items: center; color: var(--ink); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }

.list { display: grid; gap: 10px; }
.account-group-section {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}
.account-group-section + .account-group-section {
  margin-top: 8px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.account-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.account-group-head h3 {
  margin: 0;
  font-size: 15px;
}
.account-group-head small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}
.account-group-list {
  display: grid;
  gap: 10px;
}
.account-group-row td {
  padding-top: 16px;
  padding-bottom: 8px;
  background: #f8fafb;
}
.account-group-row strong {
  margin-right: 8px;
}
.account-group-row span {
  color: var(--muted);
  font-size: 12px;
}
.new-group-field[hidden] {
  display: none;
}
.item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.item.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(37, 111, 107, 0.12);
}
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.account-profile-link {
  color: var(--ink);
  font-weight: 750;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}
.account-profile-link:hover,
.account-profile-link:focus-visible {
  color: var(--accent-2);
  text-decoration-color: currentColor;
}
.account-card-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.account-toggle {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
}
.account-toggle span {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 160ms ease;
}
.account-toggle.expanded span {
  transform: rotate(225deg) translate(-1px, -1px);
}
.account-details {
  display: grid;
  gap: 8px;
}
.account-details.collapsed {
  display: none;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button { min-height: 32px; padding: 0 10px; }

.account-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.account-settings label.full {
  grid-column: 1 / -1;
}

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

.progress-block strong {
  font-size: 14px;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ecf1;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-2);
}

.workflow-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(76px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.topic-bank-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.topic-bank-row button {
  min-height: 40px;
  padding: 0 12px;
}

.workflow-grid label {
  font-size: 12px;
}

.workflow-grid input[type="number"] {
  min-height: 34px;
  padding: 7px 8px;
}

.check.compact {
  align-self: end;
  min-height: 34px;
  grid-template-columns: 18px 1fr;
  gap: 7px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 750;
  background: #eef1f5;
}
.badge.active, .badge.sent, .badge.done { color: var(--good); background: #e8f4ee; }
.badge.paused, .badge.queued { color: var(--warn); background: #fbf0df; }
.badge.failed, .badge.rejected { color: var(--bad); background: #f8e7e7; }
.badge.running, .badge.generated { color: var(--accent-2); background: #e5f4f3; }

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

.gallery-tools {
  display: grid;
  grid-template-columns: minmax(130px, 170px) minmax(160px, 220px) minmax(90px, 120px) repeat(3, auto);
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.gallery-tools button {
  min-height: 40px;
  padding: 0 12px;
}

.gallery-tools label {
  min-width: 0;
}

.gallery-tools input,
.gallery-tools select {
  min-height: 40px;
}
.image-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.image-preview,
.image-placeholder {
  aspect-ratio: 2 / 3;
}

.image-preview {
  display: block;
  overflow: hidden;
  background: #eef1f5;
}

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

.image-placeholder {
  display: grid;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  background: linear-gradient(135deg, #f4eee7, #d9e9e7);
  text-align: center;
}
.image-body { padding: 12px; display: grid; gap: 8px; }
.image-url {
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.test-result {
  display: grid;
  gap: 12px;
}

.test-card {
  box-shadow: none;
}

.prompt-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fafafa;
}

.prompt-preview p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.error-text {
  color: #9f1d1d;
  margin: 0;
}

.logs {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}
.log {
  border-left: 3px solid var(--accent-2);
  padding: 8px 10px;
  background: #f8fafb;
}

@media (max-width: 720px) {
  .sidebar {
    position: static;
    width: auto;
    max-height: none;
  }
  .side-nav { grid-template-columns: 1fr; }
  main { margin-left: 0; padding: 18px; }
  .metrics, .grid.two { grid-template-columns: 1fr; }
  .gallery-tools { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; align-items: stretch; flex-direction: column; }
  .account-filter { min-width: 0; }
}
