/* ── Reset & tokens ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #20243a;
  --border:    #2a2f45;
  --border2:   #353b54;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --accent:    #4f8ef7;
  --accent2:   #7c5cd8;
  --green:     #22c55e;
  --yellow:    #f59e0b;
  --orange:    #f97316;
  --red:       #ef4444;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
}

html { font-size: 15px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ───────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.15rem;
  letter-spacing: -.01em;
}
.brand-icon { width: 22px; height: 22px; stroke: var(--accent); }
.brand-name { color: var(--text); }
.brand-name strong { color: var(--accent); }
.topbar-nav { display: flex; gap: .5rem; align-items: center; }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: .15em .55em;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-version { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.badge-critical { background: rgba(239,68,68,.18); color: var(--red); }
.badge-high     { background: rgba(249,115,22,.18); color: var(--orange); }
.badge-medium   { background: rgba(245,158,11,.18); color: var(--yellow); }
.badge-low      { background: rgba(34,197,94,.18);  color: var(--green); }

/* ── Layout ───────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}

/* ── Panel base ───────────────────────────────────────────────── */
.panel {
  padding: 1.75rem 1.5rem;
  overflow-y: auto;
  height: calc(100vh - 53px);
}
.panel-input {
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.panel-workflow { background: var(--bg); }
.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  letter-spacing: -.01em;
}

/* ── Form ─────────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 1rem 0 .35rem;
}
.required { color: var(--red); }
.field-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
  padding: .55rem .8rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
  line-height: 1.5;
}
.field-input::placeholder { color: var(--muted); opacity: .7; }
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,142,247,.15);
}
.field-textarea { resize: vertical; min-height: 110px; }
select.field-input { cursor: pointer; }
select.field-input option { background: var(--surface2); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .6rem 1.1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s;
  font-family: inherit;
  line-height: 1;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: .9; }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-full { width: 100%; justify-content: center; margin-top: 1.25rem; }
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .78rem;
  padding: .25rem .65rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.example-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--border);
}
.example-label { font-size: .75rem; color: var(--muted); }

/* ── Loading state ────────────────────────────────────────────── */
.btn-primary.loading {
  opacity: .7;
  pointer-events: none;
}
.btn-primary.loading::after {
  content: '';
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-left: .3rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  gap: 1.25rem;
  color: var(--muted);
  text-align: center;
  padding: 2rem;
}
.empty-state svg { width: 72px; height: 72px; opacity: .5; }
.empty-state p { max-width: 280px; font-size: .9rem; line-height: 1.7; }

/* ── Workflow ─────────────────────────────────────────────────── */
.workflow-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

/* Stage tabs */
.stage-tabs {
  display: flex;
  gap: .35rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.stage-tab {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  padding: .45rem .9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  position: relative;
}
.stage-tab:hover { border-color: var(--accent); color: var(--accent); }
.stage-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.stage-tab.done::after {
  content: '✓';
  position: absolute;
  top: -6px; right: -6px;
  width: 16px; height: 16px;
  background: var(--green);
  color: #fff;
  font-size: .65rem;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  line-height: 16px;
  text-align: center;
}

/* Stage content pane */
.stage-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  min-height: 240px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.stage-content h3 {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: .85rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.stage-content h3 svg { width: 16px; height: 16px; }

/* Checklist */
.checklist { list-style: none; display: flex; flex-direction: column; gap: .45rem; }
.checklist li {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  font-size: .88rem;
  color: var(--text);
}
.checklist li::before {
  content: '';
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  margin-top: 3px;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='8' cy='8' r='8' fill='%2322c55e'/%3E%3Cpath d='M4.5 8l2.5 2.5 4.5-4.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.checklist li.warn::before {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='8' cy='8' r='8' fill='%23f59e0b'/%3E%3Cpath d='M8 5v3.5M8 11v.5' stroke='white' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* Code block */
.code-block {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: .8rem;
  color: #c9d1d9;
  overflow-x: auto;
  white-space: pre;
  margin: .6rem 0;
  line-height: 1.65;
}
.code-block .kw  { color: #ff7b72; }
.code-block .str { color: #a5d6ff; }
.code-block .cmt { color: #8b949e; }
.code-block .fn  { color: #d2a8ff; }
.code-block .num { color: #79c0ff; }

/* File chip list */
.file-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.file-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .2rem .7rem;
  font-size: .78rem;
  color: var(--accent);
  font-family: monospace;
}

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* Numbered list */
.num-list { list-style: none; counter-reset: item; display: flex; flex-direction: column; gap: .5rem; }
.num-list li { counter-increment: item; display: flex; gap: .6rem; font-size: .88rem; }
.num-list li::before {
  content: counter(item);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: .72rem;
  font-weight: 700;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Stage nav buttons */
.stage-nav {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
  gap: .5rem;
}

/* ── PR Summary ───────────────────────────────────────────────── */
.pr-summary {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  animation: fadeIn .25s ease;
}
.pr-summary-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .95rem;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.pr-summary-header svg { width: 18px; height: 18px; }

.pr-section { margin-bottom: 1rem; }
.pr-section-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: .4rem;
}
.pr-section p { font-size: .88rem; line-height: 1.65; color: var(--text); }

/* Acceptance criteria */
.ac-list { list-style: none; display: flex; flex-direction: column; gap: .35rem; }
.ac-list li {
  font-size: .85rem;
  padding-left: 1.3rem;
  position: relative;
  color: var(--text);
}
.ac-list li::before {
  content: '☐';
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: .65rem 1.1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 200;
}
.toast.show { opacity: 1; transform: none; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .panel {
    height: auto;
    overflow-y: visible;
  }
  .panel-input {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 480px) {
  .stage-tabs { gap: .25rem; }
  .stage-tab { font-size: .76rem; padding: .4rem .6rem; }
  .stage-content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}
