:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #687483;
  --line: #dce3e8;
  --paper: #fbfaf7;
  --surface: #ffffff;
  --teal: #0b7a75;
  --teal-dark: #075f5b;
  --coral: #c9563f;
  --gold: #d8a21b;
  --leaf: #587d46;
  --shadow: 0 18px 60px rgba(23, 32, 42, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px) 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  max-width: 680px;
  font-size: clamp(1.75rem, 3vw, 3rem);
  line-height: 1.02;
}

h2 {
  font-size: 1.03rem;
  line-height: 1.2;
}

.metric-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.metric-strip span,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 6px 11px;
  font-size: 0.83rem;
  white-space: nowrap;
}

.metric-strip strong {
  color: var(--ink);
  margin-right: 4px;
}

.badge-ok {
  border-color: rgba(11, 122, 117, 0.22);
  background: rgba(11, 122, 117, 0.08);
  color: var(--teal-dark);
}

.badge-warn {
  border-color: rgba(201, 86, 63, 0.28);
  background: rgba(201, 86, 63, 0.09);
  color: #943722;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 0.92fr) minmax(460px, 1.45fr) minmax(300px, 0.95fr);
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 48px) 36px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intake-panel,
.output-panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 176px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 12px;
  line-height: 1.45;
}

textarea:focus,
select:focus,
input:focus,
button:focus-visible,
[contenteditable="true"]:focus {
  outline: 3px solid rgba(11, 122, 117, 0.22);
  outline-offset: 2px;
}

.fineprint {
  min-height: 38px;
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.fineprint.is-error {
  color: #943722;
}

.fineprint.is-success {
  color: var(--teal-dark);
}

.button-row,
.button-stack {
  display: grid;
  gap: 10px;
}

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

button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-weight: 800;
  cursor: pointer;
}

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

.primary-button {
  background: var(--teal);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--teal-dark);
}

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-button:hover:not(:disabled) {
  border-color: rgba(11, 122, 117, 0.32);
  color: var(--teal-dark);
}

.provider-section {
  margin-bottom: 14px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-card {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
  cursor: pointer;
}

.mode-card.is-active {
  border-color: rgba(11, 122, 117, 0.42);
  background: rgba(11, 122, 117, 0.07);
}

.mode-card input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--teal);
}

.mode-card span {
  min-width: 0;
}

.mode-card strong,
.mode-card small {
  display: block;
}

.mode-card strong {
  font-size: 0.9rem;
  line-height: 1.15;
}

.mode-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.provider-controls {
  display: grid;
  grid-template-columns: minmax(88px, 0.72fr) minmax(140px, 1.28fr);
  gap: 9px 10px;
  align-items: center;
  margin-top: 12px;
}

.provider-controls label {
  margin: 0;
}

.provider-controls select,
.provider-controls input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 7px 9px;
}

.provider-controls input:disabled {
  background: #f1f4f4;
  color: var(--muted);
}

.spec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.spec-grid div {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.spec-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.spec-grid strong {
  display: block;
  margin-top: 7px;
  font-size: 1rem;
}

.blueprint-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.blueprint-panel .panel-heading {
  padding: 18px 18px 0;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 190px);
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faf9;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

th:first-child,
td:first-child {
  width: 54px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

th:nth-child(2) {
  width: 22%;
}

th:nth-child(3) {
  width: 34%;
}

td[contenteditable="true"] {
  border-left: 3px solid transparent;
  font-size: 0.88rem;
  line-height: 1.35;
}

td[contenteditable="true"]:hover {
  background: #fffdf8;
}

tr.is-selected td {
  background: rgba(216, 162, 27, 0.12);
}

#pagePreview {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.preview-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  margin: 10px 0 14px;
}

.preview-caption span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-list {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.progress-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

meter {
  width: 100%;
  height: 12px;
}

meter::-webkit-meter-bar {
  border: 0;
  border-radius: 999px;
  background: #edf1f2;
}

meter::-webkit-meter-optimum-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.project-tools {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.project-row {
  display: grid;
  gap: 8px;
}

.project-row label {
  margin: 0;
}

.project-row select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 8px 10px;
}

.project-actions {
  display: grid;
  grid-template-columns: minmax(118px, 1fr) minmax(74px, 0.72fr) minmax(86px, 0.82fr);
  gap: 8px;
}

.project-actions button {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 0.84rem;
}

.project-status {
  min-height: 20px;
  margin: 0;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(280px, 0.8fr) minmax(440px, 1.2fr);
  }

  .output-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(260px, 360px) 1fr;
    align-items: start;
    gap: 16px;
  }

  .output-panel .panel-heading,
  .output-panel .preview-caption,
  .output-panel .progress-list,
  .output-panel .project-tools,
  .output-panel .button-stack {
    grid-column: 2;
  }

  #pagePreview {
    grid-row: 1 / span 5;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-strip {
    justify-content: flex-start;
  }

  .app-shell,
  .output-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

  .output-panel .panel-heading,
  .output-panel .preview-caption,
  .output-panel .progress-list,
  .output-panel .project-tools,
  .output-panel .button-stack,
  #pagePreview {
    grid-column: 1;
    grid-row: auto;
  }

  .button-row,
  .project-actions,
  .mode-grid,
  .provider-controls,
  .spec-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 62vh;
  }
}
