:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d7dce3;
  --line-soft: #e8ebef;
  --text: #111827;
  --muted: #687386;
  --blue: #2563eb;
  --green: #18a957;
  --green-soft: #e9f8ee;
  --red: #dc2626;
  --red-soft: #fff1f1;
  --yellow-soft: #fff8d9;
  --yellow-line: #e7c955;
}

* {
  box-sizing: border-box;
}

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

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

button,
.button,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
}

button,
.button {
  align-items: center;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  background: #fff;
  color: var(--text);
  min-height: 34px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #111827 50%),
    linear-gradient(135deg, #111827 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 14px,
    calc(100% - 10px) 14px;
  background-repeat: no-repeat;
  background-size:
    8px 8px,
    8px 8px;
  padding-right: 34px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
}

label,
.field-full {
  display: grid;
  gap: 6px;
}

label span,
.label {
  font-size: 12px;
  font-weight: 800;
}

small,
.hint,
.page-header p,
.list-meta {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.app {
  margin: 0 auto;
  max-width: 1500px;
  min-height: 100vh;
  padding: 28px 32px;
}

.admin-nav {
  align-items: center;
  display: flex;
  gap: 18px;
  margin-bottom: 22px;
}

.admin-nav a {
  color: #344054;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}

.admin-nav a.active,
.admin-nav a:hover {
  color: var(--blue);
}

.hidden {
  display: none !important;
}

.locked .view,
.locked .admin-nav {
  display: none;
}

.login-view {
  align-items: center;
  display: grid;
  min-height: calc(100vh - 56px);
  justify-items: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  display: grid;
  gap: 18px;
  max-width: 430px;
  padding: 32px;
  width: 100%;
}

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

.secondary {
  background: #fff;
}

.full {
  width: 100%;
}

.queue-view {
  align-items: start;
  display: grid;
  gap: 28px;
  grid-template-columns: minmax(520px, 620px) minmax(0, 1fr);
}

.idea-panel h1 {
  font-size: 42px;
  margin-bottom: 34px;
}

.idea-form,
.profile-card,
.project-row,
.stats-grid > div,
.setting-section,
.library-item,
.activity-row,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.idea-form {
  display: grid;
  gap: 28px;
  padding: 32px;
}

.idea-form label span,
.idea-form .label {
  font-size: 20px;
}

.idea-form select,
.idea-form input,
.idea-form textarea {
  border-radius: 8px;
  font-size: 20px;
  min-height: 58px;
  padding: 14px 18px;
}

.idea-form textarea {
  min-height: 170px;
}

.range-field span {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.range-field strong {
  color: var(--blue);
  font-size: 20px;
}

input[type="range"] {
  accent-color: #1478ff;
  border: 0;
  min-height: 24px;
  padding: 0;
}

.triple-input,
.two-column {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, 1fr);
}

.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.idea-form .primary {
  border-radius: 8px;
  font-size: 20px;
  min-height: 58px;
}

.stats-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 36px;
}

.stats-grid > div {
  padding: 24px;
}

.stats-grid span {
  color: var(--muted);
  display: block;
  font-size: 16px;
  font-weight: 850;
  margin-bottom: 5px;
}

.stats-grid strong {
  font-size: 42px;
}

.health-strip {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.health-strip span {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 8px;
  grid-template-columns: auto 1fr auto;
  min-height: 38px;
  padding: 0 10px;
}

.dot {
  background: var(--muted);
  border-radius: 99px;
  height: 8px;
  width: 8px;
}

.dot.up {
  background: var(--green);
}

.dot.down {
  background: var(--red);
}

.dot.missing {
  background: var(--yellow-line);
}

.projects-header,
.page-header {
  align-items: start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.header-actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.search {
  width: 210px;
}

.list-meta {
  margin-bottom: 10px;
}

.project-list,
.library-list,
.activity-log {
  display: grid;
  gap: 10px;
}

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

.project-status,
.project-main {
  display: grid;
  gap: 8px;
}

.project-main strong,
.library-item strong,
.activity-row strong {
  font-size: 14px;
  line-height: 1.3;
}

.project-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
}

.language-select {
  max-width: 220px;
  min-width: 160px;
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.project-actions .button,
.project-actions button {
  min-width: 88px;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 11px;
  font-weight: 900;
  justify-content: center;
  min-width: 92px;
  padding: 5px 9px;
  width: fit-content;
}

.status.queued {
  background: var(--yellow-soft);
  border: 1px solid #f0df99;
  color: #8a5415;
}

.status.processing {
  background: #eaf1ff;
  border: 1px solid #bed2ff;
  color: #194fae;
}

.status.done {
  background: var(--green-soft);
  border: 1px solid #b9e7ca;
  color: #12633a;
}

.status.error {
  background: var(--red-soft);
  border: 1px solid #f3b4b4;
  color: var(--red);
}

.page-header {
  margin-bottom: 18px;
}

.settings-actions,
.profile-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.profile-card {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) auto;
  margin-bottom: 18px;
  padding: 16px;
}

.page-header div {
  display: grid;
  gap: 6px;
}

.library-item {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 16px;
}

.library-item div {
  display: grid;
  gap: 5px;
}

.setting-section {
  margin-bottom: 12px;
  overflow: hidden;
}

.section-title {
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  display: flex;
  justify-content: space-between;
  min-height: 62px;
  padding: 12px 16px;
  width: 100%;
}

.section-title span {
  display: grid;
  gap: 4px;
  text-align: left;
}

.section-title em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

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

.single-column {
  grid-template-columns: 1fr;
}

.field-full {
  grid-column: 1 / -1;
}

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

.choice-row button {
  min-height: 38px;
}

.choice-row .active-choice {
  background: #eaf8ef;
  border-color: var(--green);
  color: #086b32;
}

.key-field {
  gap: 7px;
}

.key-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.key-row button {
  min-width: 74px;
}

.key-field em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  min-height: 14px;
}

.key-field em.ok {
  color: var(--green);
}

.key-field em.failed {
  color: var(--red);
}

.key-field em.missing,
.key-field em.checking {
  color: #8a5415;
}

.danger {
  background: var(--red-soft);
  border-color: #f3b4b4;
  color: var(--red);
}

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

.plain-link {
  background: transparent;
  border: 0;
  color: var(--blue);
  font-weight: 850;
  min-height: 0;
  padding: 0;
}

.detail-view {
  display: grid;
  gap: 18px;
}

.detail-header {
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 24px;
}

.detail-header > div:first-child {
  display: grid;
  gap: 10px;
}

.detail-header h1 {
  font-size: 28px;
}

.detail-header p {
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.detail-meta,
.detail-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.detail-meta > span:not(.status) {
  color: var(--muted);
  font-weight: 850;
}

.progress-card,
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.progress-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.progress-head {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

.progress-head > div {
  display: grid;
  gap: 3px;
}

.progress-head span,
.output-list span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.progress-head strong {
  font-size: 38px;
  line-height: 1;
}

.progress-head dl {
  display: flex;
  gap: 24px;
  margin: 0;
}

.progress-head dt,
.progress-head dd {
  margin: 0;
  text-align: right;
}

.progress-head dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.progress-head dd {
  font-size: 13px;
  font-weight: 900;
}

.big-progress,
.progress-tiles i {
  background: #eff2f6;
  border-radius: 999px;
  display: block;
  overflow: hidden;
}

.big-progress {
  height: 10px;
}

.big-progress span,
.progress-tiles em {
  background: linear-gradient(90deg, var(--blue), #0f9f8a);
  display: block;
  height: 100%;
  transition: width 160ms ease;
  width: 0;
}

.progress-tiles {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.progress-tiles div {
  border: 1px solid var(--line);
  border-radius: 4px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.progress-tiles span {
  font-size: 12px;
  font-weight: 850;
}

.progress-tiles b {
  justify-self: end;
}

.progress-tiles i {
  height: 6px;
}

.detail-grid {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
}

.detail-panel {
  overflow: hidden;
}

.detail-panel header {
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  min-height: 48px;
  padding: 12px 16px;
}

.detail-panel header small {
  font-weight: 850;
}

.detail-wide {
  grid-column: 1;
}

.script-grid,
.chunk-list,
.output-list,
.activity-log.compact {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.script-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.script-grid div,
.chunk-list article,
.chunk-details {
  border: 1px solid var(--line-soft);
  border-radius: 4px;
}

.script-grid div {
  padding: 10px;
}

.script-grid div,
.chunk-list article div,
.chunk-details summary {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.chunk-list article {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.chunk-list p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.chunk-details {
  background: #fff;
  overflow: hidden;
}

.chunk-details summary {
  cursor: pointer;
  list-style: none;
  min-height: 56px;
  padding: 10px 12px;
}

.chunk-details summary::-webkit-details-marker {
  display: none;
}

.chunk-details summary span {
  display: grid;
  gap: 4px;
}

.chunk-details summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.chunk-details[open] summary {
  border-bottom: 1px solid var(--line-soft);
}

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

.chunk-inspector section {
  background: #f8fafc;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
}

.chunk-inspector h4 {
  font-size: 12px;
  margin: 0;
}

.asset-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.asset-thumb,
.asset-link,
.empty-asset,
.step-list span {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  color: #263142;
  font-size: 11px;
  font-weight: 800;
  overflow-wrap: anywhere;
  padding: 8px;
  text-decoration: none;
}

.asset-thumb {
  display: grid;
  gap: 6px;
}

.asset-thumb img {
  aspect-ratio: 16 / 9;
  background: #eef2f7;
  border-radius: 3px;
  object-fit: cover;
  width: 100%;
}

.asset-link {
  display: block;
}

.empty-asset {
  color: var(--muted);
}

.step-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-status {
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  padding: 3px 7px;
}

.mini-status.done {
  background: var(--green-soft);
  color: #12633a;
}

.mini-status.processing {
  background: #eaf1ff;
  color: #194fae;
}

.mini-status.queued {
  background: var(--yellow-soft);
  color: #8a5415;
}

.output-list {
  gap: 6px;
}

.output-list code {
  background: #f8fafc;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  color: #263142;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  padding: 8px;
}

.activity-log.compact .activity-row {
  gap: 8px;
  grid-template-columns: 110px minmax(0, 1fr) 100px;
  padding: 8px;
}

.reference-card {
  align-items: center;
  background: #fff8d9;
  border: 1px solid var(--yellow-line);
  border-radius: 4px;
  display: flex;
  gap: 14px;
  max-width: 640px;
  padding: 12px;
}

.reference-card img {
  border-radius: 4px;
  height: 54px;
  object-fit: cover;
  width: 54px;
}

.reference-card div {
  display: grid;
  gap: 3px;
}

.active-title {
  border-top: 2px solid var(--blue);
}

.worker-body {
  grid-template-columns: 1fr auto;
}

.worker-list {
  display: grid;
  gap: 8px;
}

.worker-row {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  min-height: 54px;
  padding: 10px;
}

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

.worker-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.language-grid {
  display: flex;
  flex-wrap: wrap;
}

.language-grid button {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: #344054;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  min-height: 34px;
  padding: 6px 10px;
}

.language-grid button.active-language,
.language-grid button:hover {
  background: #eaf8ef;
  border-color: var(--green);
  color: #086b32;
}

.activity-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 90px minmax(0, 1fr) 160px 130px;
  padding: 14px;
}

.activity-row span,
.activity-row em,
.activity-row small {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.empty-state {
  color: var(--muted);
  font-weight: 800;
  padding: 22px;
}

.toast {
  background: var(--text);
  border-radius: 8px;
  bottom: 20px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 14px);
  transition: 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 980px) {
  .app {
    padding: 20px;
  }

  .admin-nav {
    overflow-x: auto;
    white-space: nowrap;
  }

  .queue-view,
  .detail-grid,
  .profile-card,
  .section-body,
  .worker-body,
  .triple-input,
  .two-column {
    grid-template-columns: 1fr;
  }

  .idea-panel h1 {
    font-size: 28px;
    margin-bottom: 20px;
  }

  .idea-form {
    gap: 18px;
    padding: 20px;
  }

  .idea-form label span,
  .idea-form .label,
  .range-field strong,
  .idea-form select,
  .idea-form input,
  .idea-form textarea,
  .idea-form .primary {
    font-size: 14px;
  }

  .idea-form select,
  .idea-form input {
    min-height: 38px;
    padding: 8px 10px;
  }

  .stats-grid strong {
    font-size: 28px;
  }

  .projects-header,
  .page-header {
    display: grid;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions > *,
  .search {
    width: 100%;
  }

  .project-row,
  .activity-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .detail-header,
  .progress-head {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-actions {
    justify-content: flex-start;
  }

  .progress-head dl,
  .progress-tiles,
  .script-grid,
  .chunk-inspector,
  .step-list {
    grid-template-columns: 1fr;
  }

  .progress-head dl {
    display: grid;
    gap: 8px;
  }

  .progress-head dt,
  .progress-head dd {
    text-align: left;
  }

  .detail-wide {
    grid-column: auto;
  }

  .project-actions {
    justify-content: start;
  }
}
