:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #202124;
  --muted: #6b6f76;
  --line: #d9d6cf;
  --soft: #f1eee8;
  --blue: #2f68c8;
  --green: #167a54;
  --orange: #b85d1c;
  --red: #b83a3a;
  --violet: #6b4bb8;
  --shadow: 0 16px 40px rgba(27, 31, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

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

button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9f9a90;
  background: #fbfaf7;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  height: 100vh;
  min-height: 0;
  margin: 0 auto;
  padding: 14px 0 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.topbar,
.archive-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 0 0 10px;
}

.archive-panel {
  align-items: start;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  padding: 10px 0 0;
}

.eyebrow,
.agent-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

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

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

.run-meta,
.archive-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.run-archive {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
  flex: 1;
}

.run-archive select {
  width: min(420px, 100%);
  min-width: 220px;
}

.run-meta label {
  width: min(320px, 42vw);
}

label,
legend {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
  outline: none;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

.agent-prompt {
  min-height: 58px;
  max-height: 130px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 104, 200, 0.14);
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(245px, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.agent-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 5px solid var(--blue);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

.agent-card.analyst {
  border-top-color: var(--blue);
}

.agent-card.observer {
  border-top-color: var(--green);
}

.agent-card.interviewer {
  border-top-color: var(--violet);
}

.agent-card.copywriter {
  border-top-color: var(--orange);
}

.agent-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.status {
  width: 18px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2.5px solid var(--line);
  border-top-color: #9f9a90;
  background: transparent;
}

.status.waiting {
  border-color: var(--line);
  background: #eeeae2;
}

.status.done {
  border-color: var(--green);
  background: var(--green);
}

.status.running {
  border-color: var(--line);
  border-top-color: var(--blue);
  animation: spin 0.75s linear infinite;
}

.status.blocked {
  border-color: var(--red);
  background: var(--red);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.fields {
  display: grid;
  align-content: start;
  gap: 8px;
}

.company-list {
  display: grid;
  gap: 10px;
}

.company-row {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 10px;
}

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

.company-row textarea {
  min-height: 96px;
}

.icon-button {
  min-width: 36px;
  padding: 0;
  color: var(--red);
}

.danger-button {
  border-color: rgba(184, 58, 58, 0.45);
  color: var(--red);
  font-weight: 800;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(32, 33, 36, 0.42);
  padding: 18px;
  z-index: 10;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(640px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.2);
  padding: 16px;
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-actions {
  justify-content: flex-end;
}

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

.date-summary {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfaf7;
  color: #3f4348;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 800;
}

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

.output {
  display: block;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfaf7;
  color: #3f4348;
  padding: 12px;
  white-space: normal;
  word-break: break-word;
  font-size: 13px;
}

.markdown-viewer {
  line-height: 1.5;
}

.markdown-viewer > *:first-child {
  margin-top: 0;
}

.markdown-viewer > *:last-child {
  margin-bottom: 0;
}

.markdown-viewer h1,
.markdown-viewer h2,
.markdown-viewer h3,
.markdown-viewer h4,
.markdown-viewer h5,
.markdown-viewer h6 {
  margin: 14px 0 7px;
  color: var(--ink);
  line-height: 1.24;
  letter-spacing: 0;
}

.markdown-viewer h1 {
  margin-top: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 22px;
}

.markdown-viewer h2 {
  margin-top: 18px;
  font-size: 19px;
}

.markdown-viewer h3 {
  font-size: 17px;
}

.markdown-viewer h4 {
  font-size: 15px;
}

.markdown-viewer h5,
.markdown-viewer h6 {
  font-size: 14px;
}

.markdown-viewer p {
  margin: 7px 0;
}

.markdown-viewer ul,
.markdown-viewer ol {
  margin: 6px 0 10px;
  padding-left: 20px;
}

.markdown-viewer li {
  margin: 4px 0;
}

.markdown-viewer hr {
  height: 1px;
  border: 0;
  background: var(--line);
  margin: 14px 0;
}

.markdown-viewer code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.md-code {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 12px;
  white-space: pre;
}

.md-code code {
  border: 0;
  background: transparent;
  padding: 0;
}

.md-table-wrap {
  width: 100%;
  overflow: auto;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.markdown-viewer table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.markdown-viewer th,
.markdown-viewer td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.markdown-viewer th {
  background: #f1eee8;
  color: var(--ink);
  font-size: 12px;
}

.markdown-viewer tr:last-child td {
  border-bottom: 0;
}

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

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
    min-height: 100vh;
  }

  .agent-grid {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    grid-auto-rows: minmax(560px, auto);
    height: auto;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .shell {
    min-height: auto;
    height: auto;
    display: block;
    width: min(100% - 20px, 680px);
    padding-top: 16px;
  }

  .topbar,
  .archive-panel,
  .run-meta,
  .archive-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .run-meta label {
    width: 100%;
  }

  .run-archive {
    grid-template-columns: 1fr;
  }

  .agent-grid {
    grid-template-columns: 1fr;
  }

  .company-row {
    grid-template-columns: 1fr;
  }

  .agent-card {
    min-height: 560px;
  }
}
