:root {
  --bg: #f6f8fc;
  --panel: rgba(255, 255, 255, .88);
  --panel-solid: #ffffff;
  --line: #e4e9f2;
  --line-strong: #d5deeb;
  --text: #102033;
  --muted: #66758a;
  --primary: #3578f6;
  --primary-dark: #1f5ed8;
  --green: #16a673;
  --green-soft: #e9fbf3;
  --blue-soft: #eef5ff;
  --amber: #a96c14;
  --amber-soft: #fff6e7;
  --red: #d94a3a;
  --red-soft: #fff0ee;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 22px rgba(28, 47, 84, .05);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(72, 128, 255, .08), transparent 36%),
    linear-gradient(215deg, rgba(130, 88, 255, .08), transparent 32%),
    var(--bg);
  min-height: 100vh;
  font-size: 14px;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(50, 75, 120, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(50, 75, 120, .045) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  opacity: .42;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.5), transparent 70%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(1280px, calc(100vw - 40px));
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 14px 0 12px;
  background: rgba(246, 248, 252, .96);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #2d78ff, #6d7cff);
  box-shadow: none;
}

.top-nav nav {
  display: inline-flex;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .88);
  box-shadow: none;
}

.nav-link {
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  background: transparent;
  color: #526176;
  font-weight: 700;
  white-space: nowrap;
}

.nav-link:hover,
.nav-link.active {
  color: var(--primary);
  background: var(--blue-soft);
}

.nav-actions,
.title-actions,
.panel-head,
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-actions,
.title-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

main {
  padding: 16px 0 32px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 14px 0 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
}

.section-title p,
.panel-head p,
.muted,
.soft-box,
.meta-line {
  color: var(--muted);
  line-height: 1.6;
}

.section-title p {
  margin-top: 6px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metric-card,
.panel {
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 20px;
  min-height: 112px;
}

.metric-card strong {
  display: block;
  font-size: 30px;
  line-height: 1;
  margin-bottom: 12px;
}

.metric-card span {
  color: var(--muted);
  font-weight: 650;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.panel.large {
  min-height: 320px;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 16px;
  min-width: 0;
}

.primary-btn,
.ghost-btn,
.danger-btn {
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  height: 38px;
  padding: 0 16px;
  font-weight: 800;
  background: #fff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--primary);
}

.primary-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.danger-btn {
  color: var(--red);
  border-color: #f1c1bb;
  background: #fff;
}

.wide {
  width: 100%;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  min-height: 28px;
  padding: 5px 10px;
  background: var(--blue-soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}

.badge.pending { background: var(--amber-soft); color: var(--amber); }
.badge.running { background: var(--blue-soft); color: var(--primary-dark); }
.badge.done { background: var(--green-soft); color: var(--green); }
.badge.failed,
.badge.stopped { background: var(--red-soft); color: var(--red); }

.task-composer {
  display: grid;
  grid-template-columns: 1.05fr 1.05fr 1.25fr 1.05fr;
  gap: 14px;
  align-items: stretch;
  margin-bottom: 14px;
}

.composer-card {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 800;
  color: #243449;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, .92);
  border-radius: 11px;
  min-height: 38px;
  padding: 8px 11px;
  outline: none;
  color: var(--text);
  min-width: 0;
}

textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.55;
}

#taskKeywords {
  min-height: 90px;
  max-height: 128px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(53, 120, 246, .75);
  box-shadow: 0 0 0 4px rgba(53, 120, 246, .12);
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.72);
  font-weight: 700;
}

.check-item input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--primary);
}

.soft-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(247, 250, 255, .8);
  padding: 11px 12px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 20px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: #506075;
  border-radius: 999px;
  padding: 6px 9px;
  font-weight: 700;
  font-size: 12px;
}

.keyword-count-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
  padding-right: 2px;
}

.keyword-count-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.78);
  padding: 8px 10px;
}

.keyword-count-row span {
  min-width: 0;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keyword-count-row input {
  min-height: 34px;
  text-align: center;
  padding: 6px 8px;
}

.keyword-empty {
  padding: 16px;
  font-size: 13px;
}

.queue-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.queue-tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 800;
  color: #506075;
}

.queue-tab.active {
  color: var(--primary-dark);
  border-color: rgba(53, 120, 246, .4);
  background: var(--blue-soft);
}

.task-list,
.compact-list,
.client-list,
.article-list {
  display: grid;
  gap: 10px;
}

.task-batch {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.7);
  padding: 14px;
  overflow: hidden;
}

.batch-head,
.task-row-head,
.article-row,
.client-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.batch-head {
  margin-bottom: 10px;
}

.batch-head strong {
  display: block;
  font-size: 17px;
}

.task-progress {
  height: 7px;
  border-radius: 999px;
  background: #edf2f7;
  overflow: hidden;
  margin: 8px 0 12px;
}

.task-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #5ee0aa);
}

.task-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  margin-top: 8px;
  overflow: hidden;
}

.task-row.running {
  background: #f3f9ff;
  border-color: #cfe0ff;
}

.task-row.failed,
.task-row.stopped {
  background: #fff8ed;
  border-color: #f3d2a3;
}

.task-title strong {
  display: block;
  font-size: 15px;
  margin-bottom: 4px;
}

.task-title span,
.row-note,
.event-log {
  color: var(--muted);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.task-meta {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.task-meta div {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}

.task-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.task-actions,
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  min-width: 0;
}

.task-actions button,
.row-actions button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  height: 32px;
  padding: 0 11px;
  font-weight: 750;
  white-space: nowrap;
}

.client-row .row-actions,
.provider-card .row-actions {
  margin-top: 0;
  flex-wrap: nowrap;
}

details.event-box {
  margin-top: 10px;
}

details.event-box summary {
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}

.event-log {
  max-height: 180px;
  overflow: auto;
  padding-top: 8px;
}

.event-log div {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
}

.client-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, .8fr);
  gap: 14px;
  height: calc(100vh - 170px);
  min-height: 560px;
}

.client-editor,
.client-layout > .panel {
  min-height: 0;
  overflow: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

.client-row,
.article-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.client-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.client-row > div:first-child,
.article-row > div {
  min-width: 0;
}

.client-row p,
.article-row p,
.client-row strong,
.article-row strong {
  overflow-wrap: anywhere;
}

.client-row strong,
.article-row strong {
  display: block;
  margin-bottom: 5px;
}

.filter-row {
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: 1fr 280px;
}

.filter-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
}

.article-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 275px);
  min-height: 520px;
  min-width: 0;
}

.generator-layout {
  grid-template-columns: 330px minmax(0, 1fr);
}

.article-list {
  max-height: none;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  align-content: start;
}

.article-row {
  cursor: pointer;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  min-height: 72px;
}

.article-select-placeholder {
  width: 16px;
  height: 16px;
}

.article-row.active {
  border-color: rgba(53, 120, 246, .55);
  background: var(--blue-soft);
}

.article-preview {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.article-preview .meta-line {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.article-preview pre {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow: auto;
  font-family: inherit;
  line-height: 1.8;
  min-height: 0;
}

.prompt-layout,
.quality-layout,
.publish-layout {
  display: grid;
  gap: 14px;
}

.prompt-layout {
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
}

.prompt-only .prompt-list-panel {
  min-height: calc(100vh - 180px);
}

.prompt-list,
.quality-list {
  display: grid;
  gap: 10px;
}

.prompt-list {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  align-content: start;
  max-height: calc(100vh - 255px);
  overflow: auto;
  padding-right: 4px;
}

.prompt-row {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  min-height: 124px;
  overflow: hidden;
}

.prompt-row strong,
.prompt-row span,
.prompt-row em {
  display: block;
}

.prompt-row em {
  margin-top: 5px;
  color: var(--primary-dark);
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
}

.prompt-row span {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 12px;
}

.prompt-row.active {
  border-color: rgba(53, 120, 246, .55);
  background: var(--blue-soft);
}

.prompt-detail {
  min-height: calc(100vh - 270px);
  max-height: calc(100vh - 270px);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 16px;
  line-height: 1.75;
  font-family: inherit;
}

.quality-layout {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.quality-row {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
}

.quality-row.warn {
  background: var(--amber-soft);
  border-color: #ecd3a7;
}

.quality-row p {
  grid-column: span 2;
  color: var(--muted);
  line-height: 1.55;
}

.review-panel {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 210px);
  min-height: 540px;
  min-width: 0;
}

.review-list {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 4px;
}

.review-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  text-align: left;
  min-height: 72px;
}

.review-item.active {
  border-color: rgba(22, 166, 115, .58);
  background: var(--green-soft);
}

.review-item-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
  font-weight: 850;
}

.review-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.review-status {
  display: inline-flex;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 2px 7px;
  font-weight: 850;
}

.review-status.pending { background: #f7f9fb; color: #516071; }
.review-status.queued { background: var(--blue-soft); color: var(--primary-dark); }
.review-status.publishing { background: #e8f1ff; color: #0b63c4; }
.review-status.published { background: var(--green-soft); color: var(--green); }
.review-status.failed { background: var(--red-soft); color: var(--red); }
.review-status.void { background: var(--amber-soft); color: var(--amber); }

.review-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  overflow: hidden;
}

.review-preview .meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.review-preview .meta-line span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #f8fbff;
}

.review-preview pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.85;
  font-family: inherit;
}

.publish-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
  align-items: start;
  min-width: 0;
}

.publish-layout .form-grid {
  align-items: start;
}

.publish-layout .primary-btn,
.publish-layout .ghost-btn {
  margin-top: 12px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  min-height: 38px;
  padding: 0 2px;
}

.wait-alert {
  border: 1px solid #efc98d;
  background: var(--amber-soft);
  color: #7c4b12;
  border-radius: 10px;
  padding: 9px 10px;
  margin: 8px 0;
  font-weight: 750;
}

.settings-panel {
  margin-bottom: 14px;
}

.model-settings-panel .primary-btn {
  margin-top: 12px;
}

.provider-admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.provider-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.provider-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  min-width: 0;
}

.provider-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.provider-editor {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(247,250,255,.8);
  padding: 12px;
  min-width: 0;
}

.provider-editor-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.import-box {
  min-height: 140px;
  margin: 12px 0;
}

.file-input {
  width: 100%;
  height: 40px;
  margin: 10px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.status-stack {
  display: grid;
  gap: 10px;
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,.58);
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  z-index: 100;
}

.toast {
  width: 320px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  line-height: 1.55;
}

.toast.bad { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

@media (max-width: 1100px) {
  .page-shell { width: min(100vw - 24px, 980px); }
  .top-nav { grid-template-columns: 1fr; }
  .top-nav nav { justify-content: flex-start; overflow: auto; }
  .metric-grid,
  .task-composer { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid,
  .client-layout,
  .article-layout,
  .prompt-layout,
  .quality-layout,
  .publish-layout,
  .review-panel { grid-template-columns: 1fr; height: auto; }
}

@media (max-width: 680px) {
  .metric-grid,
  .task-composer,
  .form-grid,
  .filter-row,
  .filter-row.three,
  .task-meta { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .section-title { align-items: flex-start; flex-direction: column; }
}
