:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #61708a;
  --line: #dfe6ef;
  --brand: #2358d6;
  --brand-dark: #1742a5;
  --danger: #c83d3d;
  --keep: #0f7b52;
  --reduce: #a16207;
  --discard: #8a3342;
  --shadow: 0 14px 40px rgba(23, 32, 51, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top left, #eaf0ff, transparent 32rem), var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 24px;
}

.hero {
  margin-bottom: 22px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #ffffff 0%, #eef4ff 100%);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.2rem, 8vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.07em;
}

.subtitle {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.25rem);
}

main { display: grid; gap: 18px; }

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-heading h2 { margin-bottom: 0; font-size: 1.05rem; }
.section-heading p { max-width: 660px; margin-bottom: 0; color: var(--muted); font-size: 0.93rem; }

.context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #35445d;
  font-weight: 700;
  font-size: 0.9rem;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcff;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  padding: 12px 14px;
  outline: none;
}

textarea { min-height: 150px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(35, 88, 214, 0.13); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 10px 15px;
}
button:hover { transform: translateY(-1px); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); }
button.danger { color: var(--danger); }

.status { min-height: 1.4em; margin: 10px 0 0; color: var(--muted); font-weight: 700; }

.results-list { display: grid; gap: 12px; }
.empty-state { color: var(--muted); padding: 8px 0; }
.result-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #fbfcff; }
.result-top { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.badge { border-radius: 999px; padding: 4px 9px; background: #e9eef7; color: #31415c; font-size: 0.78rem; font-weight: 800; }
.badge.keep { background: #ddf7ed; color: var(--keep); }
.badge.reduce { background: #fff2cf; color: var(--reduce); }
.badge.discard { background: #ffe5e9; color: var(--discard); }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-field { color: var(--muted); font-size: 0.84rem; }
.result-field strong { display: block; color: var(--ink); font-size: 0.9rem; }
.original { grid-column: 1 / -1; overflow-wrap: anywhere; }

footer { color: var(--muted); padding: 18px 4px 0; text-align: center; font-size: 0.9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 780px) {
  .app-shell { width: min(100% - 20px, 1120px); padding-top: 10px; }
  .hero, .panel { padding: 18px; }
  .section-heading { display: block; }
  .section-heading h2 { margin-bottom: 6px; }
  .context-grid, .result-grid { grid-template-columns: 1fr; }
  .actions button { width: 100%; }
}

.results-summary {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #c9d8ff;
  border-radius: 14px;
  background: #f4f7ff;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.summary-grid > div {
  padding: 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}
.summary-number { display: block; font-size: 1.45rem; font-weight: 900; line-height: 1; }
.summary-label { color: var(--muted); font-size: 0.8rem; font-weight: 800; text-transform: uppercase; }
.keep-text { color: var(--keep); }
.reduce-text { color: var(--reduce); }
.discard-text { color: var(--discard); }
.summary-sentence { margin: 0; color: #31415c; font-weight: 700; }

.result-card { border-left: 5px solid var(--line); }
.result-card.keep { border-left-color: var(--keep); }
.result-card.reduce { border-left-color: var(--reduce); }
.result-card.discard { border-left-color: var(--discard); }
.result-main { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; }
.result-field.problem,
.result-field.fix {
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: #293850;
  font-size: 0.95rem;
}
.result-field.problem strong,
.result-field.fix strong { font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
.result-field.fix { background: #f7fbff; border-color: #cfe0ff; }
.type-badge { background: #eef3ff; color: var(--brand-dark); }
.result-details { margin-top: 10px; color: var(--muted); }
.result-details summary { cursor: pointer; font-weight: 800; font-size: 0.86rem; }
.result-details .result-grid { margin-top: 10px; }
.original { color: #77849a; font-size: 0.8rem; }

.next-panel h2 { margin-bottom: 10px; font-size: 1.05rem; }
.next-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.next-steps li {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcff;
  color: #35445d;
  font-size: 0.88rem;
  font-weight: 700;
}
.prompt-actions { display: flex; justify-content: flex-end; margin: -6px 0 10px; }
.prompt-panel textarea { min-height: 430px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.55; }

@media (max-width: 780px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-main, .next-steps { grid-template-columns: 1fr; }
  .prompt-actions button { width: 100%; }
  .prompt-panel textarea { min-height: 360px; font-size: 0.9rem; }
}
.prompt-actions { display: flex; justify-content: flex-end; margin: -6px 0 10px; }
.prompt-panel textarea { min-height: 430px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.55; }

.issue-clusters {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcff;
}
.cluster-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.cluster-heading h3 { margin: 0; font-size: 1rem; }
.cluster-heading p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.cluster-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.cluster-card { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.cluster-title { font-weight: 900; color: var(--ink); }
.cluster-frequency { margin-top: 4px; color: var(--brand-dark); font-weight: 800; }
.cluster-meta { margin-top: 4px; color: var(--muted); font-size: 0.82rem; }
.cluster-example { margin-top: 9px; color: #56657d; font-size: 0.84rem; overflow-wrap: anywhere; }
.cluster-example strong { display: block; color: var(--ink); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

@media (max-width: 780px) {
  .cluster-heading { display: block; }
  .cluster-heading h3 { margin-bottom: 4px; }
  .cluster-grid { grid-template-columns: 1fr; }
}

.priority-ranking {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #bfd1ff;
  border-radius: 14px;
  background: #f7f9ff;
}
.priority-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.priority-heading h3 { margin: 0; font-size: 1rem; }
.priority-heading p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.priority-list { display: grid; gap: 10px; }
.priority-card { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.priority-rank { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 900; }
.priority-title { font-weight: 900; color: var(--ink); }
.priority-meta { margin-top: 3px; color: var(--brand-dark); font-weight: 800; }
.priority-example { margin-top: 8px; color: #56657d; font-size: 0.84rem; overflow-wrap: anywhere; }
.priority-example strong { display: block; color: var(--ink); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

@media (max-width: 780px) {
  .priority-heading { display: block; }
  .priority-heading h3 { margin-bottom: 4px; }
  .priority-card { grid-template-columns: 1fr; }
  .priority-rank { width: auto; }
}

.pr-spec-section, .impl-prompt-section {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #ffdcbf;
  border-radius: 14px;
  background: #fff9f4;
}
.impl-prompt-section { border-color: #c9d8ff; background: #f4f7ff; }

.pr-spec-heading, .impl-prompt-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.pr-spec-heading h3, .impl-prompt-heading h3 { margin: 0; font-size: 1rem; }
.pr-spec-body, .impl-prompt-body { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.pr-spec-body pre, .impl-prompt-body pre { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88rem; white-space: pre-wrap; word-break: break-all; }

@media (max-width: 780px) {
  .pr-spec-heading, .impl-prompt-heading { display: block; }
  .pr-spec-heading h3, .impl-prompt-heading h3 { margin-bottom: 8px; }
  .pr-spec-heading button, .impl-prompt-heading button { width: 100%; }
}
