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

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --panel-muted: #f9fafb;
  --panel-deep: #f0f2f5;
  --rail: #0a0a0a;
  --rail-soft: #151515;
  --text: #111827;
  --muted: #6b7280;
  --soft: #9ca3af;
  --line: #e5e7eb;
  --line-soft: #eef0f3;
  --accent: #ff002f;
  --accent-dark: #df0029;
  --blue: #1d4ed8;
  --blue-soft: rgba(29, 78, 216, 0.08);
  --green: #087f5b;
  --green-soft: rgba(8, 127, 91, 0.1);
  --amber: #9f6400;
  --amber-soft: rgba(159, 100, 0, 0.1);
  --danger: #bd2d2d;
  --danger-soft: rgba(189, 45, 45, 0.1);
  --input: #ffffff;
  --preview: #ffffff;
  --result-bg: #111418;
  --result-text: #edf1f5;
  --shadow: 0 14px 36px rgba(17, 24, 39, 0.07);
  --radius: 8px;
  color-scheme: light;
}

html.dark {
  --bg: #0f0f0f;
  --panel: #141414;
  --panel-strong: #1a1a1a;
  --panel-muted: #181818;
  --panel-deep: #101010;
  --rail: #0a0a0a;
  --rail-soft: #101010;
  --text: #f9fafb;
  --muted: #9ca3af;
  --soft: #737780;
  --line: rgba(255, 255, 255, 0.1);
  --line-soft: rgba(255, 255, 255, 0.07);
  --blue: #8ab4ff;
  --blue-soft: rgba(138, 180, 255, 0.12);
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, 0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.13);
  --input: #101010;
  --preview: #181818;
  --result-bg: #09090b;
  --result-text: #f4f4f5;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.app-shell {
  display: grid;
  grid-template-columns: 306px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.task-rail {
  min-width: 0;
  background: var(--rail);
  color: #f7f8fa;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
}

.rail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.rail-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.rail-title { font-size: 15px; font-weight: 750; }
.rail-subtitle { margin-top: 2px; color: #a9b0bb; font-size: 12px; }

.task-list {
  padding: 10px;
  overflow: auto;
  max-height: calc(100vh - 72px);
}

.task-item {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  text-align: left;
}
.task-item:hover { background: rgba(255,255,255,0.06); }
.task-item.active { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.12); }
.task-item-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.task-name, .task-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-name { font-size: 13px; font-weight: 700; }
.task-meta { color: #a9b0bb; font-size: 11px; }
.task-status { color: #cdd3dc; font-size: 11px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--soft);
}
.status-dot.running { background: #f0c84b; box-shadow: 0 0 0 4px rgba(240,200,75,0.12); }
.status-dot.completed { background: #22b07d; }
.status-dot.failed { background: #e15d55; }
.status-dot.queued { background: #8aa3c9; }

.workspace {
  min-width: 0;
  padding: 18px;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.08; color: var(--text); }

.health-strip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.health {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.health span { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.health.ok { color: var(--green); }
.health.warn { color: var(--amber); }

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-muted);
}
.tab-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.tab-button.active { background: var(--panel-strong); color: var(--text); box-shadow: 0 1px 5px rgba(0,0,0,0.08); }
html.dark .tab-button.active { border: 1px solid var(--line-soft); box-shadow: none; }

.create-grid {
  display: grid;
  grid-template-columns: minmax(620px, 1.35fr) minmax(380px, 0.65fr);
  gap: 14px;
  align-items: start;
}
.side-stack { display: grid; gap: 14px; min-width: 0; }
.preview-grid {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.scope-panel, .brief-panel, .detail-panel, .preview-control-panel, .ads-panel { padding: 16px; }
.detail-panel { min-height: 360px; }
.compact-detail { min-height: 0; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 17px; line-height: 1.2; color: var(--text); }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.scope-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.scope-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel-muted);
  min-height: 520px;
}
.scope-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.scope-column-head strong { font-size: 13px; color: var(--text); }
.scope-column-head span {
  min-width: 24px;
  min-height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  border: 1px solid var(--line-soft);
}
.scope-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--input);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
  min-height: 38px;
  font-size: 13px;
}
.scope-search.wide { margin-bottom: 10px; }
.scope-search::placeholder { color: var(--soft); }
.scope-search:focus, input:focus, textarea:focus { border-color: rgba(255,0,47,0.55); box-shadow: 0 0 0 3px rgba(255,0,47,0.12); }
.scope-list {
  display: grid;
  gap: 7px;
  align-content: start;
  overflow: auto;
  max-height: 440px;
  padding-right: 2px;
}
.scope-card {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 66px;
  display: grid;
  gap: 5px;
  justify-items: start;
  align-content: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--text);
  text-align: left;
}
.scope-card:hover { border-color: rgba(255,0,47,0.35); }
.scope-card.active { border-color: rgba(255,0,47,0.55); box-shadow: inset 3px 0 0 var(--accent); }
.scope-card.selected { background: rgba(255,0,47,0.08); border-color: rgba(255,0,47,0.42); }
.scope-card-title {
  width: 100%;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 750;
  overflow-wrap: anywhere;
}
.scope-card-meta {
  width: 100%;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.campaign-card { padding-right: 58px; }
.campaign-kind {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 10px;
  font-weight: 850;
}
.campaign-card.selected .campaign-kind { background: var(--accent); color: #fff; }

.selected-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.selected-targets.full { margin: 0 0 14px; }
.empty-targets {
  min-height: 42px;
  align-items: center;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--panel-muted);
  font-size: 13px;
}
.target-chip {
  min-width: 210px;
  max-width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "kind main remove"
    "kind sub remove";
  align-items: center;
  gap: 2px 8px;
  padding: 8px 8px 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}
.target-kind {
  grid-area: kind;
  min-width: 38px;
  min-height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 10px;
  font-weight: 850;
}
.target-main {
  grid-area: main;
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.target-sub {
  grid-area: sub;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-remove {
  grid-area: remove;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-muted);
  color: var(--muted);
  font-weight: 800;
  line-height: 1;
}
.chip-remove:hover { color: var(--accent); border-color: rgba(255,0,47,0.35); }

.field-grid { display: grid; gap: 10px; margin-bottom: 10px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.compact { margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; min-width: 0; }
.field span { color: var(--muted); font-size: 12px; font-weight: 750; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--input);
  color: var(--text);
  padding: 10px 11px;
  outline: none;
  min-height: 40px;
}
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--soft); }

.control-row { display: grid; gap: 12px; margin: 12px 0; }
.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-muted);
}
.segment { position: relative; min-width: 0; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: grid;
  place-items: center;
  min-height: 32px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.segment.active span { background: var(--panel-strong); color: var(--text); box-shadow: 0 1px 5px rgba(0,0,0,0.08); }
html.dark .segment.active span { border: 1px solid var(--line-soft); box-shadow: none; }

.pill-block { display: grid; gap: 7px; }
.pill-title { color: var(--muted); font-size: 12px; font-weight: 800; }
.format-set { display: flex; flex-wrap: wrap; gap: 6px; }
.check-pill { position: relative; }
.check-pill input { position: absolute; opacity: 0; pointer-events: none; }
.check-pill span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.check-pill input:checked + span { border-color: rgba(255,0,47,0.35); color: var(--accent); background: rgba(255,0,47,0.08); }

.action-row, .task-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action-row { margin-top: 14px; }
.primary-button, .secondary-button, .ghost-button, .icon-button {
  border-radius: var(--radius);
  border: 1px solid transparent;
  min-height: 38px;
  padding: 0 13px;
  font-weight: 800;
  font-size: 13px;
}
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); }
.secondary-button { background: var(--panel-strong); color: var(--text); border-color: var(--line); }
.secondary-button:hover, .ghost-button:hover, .icon-button:hover { border-color: rgba(255,0,47,0.3); color: var(--accent); }
.ghost-button { background: var(--panel-muted); color: var(--text); border-color: var(--line); }
.icon-button { width: 34px; padding: 0; background: var(--panel-strong); border-color: var(--line); color: var(--text); }

.error-line, .toast-line, .warning-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 650;
}
.error-line { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(189,45,45,0.18); }
.toast-line { background: var(--green-soft); color: var(--green); border: 1px solid rgba(8,127,91,0.18); }
.warning-box { background: var(--amber-soft); color: var(--amber); border: 1px solid rgba(159,100,0,0.18); }

.preview-stack { display: grid; gap: 14px; }
.search-preview {
  max-width: 660px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--preview);
}
.ad-label { color: var(--muted); font-size: 13px; }
.ad-title { margin-top: 7px; color: var(--blue); font-size: 20px; line-height: 1.2; font-weight: 700; overflow-wrap: anywhere; }
.ad-url { margin-top: 5px; color: var(--green); font-size: 14px; overflow-wrap: anywhere; }
.ad-text { margin-top: 8px; color: var(--text); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.ad-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; color: var(--blue); font-size: 13px; }
.network-preview {
  width: min(100%, 520px);
  min-height: 210px;
  display: grid;
  grid-template-columns: 44% 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--preview);
}
.network-art { background: linear-gradient(135deg, #ff002f 0%, #1a1a1a 54%, #f9fafb 100%); }
html.dark .network-art { background: linear-gradient(135deg, #ff002f 0%, #2e2e2e 48%, #0a0a0a 100%); }
.network-copy { padding: 16px; display: flex; flex-direction: column; gap: 10px; justify-content: center; min-width: 0; }
.network-copy span { color: var(--muted); font-size: 12px; font-weight: 800; }
.network-copy strong { font-size: 19px; line-height: 1.15; color: var(--text); overflow-wrap: anywhere; }
.network-copy button { width: fit-content; min-height: 34px; padding: 0 12px; border: 0; border-radius: 7px; background: var(--text); color: var(--bg); font-weight: 800; }
html.dark .network-copy button { background: #f4f4f5; color: #09090b; }

.mode-badge, .status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.mode-badge { background: var(--blue-soft); color: var(--blue); }
.status-chip.queued { background: var(--blue-soft); color: var(--blue); }
.status-chip.running { background: var(--amber-soft); color: var(--amber); }
.status-chip.completed { background: var(--green-soft); color: var(--green); }
.status-chip.failed { background: var(--danger-soft); color: var(--danger); }

.context-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -2px 0 14px;
}
.context-strip span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--panel-muted);
  color: var(--muted);
  border: 1px solid var(--line-soft);
  font-size: 12px;
  font-weight: 700;
}
.result-box {
  width: 100%;
  max-height: 52vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--result-bg);
  color: var(--result-text);
  line-height: 1.5;
  font-size: 13px;
}
.result-box.prompt { background: var(--panel-strong); color: var(--text); }
.error-box { background: #3d1616; color: #ffe4e4; }

.timeline { margin-top: 14px; border-top: 1px solid var(--line-soft); }
.timeline-row {
  display: grid;
  grid-template-columns: 82px 120px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.timeline-row span { color: var(--soft); }
.timeline-row strong { color: var(--text); }
.timeline-row em { color: var(--muted); font-style: normal; overflow: hidden; text-overflow: ellipsis; }
.empty {
  border: 1px dashed rgba(255,255,255,0.16);
  border-radius: var(--radius);
  color: #a9b0bb;
  padding: 24px 14px;
  text-align: center;
  font-size: 13px;
}
.detail-panel .empty, .scope-column .empty, .ads-panel .empty, .preview-control-panel .empty {
  border-color: var(--line);
  color: var(--muted);
  background: var(--panel-strong);
}
.empty.small { padding: 16px 10px; }
.empty.tall { min-height: 180px; display: grid; place-items: center; }

.preview-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.preview-summary div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-muted);
}
.preview-summary strong { font-size: 22px; line-height: 1; color: var(--text); }
.preview-summary span { color: var(--muted); font-size: 11px; font-weight: 750; }

.ad-list {
  display: grid;
  gap: 9px;
  max-height: calc(100vh - 196px);
  overflow: auto;
  padding-right: 2px;
}
.ad-card {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--text);
  text-align: left;
}
.ad-card:hover { border-color: rgba(255,0,47,0.35); }
.ad-card.selected { border-color: rgba(255,0,47,0.45); background: rgba(255,0,47,0.07); }
.ad-check {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #fff;
  background: var(--panel-muted);
  font-size: 13px;
  font-weight: 900;
}
.ad-card.selected .ad-check { background: var(--accent); border-color: var(--accent); }
.ad-card-body { min-width: 0; display: grid; gap: 5px; }
.ad-card-top { display: flex; gap: 8px; align-items: center; justify-content: space-between; min-width: 0; }
.ad-card-top strong { color: var(--text); font-size: 12px; white-space: nowrap; }
.ad-card-top em { color: var(--muted); font-size: 11px; font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-card-title { color: var(--blue); font-size: 16px; line-height: 1.25; font-weight: 750; overflow-wrap: anywhere; }
.ad-card-text { color: var(--text); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.ad-card-meta { color: var(--green); font-size: 12px; overflow-wrap: anywhere; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }
html.dark ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }

@media (max-width: 1320px) {
  .create-grid { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .task-rail { min-height: auto; }
  .task-list { display: flex; gap: 8px; overflow-x: auto; max-height: none; }
  .task-item { min-width: 280px; }
  .preview-grid { grid-template-columns: 1fr; }
  .ad-list { max-height: none; }
}

@media (max-width: 940px) {
  .scope-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scope-column { min-height: 420px; }
  .side-stack { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .workspace { padding: 12px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  h1 { font-size: 24px; }
  .tabs { width: 100%; grid-template-columns: 1fr; }
  .field-grid.two, .scope-board, .preview-summary { grid-template-columns: 1fr; }
  .scope-column { min-height: 320px; }
  .network-preview { grid-template-columns: 1fr; }
  .network-art { min-height: 130px; }
  .timeline-row { grid-template-columns: 1fr; gap: 3px; }
  .ad-card-top { align-items: flex-start; flex-direction: column; gap: 2px; }
}

/* Agent workflow revision */
.create-stack {
  display: grid;
  gap: 14px;
  align-items: start;
}
.create-stack .scope-panel,
.create-stack .brief-panel,
.create-stack .agent-panel,
.create-stack .detail-panel {
  width: 100%;
}
.agent-panel {
  min-height: 0;
}
.agent-dialog {
  display: grid;
  gap: 12px;
  max-height: 68vh;
  overflow: auto;
  padding: 4px 2px 4px 0;
}
.dialog-message {
  width: min(100%, 980px);
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}
.dialog-message.assistant {
  justify-self: start;
  border-left: 3px solid var(--accent);
}
.dialog-message.user {
  justify-self: end;
  max-width: min(100%, 760px);
  background: var(--blue-soft);
  border-color: rgba(29, 78, 216, 0.2);
}
.dialog-message.error {
  background: var(--danger-soft);
  border-color: rgba(189,45,45,0.18);
}
.dialog-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}
.dialog-message pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  font-family: inherit;
}
.reply-box {
  display: grid;
  gap: 9px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-muted);
}
.reply-box textarea {
  min-height: 104px;
  background: var(--panel-strong);
}
.reply-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.reply-actions span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.timeline-details {
  margin-top: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
}
.timeline-details summary {
  cursor: pointer;
  padding: 10px 0 0;
  font-size: 12px;
  font-weight: 850;
}
.timeline-details[open] summary {
  margin-bottom: 4px;
}
.empty-dialog {
  max-height: none;
}

@media (max-width: 1320px) {
  .create-stack { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .agent-dialog { max-height: none; }
  .dialog-message.user { max-width: 100%; }
  .reply-actions { align-items: stretch; flex-direction: column; }
  .reply-actions .primary-button { width: 100%; }
}


/* Task readiness and markdown chat */
.status-dot.draft { background: #8aa3c9; }
.status-dot.answered { background: #f0c84b; box-shadow: 0 0 0 4px rgba(240,200,75,0.12); }
.status-dot.ready { background: #22b07d; }
.status-dot.created { background: #087f5b; box-shadow: 0 0 0 4px rgba(8,127,91,0.12); }
.status-chip.draft { background: var(--blue-soft); color: var(--blue); }
.status-chip.answered { background: var(--amber-soft); color: var(--amber); }
.status-chip.ready, .status-chip.created { background: var(--green-soft); color: var(--green); }

.account-target-card {
  padding-right: 58px;
  border-style: dashed;
}
.account-target-card .campaign-kind {
  background: var(--green-soft);
  color: var(--green);
}
.account-target-card.selected {
  border-style: solid;
  background: rgba(8,127,91,0.08);
  border-color: rgba(8,127,91,0.35);
}
.account-target-card.selected .campaign-kind { background: var(--green); color: #fff; }

.readiness-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-muted);
}
.readiness-panel strong {
  display: block;
  margin-bottom: 3px;
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
}
.readiness-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.readiness-panel.answered {
  border-color: rgba(159,100,0,0.22);
  background: var(--amber-soft);
}
.readiness-panel.ready, .readiness-panel.created {
  border-color: rgba(8,127,91,0.24);
  background: var(--green-soft);
}
.readiness-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.markdown-body {
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.58;
  overflow-wrap: anywhere;
}
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 10px; }
.markdown-body h3, .markdown-body h4, .markdown-body h5 {
  margin: 14px 0 7px;
  color: var(--text);
  line-height: 1.25;
}
.markdown-body h3 { font-size: 16px; }
.markdown-body h4 { font-size: 15px; }
.markdown-body h5 { font-size: 14px; }
.markdown-body ul, .markdown-body ol {
  margin: 0 0 10px 18px;
  padding: 0;
}
.markdown-body li { margin: 3px 0; }
.markdown-body code {
  padding: 1px 5px;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  background: var(--panel-muted);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}
.markdown-body a { color: var(--blue); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.md-table-wrap {
  width: 100%;
  overflow: auto;
  margin: 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}
.markdown-body table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 12px;
}
.markdown-body th, .markdown-body td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}
.markdown-body th:last-child, .markdown-body td:last-child { border-right: 0; }
.markdown-body tr:last-child td { border-bottom: 0; }
.markdown-body th {
  position: sticky;
  top: 0;
  background: var(--panel-muted);
  color: var(--text);
  font-weight: 850;
}
.md-code {
  margin: 8px 0 12px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--result-bg);
  color: var(--result-text);
  line-height: 1.5;
}
.md-code code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}
.dialog-message.user .markdown-body { font-weight: 650; }
.dialog-message.error .markdown-body { color: var(--danger); }

@media (max-width: 680px) {
  .readiness-panel { align-items: stretch; flex-direction: column; }
  .readiness-actions { justify-content: stretch; }
  .readiness-actions button { width: 100%; }
  .markdown-body table { min-width: 620px; }
}
