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

:root {
  --navy:      #1a3352;
  --navy-lt:   #2a4a6e;
  --teal:      #1d7a6e;
  --teal-lt:   #e6f4f2;
  --bg:        #f0f4f8;
  --surface:   #ffffff;
  --border:    #dde3ec;
  --text:      #1a1a2e;
  --text-2:    #556080;
  --text-3:    #8a94a6;
  --green:     #16a34a;
  --green-bg:  #f0fdf4;
  --amber:     #d97706;
  --amber-bg:  #fffbeb;
  --red:       #dc2626;
  --red-bg:    #fef2f2;
  --blue:      #2563eb;
  --blue-bg:   #eff6ff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --radius:    8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--navy);
  color: #fff;
  padding: 0 2rem;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}

.app-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.app-header .tagline {
  font-size: .8rem;
  opacity: .65;
  font-style: italic;
}

.app-header .spacer { flex: 1; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.container-narrow {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.5rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):hover { opacity: .88; }
.btn:not(:disabled):active { transform: scale(.98); }

.btn-primary   { background: var(--navy);  color: #fff; }
.btn-teal      { background: var(--teal);  color: #fff; }
.btn-danger    { background: var(--red);   color: #fff; }
.btn-success   { background: var(--green); color: #fff; }
.btn-outline   { background: transparent; color: var(--navy); border: 1.5px solid var(--navy); }
.btn-ghost     { background: transparent; color: var(--text-2); border: 1.5px solid var(--border); }
.btn-sm        { padding: .35rem .85rem; font-size: .8rem; }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.badge-draft              { background: #e2e8f0; color: #475569; }
.badge-justification_generated { background: var(--blue-bg); color: var(--blue); }
.badge-submitted          { background: #ede9fe; color: #7c3aed; }
.badge-approved           { background: var(--green-bg); color: var(--green); }
.badge-denied             { background: var(--red-bg); color: var(--red); }
.badge-appeal_generated   { background: var(--blue-bg); color: var(--blue); }
.badge-appeal_submitted   { background: #ede9fe; color: #7c3aed; }
.badge-documenting        { background: #fef3c7; color: #92400e; }
.badge-resolved           { background: var(--green-bg); color: var(--green); }
.badge-generation_failed  { background: #fee2e2; color: #991b1b; }
.badge-complete           { background: var(--green-bg); color: var(--green); }

.badge-confident   { background: var(--green-bg); color: var(--green); }
.badge-named_source { background: var(--blue-bg); color: var(--blue); }
.badge-flagged     { background: var(--amber-bg); color: var(--amber); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 600; color: var(--text-2); margin-bottom: .4rem; }
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: .6rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--navy);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-hint { font-size: .78rem; color: var(--text-3); margin-top: .3rem; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 2px solid var(--border); }
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
th { padding: .75rem 1rem; text-align: left; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
td { padding: .85rem 1rem; font-size: .875rem; }
td.condition { font-weight: 600; }

/* ── Step progress ───────────────────────────────────────────────────────── */
.step-progress {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 2rem;
}

.step-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex: 1;
}

.step-item:last-child { flex: none; }

.step-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
}

.step-dot.done   { background: var(--teal); border-color: var(--teal); color: #fff; }
.step-dot.active { background: var(--navy); border-color: var(--navy); color: #fff; }

.step-label { font-size: .72rem; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.step-label.active { color: var(--navy); }
.step-label.done   { color: var(--teal); }

.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 .25rem;
}
.step-line.done { background: var(--teal); }

/* ── Document display ────────────────────────────────────────────────────── */
.document-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.document-toolbar {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.document-toolbar .doc-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  flex: 1;
}

.document-body {
  padding: 2.5rem 3rem;
  font-family: Georgia, 'Times New Roman', Times, serif;
  font-size: .95rem;
  line-height: 1.85;
  color: #1a1a2e;
  white-space: pre-wrap;
}

/* ── Claims list ─────────────────────────────────────────────────────────── */
.claims-section { margin-top: 1.5rem; }
.claims-section h3 { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: .75rem; }

.claim-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: .5rem;
  background: #fafbfc;
}

.claim-item .badge { flex-shrink: 0; margin-top: .1rem; }
.claim-item .claim-text { font-size: .875rem; color: var(--text); flex: 1; }
.claim-item .claim-source { font-size: .75rem; color: var(--text-3); margin-top: .2rem; }

/* ── Rebuttal map ────────────────────────────────────────────────────────── */
.rebuttal-map { margin-top: 1.5rem; }
.rebuttal-map h3 { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: .75rem; }

.rebuttal-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: .75rem;
}

.rebuttal-denial {
  background: var(--red-bg);
  padding: .75rem 1rem;
  border-bottom: 1px solid #fecaca;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}

.rebuttal-denial .label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--red); flex-shrink: 0; padding-top: .1rem; }
.rebuttal-denial .reason { font-size: .875rem; color: #7f1d1d; }

.rebuttal-response {
  background: var(--surface);
  padding: .75rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
}

.rebuttal-response .label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--green); flex-shrink: 0; padding-top: .1rem; }
.rebuttal-response .rebuttal-text { font-size: .875rem; color: var(--text); flex: 1; }

/* ── Missing info note ───────────────────────────────────────────────────── */
.missing-note {
  background: var(--amber-bg);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-top: 1rem;
  display: flex;
  gap: .5rem;
  align-items: flex-start;
}
.missing-note .icon { color: var(--amber); font-size: 1rem; flex-shrink: 0; }
.missing-note .text { font-size: .875rem; color: #78350f; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 540px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-3); line-height: 1; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }

/* ── Spinner / Loading ───────────────────────────────────────────────────── */
.generating-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.8);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.generating-overlay.show { display: flex; }

.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.generating-overlay p { font-size: 1rem; font-weight: 600; color: var(--navy); }
.generating-overlay small { font-size: .8rem; color: var(--text-3); }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.5rem;
}

.page-back {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .875rem;
  color: var(--text-2);
  text-decoration: none;
  margin-bottom: 1.5rem;
  font-weight: 600;
}
.page-back:hover { color: var(--navy); }

.action-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-3);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 1rem; margin-bottom: 1.5rem; }

.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #bbf7d0; }

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

.meta-row { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin-bottom: 1rem; }
.meta-item { font-size: .8rem; color: var(--text-3); }
.meta-item strong { color: var(--text-2); }

/* ── Markdown document rendering ─────────────────────────────────────────── */
.document-body h1, .document-body h2, .document-body h3 {
  font-family: Georgia, serif;
  margin: 1.2em 0 .4em;
  font-size: 1rem;
  font-weight: 700;
}
.document-body h1 { font-size: 1.05rem; }
.document-body p { margin: 0 0 .9em; }
.document-body strong { font-weight: 700; }
.document-body em { font-style: italic; }
.document-body ul, .document-body ol { margin: .5em 0 .9em 1.5em; }
.document-body li { margin-bottom: .25em; }
.document-body hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* ── Read-only history ───────────────────────────────────────────────────── */
.step-dot.clickable { cursor: pointer; }
.step-dot.clickable:hover { opacity: .75; }

.readonly-banner {
  background: #f0f4f8;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem 1rem;
  font-size: .8rem;
  color: var(--text-3);
  text-align: center;
  margin-bottom: 1rem;
}

/* ── Frozen/submitted state ──────────────────────────────────────────────── */
.frozen-banner {
  background: #ede9fe;
  border: 1px solid #c4b5fd;
  border-radius: var(--radius);
  padding: .6rem 1rem;
  font-size: .875rem;
  color: #5b21b6;
  text-align: center;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

/* ── Screen 4 lived outcome ──────────────────────────────────────────────── */
.lived-outcome-field {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 1rem;
}
.lived-outcome-field .field-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: .75rem 1rem;
  display: flex;
  align-items: baseline;
  gap: .75rem;
}
.lived-outcome-field .field-header label {
  font-weight: 700;
  font-size: .875rem;
  color: var(--navy);
}
.lived-outcome-field .field-vector {
  font-size: .75rem;
  color: var(--teal);
  font-style: italic;
}
.lived-outcome-field .field-body { padding: 1rem; }
.lived-outcome-field textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .9rem;
  font-size: .875rem;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
  color: var(--text);
  background: var(--surface);
}
.lived-outcome-field textarea:focus { outline: none; border-color: var(--navy); }

/* ── Edit-regenerate notice ──────────────────────────────────────────────── */
.regen-notice {
  background: var(--teal-lt);
  border: 1px solid #a7d4cf;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .875rem;
  color: #0f4f47;
  margin-bottom: 1rem;
}
