/* Neutral greys throughout so plant colours are judged without a tint. */
:root {
  --bg: #1b1b1c;
  --panel: #242426;
  --panel-2: #2d2d30;
  --line: #3a3a3e;
  --text: #ececec;
  --muted: #9a9a9f;
  --accent: #7fbf6a;       /* approve / primary */
  --accent-ink: #10200b;
  --danger: #e0685d;
  --warn: #e3b345;
  --focus: #6aa8ff;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
kbd {
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; margin: 0 2px;
}
code { font: 12px ui-monospace, Menlo, monospace; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand span { color: var(--accent); font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: none; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--panel-2); color: var(--text); }
.stats { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.stat {
  display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 9px; border-radius: 999px;
  background: var(--panel-2); font-size: 12px; cursor: pointer; border: 1px solid transparent;
}
.stat b { font-variant-numeric: tabular-nums; }
.stat:hover { border-color: var(--line); }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 4px; text-transform: uppercase; letter-spacing: .5px; }
.badge.mock { background: var(--warn); color: #231a00; }
.badge.live { background: var(--accent); color: var(--accent-ink); }
.banner { background: #4a3a12; color: #ffe6a6; padding: 8px 16px; font-size: 13px; }

/* buttons */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #55555b; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .4; cursor: default; }
.btn kbd { background: rgba(0,0,0,.15); border-color: rgba(0,0,0,.2); color: inherit; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 5px 10px; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button.active { background: var(--panel-2); color: var(--text); }

/* toolbar */
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 53px; z-index: 10;
}
.toolbar select, .toolbar input, .drawer input, .drawer select, .drawer textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
}
.toolbar input[type=search] { width: 200px; }
.keys { color: var(--muted); font-size: 12px; }

/* grids */
.grid { display: grid; gap: 12px; padding: 16px; }
.grid.lib { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.rev { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.card {
  position: relative; background: var(--panel); border: 2px solid transparent; border-radius: var(--radius);
  overflow: hidden; cursor: pointer; user-select: none;
}
.card:hover { border-color: var(--line); }
.card.selected { border-color: var(--accent); }
.card.focused { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(106,168,255,.25); }
.card.done { opacity: .45; }
.card .thumb { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #111; }
.card .meta { padding: 6px 8px; display: flex; gap: 6px; align-items: center; font-size: 12px; }
.card .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .check {
  position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.7); background: rgba(0,0,0,.35);
}
.card.selected .check { background: var(--accent); border-color: var(--accent); }
.card.selected .check::after { content: "✓"; color: var(--accent-ink); font-size: 12px; font-weight: 700; display: block; text-align: center; line-height: 16px; }
.card .crop-flag {
  position: absolute; top: 6px; right: 6px; font-size: 11px; background: rgba(0,0,0,.6);
  padding: 1px 6px; border-radius: 4px;
}
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: #111; }
.pair .thumb { aspect-ratio: 2/3; }
.pair .thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 12px; padding: 12px; text-align: center; }
.card .err { color: var(--danger); font-size: 11px; padding: 0 8px 8px; }

.pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); white-space: nowrap; }
.pill.new { color: var(--muted); }
.pill.queued { background: #2f3a4d; color: #b9d0ff; }
.pill.generating { background: #2f3a4d; color: #b9d0ff; animation: pulse 1.2s infinite; }
.pill.review { background: #4a3f1c; color: #ffdf8a; }
.pill.approved { background: #28401f; color: #b6e3a3; }
.pill.rejected, .pill.failed { background: #4a2522; color: #ffb3ab; }
.pill.accent { background: var(--focus); color: #0b1a33; cursor: pointer; }
@keyframes pulse { 50% { opacity: .5; } }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; padding: 8px 16px 32px; color: var(--muted); }
.empty-state { grid-column: 1/-1; text-align: center; color: var(--muted); padding: 60px 0; }

/* modals */
.modal { position: fixed; inset: 0; z-index: 50; background: #111; display: flex; flex-direction: column; }
.modal-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.cmp-stage { flex: 1; min-height: 0; position: relative; }
.cmp-side { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; height: 100%; padding: 8px; }
.cmp-side figure { margin: 0; display: flex; flex-direction: column; min-height: 0; }
.cmp-side figcaption { font-size: 12px; color: var(--muted); padding: 0 0 6px; }
.cmp-side img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
/* frame takes the result's aspect ratio; the reference is cover-filled into the same frame */
.cmp-slider {
  position: absolute; top: 8px; bottom: 8px; left: 50%; transform: translateX(-50%);
  aspect-ratio: var(--ar, 0.6667); max-width: calc(100% - 16px); cursor: ew-resize; overflow: hidden;
}
.cmp-slider img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cmp-s-top { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
.cmp-s-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: #fff; box-shadow: 0 0 6px rgba(0,0,0,.6); pointer-events: none; }
.cmp-attempts { display: flex; gap: 8px; padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line); overflow-x: auto; }
.cmp-attempts .att {
  flex: none; width: 64px; height: 96px; border-radius: 6px; border: 2px solid transparent;
  background: #111 center/cover no-repeat; cursor: pointer; position: relative;
}
.cmp-attempts .att.active { border-color: var(--focus); }
.cmp-attempts .att.approved::after { content: "✓"; position: absolute; right: 3px; bottom: 1px; color: var(--accent); font-weight: 700; }
.cmp-attempts .att.failed { background: var(--panel-2); display: grid; place-items: center; font-size: 10px; color: var(--danger); cursor: default; }

.crop-stage { flex: 1; min-height: 0; overflow: hidden; }
.crop-stage img { display: block; max-width: 100%; max-height: 100%; }

/* settings drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 40;
  background: var(--panel); border-left: 1px solid var(--line); padding: 16px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: -10px 0 30px rgba(0,0,0,.4);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.drawer .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.drawer .grow { flex: 1; min-height: 0; }
.drawer textarea { flex: 1; resize: none; color: var(--text); font-size: 13px; line-height: 1.5; }
.drawer input, .drawer select { color: var(--text); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--panel-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 6px;
}
.toast.error { border-color: var(--danger); color: #ffb3ab; }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; }
  .toolbar { top: 0; position: static; }
  .grid.rev { grid-template-columns: 1fr; }
}

/* tweak dialog */
.dialog-wrap { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.dialog {
  width: min(620px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.dialog p { margin: 0; }
.dialog-head, .dialog-foot { display: flex; align-items: center; gap: 8px; }
.dialog-head { justify-content: space-between; }
.dialog textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; resize: vertical; color: var(--text);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 5px 11px;
  cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: baseline;
}
.chip small { color: var(--muted); font-size: 11px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on small { color: var(--accent-ink); opacity: .7; }
.chip kbd { margin: 0; }
.cmp-extra { padding: 6px 16px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.cmp-extra b { color: var(--text); font-weight: 600; }
.cmp-attempts .att .tag {
  position: absolute; left: 2px; right: 2px; bottom: 2px; font-size: 9px; line-height: 1.2; padding: 1px 3px;
  background: rgba(0,0,0,.7); color: #fff; border-radius: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.card .tweak-flag { font-size: 11px; color: var(--focus); }
.dialog:focus { outline: none; }
.chip.on kbd { background: rgba(0,0,0,.18); border-color: rgba(0,0,0,.25); color: var(--accent-ink); }

a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
.banner.info { background: #1f2f45; color: #cfe0ff; display: flex; gap: 12px; align-items: flex-start; }
.banner.info .close { margin-left: auto; cursor: pointer; opacity: .7; }
.banner.info details { font-size: 12px; }
.pill.push-done { background: #1f3a4d; color: #a8d8ff; }
.pill.push-pending { background: #1f3a4d; color: #a8d8ff; animation: pulse 1.2s infinite; }
.pill.push-failed { background: #4a2522; color: #ffb3ab; cursor: pointer; }
.pill.no-row { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.stat.push-failed { border-color: var(--danger); color: #ffb3ab; }

.credit-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.credit-table td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.credit-table td:last-child { text-align: right; }
.credit-table tr.total td { font-weight: 700; border-bottom: 0; }
.credit-warn { background: #4a2522; color: #ffd0ca; border: 1px solid var(--danger); border-radius: 6px; padding: 10px 12px; margin-top: 10px; }
.credit-ok { color: var(--muted); font-size: 12px; margin-top: 8px; }
.stat.credits.low { border-color: var(--danger); color: #ffb3ab; }

/* custom-column filters (shared by Input and Review) */
.filterbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px;
}
.filterbar .ftitle { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.filterbar label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.filterbar select, .filterbar input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; color: var(--text); max-width: 220px;
}
.filterbar .active select, .filterbar .active input { border-color: var(--focus); }
.import-report { margin: 0; padding-left: 18px; line-height: 1.6; }
.import-report details { display: inline; }
.import-report details summary { display: inline; cursor: pointer; color: #9cc3ff; text-decoration: underline; }
.import-report details[open] { display: block; margin: 2px 0 4px 8px; font-size: 12px; }
