:root {
  --bg: #f4f1eb;
  --panel: #fffdf9;
  --ink: #181512;
  --muted: #6f675f;
  --line: #e6ddd3;
  --accent: #dc5f2f;
  --accent-2: #1f7a8c;
  --ok: #2f855a;
  --warn: #b7791f;
  --bad: #c53030;
  --shadow: 0 18px 50px rgba(40, 24, 12, 0.09);
  font-family: "SF Pro Text", "PingFang SC", "Hiragino Sans GB", sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(220,95,47,.08), transparent 28%),
    radial-gradient(circle at top right, rgba(31,122,140,.08), transparent 24%),
    var(--bg);
  color: var(--ink);
}
a { color: inherit; }
.wrap { max-width: 1480px; margin: 0 auto; padding: 28px 18px 80px; }
.panel {
  background: rgba(255,253,249,.92);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(10px);
}
.panel h2 { margin: 0 0 8px; font-size: 22px; }
.panel p.title-note { margin: 0 0 18px; color: var(--muted); }
.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}
h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: .95;
  letter-spacing: -.04em;
}
.sub { color: var(--muted); margin-top: 10px; font-size: 16px; }
.pill {
  display:inline-flex;
  align-items:center;
  gap:8px;
  border:1px solid var(--line);
  background:#fff;
  border-radius:999px;
  padding:10px 14px;
  color:var(--muted);
}
.dashboard-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 18px;
  padding: 18px;
}
.sidebar h2 {
  margin: 0;
  font-size: 20px;
}
.sidebar p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}
.side-nav {
  display: grid;
  gap: 10px;
}
.side-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.side-link:hover {
  transform: translateY(-1px);
  border-color: rgba(220,95,47,.4);
  box-shadow: 0 12px 26px rgba(40, 24, 12, 0.08);
}
.side-link small {
  color: var(--muted);
  font-weight: 500;
}
.side-link.active {
  background: linear-gradient(135deg, rgba(220,95,47,.14), rgba(31,122,140,.10));
  border-color: rgba(220,95,47,.34);
}
.side-actions {
  display: grid;
  gap: 10px;
}
.sidebar-meta {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(220,95,47,.12), rgba(31,122,140,.10));
}
.sidebar-meta strong { font-size: 15px; }
.main-stack { min-width: 0; }
.grid { display:grid; grid-template-columns: 1.05fr .95fr; gap: 18px; }
.metrics { display:grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { background:#fff; border:1px solid var(--line); border-radius: 22px; padding: 16px; }
.metric strong { display:block; font-size: 28px; margin-top: 6px; }
.field { display:grid; gap: 8px; margin-bottom: 14px; }
.field label { font-size: 14px; color: var(--muted); }
input, textarea, button { font: inherit; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 14px 16px;
  color: var(--ink);
}
textarea { min-height: 108px; resize: vertical; }
button {
  border: none;
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
button:hover { transform: translateY(-1px); }
.primary { background: var(--accent); color: #fff; }
.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.ghost { background: #f7f1ea; color: var(--ink); }
.danger { background: #fff1f0; color: var(--bad); border: 1px solid #f7c7c2; }
.row { display:flex; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.status { display:inline-flex; align-items:center; gap:8px; padding:6px 10px; border-radius:999px; font-size:13px; }
.status.pending, .status.openai_processing, .status.cancel_requested { background:#fff5e8; color: var(--warn); }
.status.completed { background:#ecfdf3; color: var(--ok); }
.status.failed, .status.timeout_unknown, .status.cancelled { background:#fff1f0; color: var(--bad); }
table { width:100%; border-collapse: collapse; }
th, td { text-align:left; padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 13px; font-weight: 600; }
td { font-size: 14px; }
.table-wrap { width: 100%; max-height: 680px; overflow: auto; }
.tasks-table { width: 100%; min-width: 980px; table-layout: fixed; }
.tasks-table th:nth-child(1), .tasks-table td:nth-child(1) { width: 18%; }
.tasks-table th:nth-child(2), .tasks-table td:nth-child(2) { width: 14%; }
.tasks-table th:nth-child(3), .tasks-table td:nth-child(3) { width: 26%; }
.tasks-table th:nth-child(4), .tasks-table td:nth-child(4) { width: 16%; }
.tasks-table th:nth-child(5), .tasks-table td:nth-child(5) { width: 26%; }
.task-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.45; word-break: break-all; }
.task-prompt, .task-error { white-space: normal; word-break: break-word; overflow-wrap: anywhere; line-height: 1.55; }
.task-prompt { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.task-time { line-height: 1.55; }
.gallery { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.gallery-footer {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.gallery-footer-top {
  margin-top: 0;
  margin-bottom: 18px;
}
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.pagination button {
  min-width: 46px;
  padding: 10px 14px;
}
.page-gap {
  color: var(--muted);
  padding: 0 4px;
}
.is-disabled {
  opacity: .45;
  cursor: not-allowed;
}
.card { border:1px solid var(--line); border-radius: 20px; overflow:hidden; background:#fff; }
.card img { display:block; width:100%; aspect-ratio: 3/4; object-fit: cover; background:#efe7de; }
.card .meta { padding: 12px; display:grid; gap:4px; }
.banner {
  display:none;
  margin-bottom:18px;
  padding:14px 16px;
  border-radius:16px;
  font-size:14px;
}
.banner.show { display:block; }
.banner.info { background:#eaf5f9; color:#15516a; }
.banner.error { background:#fff1f0; color:var(--bad); }
#app { display:none; }
#loginView { max-width: 460px; margin: 12vh auto 0; }
.login-art {
  margin-top: 14px;
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(220,95,47,.14), rgba(31,122,140,.12));
  color: var(--muted);
  line-height: 1.7;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.library-grid { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.library-cards { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.library-box {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  gap: 10px;
}
.library-box h3 { margin: 0; font-size: 20px; }
.library-note {
  padding: 16px;
  border-radius: 18px;
  background: #f8f3ec;
  color: var(--muted);
  line-height: 1.7;
}
.chips { display:flex; gap:8px; flex-wrap:wrap; }
.chip {
  display:inline-flex;
  padding:8px 12px;
  border-radius:999px;
  background:#fff;
  border:1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.library-character-card {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #fff;
}
.library-character-card img {
  width: 88px;
  height: 116px;
  object-fit: cover;
  border-radius: 14px;
  background: #efe7de;
}
.library-character-meta {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.library-character-meta strong {
  font-size: 18px;
}
.library-character-meta .muted {
  line-height: 1.55;
}
@media (max-width: 1180px) {
  .dashboard-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; order: -1; }
  .side-nav { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
@media (max-width: 980px) {
  .grid, .library-grid, .library-cards, .library-character-card { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .wrap { padding: 18px 12px 48px; }
  .metrics, .gallery { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; }
  .gallery-footer { align-items: flex-start; }
}
