/* === Creative Studio · base styles === */
:root {
  --bg: #f7f7f9;
  --bg-card: #ffffff;
  --bg-muted: #f1f2f5;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #d8412c;       /* JD red */
  --primary-hover: #b8311f;
  --accent-gold: #c8a85a;
  --success: #16a34a;
  --warn: #f59e0b;
  --error: #dc2626;
  --strong-bg: #fef2e9;
  --strong-border: #f59e0b;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }

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

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  gap: 16px;
  flex-wrap: nowrap;
}
.brand { flex-shrink: 0; }
.brand a {
  color: var(--text); text-decoration: none;
  display: flex; align-items: baseline; gap: 8px;
  white-space: nowrap;
}
.brand .logo { color: var(--primary); font-size: 16px; }
.brand-text { font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand-sub { color: var(--text-muted); font-size: 11px; white-space: nowrap; }

.topnav {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: flex-end;
}
.topnav a {
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  white-space: nowrap;
  line-height: 1.4;
  flex-shrink: 0;
}
.topnav a:hover { background: var(--bg-muted); text-decoration: none; }
.topnav a.primary {
  background: var(--primary); color: #fff;
}
.topnav a.primary:hover { background: var(--primary-hover); }
.topnav a.locked-link { color: var(--text-muted); }
.topnav a.locked-link .lock {
  font-size: 10px; padding: 1px 5px; margin-left: 3px;
  background: var(--bg-muted); border-radius: 8px;
  white-space: nowrap;
}
.topnav a.logout-link {
  margin-left: 6px;
  color: var(--text-muted);
  font-size: 12px;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

/* narrow viewports: hide brand subline so nav has more room */
@media (max-width: 1280px) {
  .brand-sub { display: none; }
}
@media (max-width: 1080px) {
  .topnav a { font-size: 12px; padding: 5px 7px; }
  .topnav a.locked-link .lock { display: none; }
}

/* layout */
.container { max-width: 1280px; margin: 24px auto; padding: 0 24px; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; }
.page-actions { display: flex; gap: 8px; }

.section { margin-top: 28px; }
.section-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  margin-bottom: 18px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; font-size: 13px; font-weight: 500;
  font-family: inherit;
}
.btn:hover { background: var(--bg-muted); }
.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: #fff; border-color: var(--border);
}
.btn-link {
  background: transparent; border-color: transparent; color: var(--primary);
  padding: 4px 8px;
}
.btn-link:hover { background: var(--bg-muted); text-decoration: none; }
.btn-disabled {
  background: var(--bg-muted); color: var(--text-muted);
  border-color: var(--border); cursor: not-allowed;
}

/* forms */
input[type=text], input[type=date], input[type=number], textarea, select {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 5px; font-size: 13px; font-family: inherit;
  background: #fff;
}
textarea { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(216,65,44,0.1);
}
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
label > input, label > select, label > textarea { margin-top: 4px; }
.form-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px;
}
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr 1fr; } }

.actions { margin-top: 12px; display: flex; gap: 8px; align-items: center; }

/* === workflow banner === */
.workflow-banner {
  background: linear-gradient(135deg, #fff 0%, #faf5ed 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 24px; margin-bottom: 22px;
}
.workflow-banner h2 { margin-bottom: 14px; }
.workflow-steps {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
}
@media (max-width: 900px) { .workflow-steps { grid-template-columns: 1fr 1fr; } }
.workflow-steps li {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; background: #fff; border-radius: 6px;
  border: 1px solid var(--border);
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 12px;
}
.workflow-steps small { color: var(--text-muted); font-size: 12px; }

/* === dashboard cards === */
.cards-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px;
  margin-bottom: 22px;
}
@media (max-width: 900px) { .cards-row { grid-template-columns: 1fr; } }
.cards-row .card { margin: 0; }
.card-cta { border-left: 3px solid var(--primary); }
.card-cta h3 { color: var(--primary); }
.card-locked {
  position: relative; opacity: 0.7;
  background: repeating-linear-gradient(45deg, #fff, #fff 12px, #fafafa 12px, #fafafa 24px);
}
.lock-badge {
  position: absolute; top: 12px; right: 12px;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg-muted); color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* === tables === */
.data-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.data-table th, .data-table td {
  padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.data-table th { background: var(--bg-muted); font-weight: 600; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; }

/* === badges & tags === */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
  background: var(--bg-muted); color: var(--text-muted);
}
.badge-parsed     { background: #e0f2fe; color: #0369a1; }
.badge-queued     { background: #f3f4f6; color: #6b7280; }
.badge-running    { background: #fef3c7; color: #92400e; }
.badge-done       { background: #dcfce7; color: #166534; }
.badge-partial    { background: #fff7ed; color: #c2410c; }
.badge-errored    { background: #fee2e2; color: #991b1b; }
.badge-pass       { background: #dcfce7; color: #166534; }
.badge-to_polish  { background: #fef3c7; color: #92400e; }
.badge-mini       { font-size: 10px; padding: 1px 6px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; background: var(--bg-muted); color: var(--text);
  margin: 2px 3px 2px 0; cursor: help;
}
.tag-strong {
  background: var(--strong-bg); color: #92400e;
  border: 1px solid var(--strong-border);
}
.tag-mini { font-size: 10px; padding: 1px 5px; }

/* === stat grid === */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 14px; margin: 10px 0;
}
.stat-grid > div {
  text-align: center; padding: 10px;
  background: var(--bg-muted); border-radius: 6px;
}
.stat-num { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-pass { color: var(--success); }
.stat-fail { color: var(--warn); }
.stat-err  { color: var(--error); }

/* === brief form === */
.tpl-row {
  border: 1px solid var(--border); border-radius: 6px;
  margin: 8px 0; padding: 10px 12px; background: #fff;
}
.tpl-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.tpl-check input { width: auto; margin: 0; }
.tpl-id {
  display: inline-block; padding: 2px 8px; background: var(--primary); color: #fff;
  border-radius: 4px; font-weight: 600; font-size: 12px;
}
.tpl-desc { color: var(--text); }
.tpl-tags { margin-top: 6px; margin-left: 28px; }
.tpl-matrix {
  margin-top: 10px; margin-left: 28px; padding: 10px;
  background: var(--bg-muted); border-radius: 5px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.tpl-matrix label { font-size: 12px; }

/* === run card on brief detail === */
.run-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 12px;
}
.run-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.run-actions { display: flex; gap: 8px; align-items: center; }
.rank {
  display: inline-block; padding: 1px 8px; background: var(--bg-muted);
  border-radius: 10px; font-size: 11px; color: var(--text-muted); margin-right: 6px;
}
.run-body { margin-top: 10px; }
.thinking { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.thinking-label { font-size: 12px; color: var(--text-muted); width: 70px; }
.score-bar {
  flex: 1; height: 18px; background: var(--bg-muted); border-radius: 9px;
  position: relative; overflow: hidden;
}
.score-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent-gold), var(--primary));
  border-radius: 9px; transition: width 0.4s;
}
.score-num {
  position: absolute; right: 8px; top: 0;
  line-height: 18px; font-size: 11px; font-weight: 600; color: var(--text);
}
.mech-tags { margin: 6px 0; }
.plan-detail { margin-top: 8px; }
.plan-detail summary { cursor: pointer; font-size: 12px; color: var(--text-muted); }
.plan-detail pre {
  background: var(--bg-muted); padding: 10px; border-radius: 5px;
  font-size: 11px; overflow: auto; max-height: 240px;
}
.run-status { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.error-box {
  background: #fee2e2; color: #991b1b; padding: 8px 10px; border-radius: 5px;
  margin-top: 8px; font-size: 12px;
}

/* === gallery === */
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.img-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.img-thumb {
  position: relative; aspect-ratio: 16/9; background: var(--bg-muted);
}
.img-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.img-verdict {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,0.6); color: #fff;
}
.v-pass     { background: var(--success); }
.v-to_polish{ background: var(--warn); }
.v-errored  { background: var(--error); }
.img-meta { padding: 10px 12px; }
.img-name {
  font-size: 12px; font-family: ui-monospace, monospace;
  margin-bottom: 4px; word-break: break-all;
}
.img-score { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.img-fails { margin-top: 4px; }
.img-actions {
  display: flex; justify-content: space-between; padding: 6px 8px;
  border-top: 1px solid var(--border); background: #fafbfc;
}

/* === run detail extras === */
.strong-union, .fail-groups {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}

/* === modal === */
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-panel {
  position: relative; max-width: 1100px; width: 90%; max-height: 90vh;
  margin: 5vh auto; background: #fff; border-radius: var(--radius);
  overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-close {
  position: absolute; top: 8px; right: 14px; font-size: 28px; cursor: pointer;
  background: none; border: none; line-height: 1; color: var(--text-muted);
}
.modal-body { padding: 24px; }

.modal-img { width: 100%; max-height: 420px; object-fit: contain;
  background: var(--bg-muted); border-radius: 5px; }
.modal-meta { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-top: 16px; }
.checks-list { font-size: 12px; }
.check-row {
  display: flex; justify-content: space-between; padding: 5px 8px;
  border-bottom: 1px solid var(--border);
}
.check-ok   { color: var(--success); }
.check-fail { color: var(--warn); }
.check-skip { color: var(--text-muted); font-style: italic; }

.comments { margin-top: 14px; }
.comment {
  background: var(--bg-muted); padding: 8px 12px; border-radius: 5px;
  margin-bottom: 6px; font-size: 13px;
}
.comment-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* === locked page === */
.locked-page {
  text-align: center; padding: 60px 24px;
  background: #fff; border-radius: var(--radius); border: 1px solid var(--border);
}
.lock-icon { font-size: 48px; margin-bottom: 14px; opacity: 0.5; }
.locked-page h1 { font-size: 28px; margin-bottom: 8px; }
.subtitle { color: var(--text-muted); margin-bottom: 24px; }
.reason {
  display: inline-block; padding: 10px 18px; background: var(--bg-muted);
  border-radius: 6px; font-size: 13px; margin-bottom: 24px;
}

/* === misc === */
.empty-state {
  background: #fff; border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 36px; text-align: center; color: var(--text-muted);
}
pre {
  background: var(--bg-muted); padding: 12px; border-radius: 5px;
  font-size: 12px; overflow: auto;
}
.footer {
  margin-top: 48px; padding: 16px 24px;
  border-top: 1px solid var(--border); background: #fff;
  display: flex; justify-content: space-between; font-size: 12px;
  color: var(--text-muted);
}

/* === imported + rerender flag === */
.badge-imported, .v-imported, .badge-imported {
  background: #e0e7ff; color: #3730a3; border: 1px solid #c7d2fe;
}
.img-flagged {
  outline: 2px solid #f59e0b; outline-offset: -2px;
  background: linear-gradient(135deg, #fff 0%, #fffbeb 100%);
}
.flag-badge {
  position: absolute; top: 6px; left: 6px;
  background: #f59e0b; color: #fff; font-size: 14px;
  border-radius: 50%; width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25); z-index: 2;
}
.btn-flag { color: #b45309; }
.btn-flag[data-on="1"] { color: #d97706; font-weight: 600; }

/* === rerender queue page === */
.queue-table { width: 100%; border-collapse: collapse; background: #fff; }
.queue-table th, .queue-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
.queue-table th { background: var(--bg-muted); }
.queue-table .thumb { width: 80px; height: 45px; object-fit: cover; border-radius: 4px; }

.run-status-imported, .badge-imported { background: #e0e7ff; color: #3730a3; border: 1px solid #c7d2fe; }


/* P2-FEEDBACK-CSS-v1 */
.img-feedback { padding: 6px 10px; border-top: 1px solid #eee; font-size: 12px; }
.fb-rating { display: flex; gap: 4px; align-items: center; }
.fb-btn {
  background: #f6f7f9; border: 1px solid #d8dbe0; border-radius: 4px;
  padding: 2px 8px; cursor: pointer; font-size: 14px; line-height: 1.2;
}
.fb-btn:hover { background: #e9ebee; }
.fb-btn.fb-on { background: #2563eb; color: #fff; border-color: #2563eb; }
.fb-regen-btn { margin-left: auto; font-size: 12px; }
.fb-regen { margin-top: 6px; }
.fb-note {
  width: 100%; font-size: 12px; padding: 4px 6px;
  border: 1px solid #d8dbe0; border-radius: 4px; resize: vertical;
}
.btn-mini { padding: 2px 8px; font-size: 12px; }
.fb-regen-status { display: inline-block; margin-left: 8px; font-size: 11px; }

/* --- P4-BATCH-RERENDER-v1 ------------------------------------------------ */
.page-head-actions { display: flex; gap: 8px; align-items: center; }
.btn.btn-primary {
  background: #2563eb; color: #fff; border: 1px solid #2563eb;
  font-weight: 600; padding: 6px 14px; border-radius: 6px; cursor: pointer;
}
.btn.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.rq-budget-line { display: flex; justify-content: space-between;
  align-items: center; font-size: 14px; }
.rq-budget-line strong { color: #0f172a; }
.hidden { display: none !important; }
.rq-progress-wrap { margin: 8px 0 12px 0; }
.rq-progress-bar {
  width: 100%; height: 14px; background: #e5e7eb;
  border-radius: 7px; overflow: hidden; margin-bottom: 6px;
}
#rq-progress-fill {
  height: 100%; width: 0; background: linear-gradient(90deg, #2563eb, #60a5fa);
  transition: width 0.3s ease;
}
.rq-progress-meta { display: flex; justify-content: space-between;
  font-size: 13px; }
.rq-state-running { color: #2563eb; font-weight: 600; }
.rq-state-done { color: #16a34a; font-weight: 600; }
.rq-state-cancelled { color: #d97706; font-weight: 600; }
.rq-state-errored { color: #dc2626; font-weight: 600; }
.rq-event-log {
  margin: 8px 0 0 0; padding-left: 0; list-style: none;
  max-height: 260px; overflow-y: auto;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px;
  padding: 8px 12px; font-size: 13px; font-family: ui-monospace, monospace;
}
.rq-event-log li { padding: 2px 0; }
.rq-event-log .rq-err { color: #dc2626; }
.rq-row-done { background: #f0fdf4; }
.rq-row-err { background: #fef2f2; }
.rq-single-status { display: inline-block; margin-left: 6px;
  font-size: 12px; }
/* --- end P4-BATCH-RERENDER-v1 ------------------------------------------- */

/* RUN-IMG-ERR-PLACEHOLDER */
.img-err-placeholder {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 100%; height: 100%;
  min-height: 160px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 24px;
  border: 1px dashed #fecaca;
  border-radius: 6px;
  gap: 6px;
}
.img-err-placeholder div { font-size: 12px; font-weight: 600; }

/* P10-IA-NAV */
.topnav { width: 100%; display: flex; align-items: center; gap: 24px; justify-content: space-between; }
.nav-primary   { display: flex; gap: 6px; align-items: center; }
.nav-secondary { display: flex; gap: 4px; align-items: center; }
.topnav .nav-pri {
  font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-radius: 8px;
  background: #f1f5f9; color: #0f172a;
  border: 1px solid transparent;
  white-space: nowrap;
}
.topnav .nav-pri:hover { background: #e2e8f0; }
.topnav .nav-pri.active, .topnav .nav-pri[aria-current="page"] {
  background: #2563eb; color: #fff;
}
.nav-secondary a {
  font-size: 12px; color: #64748b;
  padding: 5px 9px; border-radius: 5px; white-space: nowrap;
}
.nav-secondary a:hover { background: #f1f5f9; color: #0f172a; }
.nav-secondary .logout-link {
  border-left: 1px solid #e2e8f0; margin-left: 4px; padding-left: 12px;
}
@media (max-width: 1100px) {
  .topnav { gap: 12px; }
  .topnav .nav-pri { font-size: 13px; padding: 6px 10px; }
  .nav-secondary a { font-size: 11px; }
}

/* P11-NAV-RUN-BADGE */
.nav-run-badge {
  display: inline-block;
  margin-left: 4px;
  min-width: 18px; padding: 0 6px;
  border-radius: 10px;
  background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
  text-align: center;
  animation: navpulse 1.6s ease-in-out infinite;
}
@keyframes navpulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.nav-pri-jump {
  background: #fef3c7 !important; color: #92400e !important;
  font-size: 12.5px !important;
}
.nav-pri-jump:hover { background: #fde68a !important; }
