@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700&display=swap');

:root {
  --canvas: #f4f2ec;
  --surface: #fffefa;
  --surface-strong: #ffffff;
  --ink: #1f2923;
  --muted: #6f776f;
  --faint: #a3aaa2;
  --line: #e2e1d9;
  --line-strong: #cbd0c7;
  --green: #146b48;
  --green-dark: #0f573b;
  --green-soft: #e6f0e9;
  --amber: #986224;
  --amber-soft: #f7ecd9;
  --red: #98463e;
  --red-soft: #f8e9e7;
  --shadow: 0 18px 55px rgba(31, 41, 35, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--ink); background: var(--canvas); font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.builder-app { min-height: 100vh; }
.builder-topbar { height: 70px; padding: 0 18px 0 22px; position: sticky; top: 0; z-index: 30; display: grid; grid-template-columns: 250px minmax(260px, 1fr) auto; align-items: center; gap: 20px; border-bottom: 1px solid var(--line); background: rgba(255,254,250,.94); backdrop-filter: blur(14px); }
.builder-brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-family: Manrope, sans-serif; font-size: 19px; font-weight: 700; }
.builder-brand em { padding: 4px 7px; border-radius: 6px; background: var(--green-soft); color: var(--green-dark); font: 700 9px/1 "DM Sans", sans-serif; letter-spacing: .06em; text-transform: uppercase; }
.builder-brand-mark { width: 31px; height: 31px; padding: 8px 7px; display: inline-flex; align-items: end; justify-content: center; gap: 2px; border-radius: 50%; background: var(--ink); }
.builder-brand-mark i { width: 3px; display: block; border-radius: 3px; background: white; }
.builder-brand-mark i:nth-child(1) { height: 8px; }
.builder-brand-mark i:nth-child(2) { height: 15px; }
.builder-brand-mark i:nth-child(3) { height: 11px; }
.project-switcher { min-width: 0; display: flex; align-items: center; justify-content: center; gap: 9px; }
.project-switcher label { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.project-switcher select { width: min(340px, 48vw); height: 39px; padding: 0 34px 0 11px; border: 1px solid var(--line); border-radius: 9px; background: white; outline: none; font-size: 12px; font-weight: 600; }
.save-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.save-state i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.save-state.saving i { background: var(--amber); }
.save-state.error { color: var(--red); }
.save-state.error i { background: var(--red); }
.builder-top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.button { min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; cursor: pointer; color: inherit; text-decoration: none; font-size: 12px; font-weight: 700; transition: transform .15s ease, background .15s ease, border-color .15s ease; white-space: nowrap; }
.button:hover { transform: translateY(-1px); }
.button.secondary { border: 1px solid var(--line-strong); background: white; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.danger { background: var(--red); color: white; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.builder-layout { min-height: calc(100vh - 70px); display: grid; grid-template-columns: 285px minmax(500px, 1fr) 405px; }
.outline-panel, .preview-panel { position: sticky; top: 70px; height: calc(100vh - 70px); min-height: 0; overflow: hidden; }
.outline-panel { padding: 24px 15px 18px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #f9f7f2; }
.panel-heading { padding: 0 7px 18px; display: flex; align-items: center; justify-content: space-between; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; }
.panel-heading h1, .preview-heading h2, .editor-header h1, .builder-modal h2 { margin: 0; font-family: Manrope, sans-serif; letter-spacing: -.025em; }
.panel-heading h1 { font-size: 18px; }
.outline-tabs { margin: 0 5px 14px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border-radius: 10px; background: #efede7; }
.outline-tabs button, .preview-tabs button { min-height: 34px; padding: 0 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 700; }
.outline-tabs button.active, .preview-tabs button.active { background: white; color: var(--ink); box-shadow: 0 3px 12px rgba(31,41,35,.06); }
.outline-tabs span, .preview-tabs span { margin-left: 4px; color: var(--faint); }
#journeyOutline, #rebuttalOutline { min-height: 0; flex: 1; display: flex; flex-direction: column; }
.outline-list { min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 6px; padding: 0 4px 10px; }
.stage-group { border-radius: 11px; }
.outline-item { width: 100%; min-height: 54px; padding: 9px 10px; display: grid; grid-template-columns: 26px minmax(0,1fr) auto; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; }
.outline-item:hover { background: white; }
.outline-item.active { border-color: rgba(20,107,72,.35); background: white; box-shadow: 0 6px 18px rgba(31,41,35,.05); }
.outline-number { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; background: #eceae4; color: var(--muted); font-size: 9px; font-weight: 700; }
.outline-item.active .outline-number { background: var(--green-soft); color: var(--green-dark); }
.outline-copy { min-width: 0; }
.outline-copy strong, .outline-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outline-copy strong { font-size: 11px; }
.outline-copy small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.outline-count { color: var(--faint); font-size: 9px; }
.step-list { margin: 2px 0 7px 35px; display: grid; gap: 3px; }
.step-outline-item { width: 100%; min-height: 38px; padding: 7px 8px; display: grid; grid-template-columns: 24px minmax(0,1fr); gap: 7px; align-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.step-outline-item:hover, .step-outline-item.active { background: white; color: var(--ink); }
.step-outline-item span:first-child { font-size: 8px; font-weight: 700; }
.step-outline-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.add-step-inline { margin: 2px 0 8px 38px; padding: 5px 8px; border: 0; background: transparent; color: var(--green); cursor: pointer; font-size: 9px; font-weight: 700; text-align: left; }
.add-outline-button { min-height: 39px; margin: 6px 5px 0; border: 1px dashed #aeb8af; border-radius: 9px; background: transparent; color: var(--green); cursor: pointer; font-size: 10px; font-weight: 700; }
.add-outline-button:hover { border-color: var(--green); background: var(--green-soft); }
.outline-footer { margin: 14px 5px 0; padding-top: 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); }
.outline-footer p { margin: 0; color: var(--muted); font-size: 9px; }
.text-button { padding: 5px 0; border: 0; background: transparent; color: var(--green); cursor: pointer; font-size: 10px; font-weight: 700; }

.editor-panel { min-width: 0; background: var(--surface); }
.editor-scroll { max-width: 900px; min-height: calc(100vh - 70px); margin: 0 auto; padding: 36px clamp(28px,4vw,64px) 80px; animation: editorIn .2s ease both; }
.editor-header { margin-bottom: 27px; display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.editor-header h1 { font-size: 25px; }
.editor-header p:not(.eyebrow) { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.editor-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.small-button { min-height: 33px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: white; cursor: pointer; color: var(--muted); font-size: 9px; font-weight: 700; }
.small-button:hover { border-color: var(--green); color: var(--green); }
.small-button.danger { color: var(--red); }
.editor-section { margin-top: 28px; padding-top: 23px; border-top: 1px solid var(--line); }
.section-heading { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.section-heading h2 { margin: 0; font-family: Manrope,sans-serif; font-size: 16px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.field-grid.one { grid-template-columns: 1fr; }
.field-grid.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
.field { min-width: 0; display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field > span { color: var(--muted); font-size: 10px; font-weight: 700; }
.field small { color: var(--faint); font-size: 8px; line-height: 1.4; }
.field input, .field textarea, .field select { width: 100%; min-width: 0; border: 1px solid var(--line-strong); border-radius: 9px; background: white; outline: none; color: var(--ink); }
.field input, .field select { height: 42px; padding: 0 11px; }
.project-switcher select, .field select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='m1 1 4 4 4-4' stroke='%236f776f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px 6px;
  cursor: pointer;
}
.field textarea { min-height: 105px; padding: 11px; resize: vertical; line-height: 1.55; }
.field textarea.body-field { min-height: 220px; font-size: 15px; }
.project-switcher select:focus, .field input:focus, .field textarea:focus, .field select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20,107,72,.08); }
.readonly-id { height: 42px; padding: 0 11px; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: #f5f4ef; color: var(--muted); font: 10px/1 ui-monospace,SFMono-Regular,Menlo,monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-check { min-height: 42px; padding: 0 11px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 9px; background: #faf9f5; color: var(--muted); font-size: 10px; font-weight: 600; }
.inline-check input { width: 15px; height: 15px; accent-color: var(--green); }
.stage-checkboxes { display: flex; flex-wrap: wrap; gap: 7px; }
.stage-checkboxes label { padding: 7px 9px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--muted); font-size: 9px; cursor: pointer; }
.stage-checkboxes input { accent-color: var(--green); }
.action-list { display: grid; gap: 9px; }
.action-editor { padding: 12px; display: grid; grid-template-columns: minmax(110px,.8fr) 130px minmax(180px,1.3fr) auto; align-items: end; gap: 9px; border: 1px solid var(--line); border-radius: 11px; background: #fbfaf6; }
.action-editor .field { gap: 5px; }
.action-editor .field > span { font-size: 8px; }
.icon-remove { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--red); cursor: pointer; font-size: 17px; }
.empty-state { padding: 42px 20px; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); text-align: center; font-size: 11px; }

.preview-panel { padding: 24px 20px 25px; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: #f8f6f1; }
.preview-heading { margin-bottom: 16px; display: flex; align-items: end; justify-content: space-between; gap: 13px; }
.preview-heading h2 { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.preview-tabs { padding: 3px; display: flex; gap: 2px; border-radius: 9px; background: #eceae4; }
.preview-tabs button { min-height: 30px; padding: 0 8px; }
.preview-body, .checks-body { min-height: 0; overflow-y: auto; flex: 1; }
.agent-preview { min-height: 610px; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; animation: previewIn .22s ease both; }
.agent-preview-header { padding: 21px 22px 18px; border-bottom: 1px solid var(--line); }
.agent-preview-header .stage { margin: 0 0 5px; color: var(--green); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.agent-preview-header h3 { margin: 0; font-family: Manrope,sans-serif; font-size: 20px; letter-spacing: -.02em; }
.agent-preview-content { padding: 28px 24px; flex: 1; }
.agent-preview-content .instruction { margin: 0 0 14px; color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.agent-preview-copy { color: #263129; font-size: 21px; line-height: 1.5; letter-spacing: -.02em; white-space: pre-wrap; }
.preview-callout { margin-top: 24px; padding: 12px 13px; border-left: 2px solid #d2a768; background: #fbf5e9; color: #735a37; font-size: 10px; line-height: 1.45; }
.preview-callout.warning { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.agent-preview-actions { padding: 17px 20px; border-top: 1px solid var(--line); background: #fbfaf6; }
.agent-preview-actions > p { margin: 0 0 9px; color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.preview-action-list { display: grid; gap: 7px; }
.preview-action { min-height: 43px; padding: 0 11px 0 13px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line-strong); border-radius: 9px; background: white; font-size: 10px; font-weight: 700; }
.preview-action.primary { border-color: var(--green); background: var(--green); color: white; }
.preview-action small { opacity: .7; }
.journey-preview { margin-bottom: 12px; display: flex; gap: 5px; overflow-x: auto; }
.journey-preview span { min-width: max-content; padding: 6px 8px; border-radius: 99px; background: #eae8e1; color: var(--muted); font-size: 8px; font-weight: 700; }
.journey-preview span.active { background: var(--green-soft); color: var(--green-dark); }
.rebuttal-preview { min-height: 520px; padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: var(--shadow); }
.rebuttal-preview-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.rebuttal-preview-header h3 { margin: 0; font-family: Manrope,sans-serif; font-size: 20px; }
.phase-chip { flex: 0 0 auto; padding: 6px 9px; border-radius: 99px; background: var(--amber-soft); color: var(--amber); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.rebuttal-preview .body { margin-top: 30px; color: #303a33; font-size: 15px; line-height: 1.65; white-space: pre-wrap; }
.rebuttal-preview .preview-action-list { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.check-summary { margin-bottom: 13px; padding: 16px; border-radius: 11px; background: white; border: 1px solid var(--line); }
.check-summary.ready { background: var(--green-soft); border-color: rgba(20,107,72,.25); }
.check-summary h3 { margin: 0; font-size: 13px; }
.check-summary p { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.check-list { display: grid; gap: 7px; }
.check-item { padding: 11px 12px; display: flex; gap: 9px; border-radius: 9px; background: white; border: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.4; }
.check-item.error { border-color: rgba(152,70,62,.25); color: var(--red); }
.check-item.warning { border-color: rgba(152,98,36,.25); color: var(--amber); }

.builder-modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 20px; display: grid; place-items: center; background: rgba(20,28,23,.45); backdrop-filter: blur(6px); }
.builder-modal { width: min(430px,100%); padding: 28px; border-radius: 18px; background: var(--surface); box-shadow: 0 30px 90px rgba(20,28,23,.22); text-align: center; }
.builder-modal h2 { font-size: 22px; }
.builder-modal > p:not(.eyebrow) { color: var(--muted); font-size: 11px; line-height: 1.55; }
.modal-actions { margin-top: 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.builder-toast { position: fixed; left: 50%; bottom: 22px; z-index: 150; padding: 10px 15px; border-radius: 9px; background: var(--ink); color: white; font-size: 11px; font-weight: 700; opacity: 0; pointer-events: none; transform: translate(-50%,12px); transition: opacity .2s,transform .2s; }
.builder-toast.show { opacity: 1; transform: translate(-50%,0); }

@keyframes editorIn { from { opacity: 0; transform: translateY(5px); } }
@keyframes previewIn { from { opacity: 0; transform: translateY(4px); } }

@media (max-width: 1250px) {
  .builder-layout { grid-template-columns: 250px minmax(460px,1fr) 350px; }
  .builder-topbar { grid-template-columns: 220px minmax(220px,1fr) auto; }
  .builder-top-actions .button.secondary:first-child { display: none; }
  .action-editor { grid-template-columns: 1fr 130px; }
  .action-editor .field:nth-child(3) { grid-column: 1 / -1; }
}

@media (max-width: 980px) {
  .builder-topbar { grid-template-columns: 190px minmax(0,1fr) auto; }
  .save-state, .builder-top-actions .button.secondary { display: none; }
  .builder-layout { grid-template-columns: 235px minmax(0,1fr); }
  .preview-panel { position: fixed; z-index: 25; top: 70px; right: 0; width: min(390px,calc(100vw - 235px)); transform: translateX(calc(100% - 48px)); transition: transform .22s ease; box-shadow: -14px 0 35px rgba(31,41,35,.1); }
  .preview-panel:hover, .preview-panel:focus-within { transform: translateX(0); }
  .editor-scroll { padding-right: 70px; }
}

@media (max-width: 680px) {
  .builder-topbar { height: auto; min-height: 64px; padding: 10px 12px; grid-template-columns: 1fr auto; }
  .builder-brand em { display: none; }
  .project-switcher { grid-column: 1 / -1; grid-row: 2; justify-content: stretch; }
  .project-switcher label { display: none; }
  .project-switcher select { width: 100%; }
  .builder-top-actions .button.primary { min-height: 38px; padding: 0 11px; }
  .builder-layout { display: block; min-height: calc(100vh - 112px); }
  .outline-panel { position: static; width: 100%; height: auto; max-height: 310px; border-right: 0; border-bottom: 1px solid var(--line); }
  .outline-list { max-height: 155px; }
  .editor-scroll { min-height: auto; padding: 24px 15px 110px; }
  .editor-header { flex-direction: column; }
  .editor-actions { justify-content: flex-start; }
  .field-grid, .field-grid.three { grid-template-columns: 1fr; }
  .action-editor { grid-template-columns: 1fr; }
  .action-editor .field:nth-child(3) { grid-column: auto; }
  .preview-panel { top: auto; bottom: 0; width: 100%; height: 62vh; padding: 15px; transform: translateY(calc(100% - 54px)); box-shadow: 0 -14px 35px rgba(31,41,35,.12); }
  .preview-panel:hover, .preview-panel:focus-within { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
