:root {
  --bg: #080d1a;
  --panel: #0f172a;
  --card: #131c31;
  --border: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --emerald: #10b981;
  --indigo: #6366f1;
  --amber: #f59e0b;
  --rose: #f43f5e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

code, pre { font-family: 'JetBrains Mono', monospace; }

/* Topbar */
.topbar {
  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}

.topbar-inner {
  width: min(1440px, 96%);
  margin: 0 auto;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-group { display: flex; align-items: center; gap: 10px; }
.pulse-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--emerald); box-shadow: 0 0 12px var(--emerald);
}
.brand-name { font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.74rem; color: var(--muted); }

.spec-links { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spec-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
  text-decoration: none;
}
.spec-pill:hover { border-color: var(--emerald); color: #fff; }
.status-pill {
  font-size: 0.72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: rgba(16, 185, 129, 0.15); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.4);
}

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 15px; border-radius: 8px; font-weight: 600; font-size: 0.85rem;
  border: 1px solid transparent; cursor: pointer; transition: 0.15s ease;
}
.btn-sm { padding: 6px 11px; font-size: 0.79rem; }
.btn-primary { background: var(--emerald); color: #042f1a; }
.btn-primary:hover { background: #34d399; }
.btn-outline { background: rgba(255,255,255,0.03); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--emerald); }

/* Dual Pane Layout */
.workspace {
  width: min(1440px, 96%);
  margin: 18px auto 34px;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  align-items: start;
}

.pane {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.pane-head h2 { font-size: 1.08rem; font-weight: 800; }
.head-btns { display: flex; gap: 8px; }

.workbench-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.card h3 { font-size: 0.92rem; margin-bottom: 10px; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-top h3 { margin-bottom: 0; }

.ctrl { margin-bottom: 10px; }
.ctrl label { display: flex; justify-content: space-between; font-size: 0.78rem; color: #cbd5e1; margin-bottom: 4px; font-weight: 600; }
.ctrl input[type="range"] { width: 100%; accent-color: var(--emerald); }
.ctrl select, .ctrl input[type="number"] {
  width: 100%; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: #0b1120; color: var(--text); font-size: 0.82rem;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.align-end { align-items: end; }
.checks { display: flex; flex-direction: column; gap: 5px; font-size: 0.78rem; color: #cbd5e1; }
.chk { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { accent-color: var(--emerald); }

/* SVG & Safety */
.blueprint-svg {
  width: 100%; height: 210px; background: #090e1a; border-radius: 10px;
  border: 1px solid var(--border); display: block;
}
.safety-badge {
  font-size: 0.72rem; font-weight: 800; padding: 3px 9px; border-radius: 999px;
}
.safety-badge.pass { background: rgba(16,185,129,0.18); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.4); }
.safety-badge.warn { background: rgba(244,63,94,0.18); color: #fda4af; border: 1px solid rgba(244,63,94,0.45); }
.safety-detail { margin-top: 8px; font-size: 0.78rem; color: #cbd5e1; }

/* Cut-List Bars */
.muted-meta { font-size: 0.76rem; color: var(--muted); }
.cut-bars { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 0.76rem; }
.bar-lbl { width: 58px; color: var(--muted); font-weight: 700; flex-shrink: 0; }
.bar-track {
  flex: 1; height: 24px; background: #090e1a; border: 1px solid var(--border);
  border-radius: 6px; display: flex; overflow: hidden;
}
.cut-seg {
  height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 700; color: #042f1a; border-right: 2px solid #090e1a;
  overflow: hidden; white-space: nowrap;
}
.seg-leg { background: #34d399; }
.seg-long { background: #818cf8; color: #fff; }
.seg-cross { background: #fbbf24; }
.cut-scrap {
  height: 100%; background: rgba(148,163,184,0.12); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 0.66rem;
}

/* BOM Table */
.bom-totals { text-align: right; }
.bom-totals strong { display: block; font-size: 1.05rem; color: var(--emerald); }
.table-wrap { max-height: 200px; overflow-y: auto; }
.bom-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.bom-table th, .bom-table td { padding: 7px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.bom-table th:last-child, .bom-table td:last-child { text-align: right; }
.bom-table th { color: var(--muted); font-size: 0.74rem; }

.rfq-box {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.4);
  font-size: 0.76rem; color: #a7f3d0; word-break: break-all;
}

/* Agent Console */
.agent-pane { position: sticky; top: 76px; }
.mode-badge { font-size: 0.72rem; color: #a5b4fc; }
.step-pill {
  font-family: 'JetBrains Mono', monospace; font-size: 0.74rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; background: #1e293b; border: 1px solid var(--border);
}

.samples-bar { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.samples-lbl { font-size: 0.74rem; color: var(--muted); margin-bottom: 7px; font-weight: 600; }
.sample-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.sample-btn {
  background: rgba(99,102,241,0.14); border: 1px solid rgba(99,102,241,0.35); color: #e0e7ff;
  border-radius: 8px; padding: 5px 9px; font-size: 0.73rem; cursor: pointer; text-align: left;
}
.sample-btn:hover { border-color: var(--emerald); color: #fff; }

.chat-feed {
  background: #090e1a; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; min-height: 220px; max-height: 280px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { padding: 9px 12px; border-radius: 10px; font-size: 0.82rem; white-space: pre-wrap; }
.msg.user { background: rgba(99,102,241,0.2); border: 1px solid rgba(99,102,241,0.35); align-self: flex-end; max-width: 90%; }
.msg.agent { background: var(--card); border: 1px solid var(--border); align-self: stretch; }

.trace-panel { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.trace-head { display: flex; justify-content: space-between; font-size: 0.76rem; font-weight: 700; margin-bottom: 8px; }
.trace-list { display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow-y: auto; }
.trace-empty { font-size: 0.75rem; color: var(--muted); }
.trace-item {
  font-size: 0.73rem; padding: 6px 8px; border-radius: 7px; background: #090e1a;
  border-left: 3px solid var(--emerald); display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.eff-badge { font-family: 'JetBrains Mono', monospace; font-size: 0.66rem; padding: 2px 6px; border-radius: 4px; font-weight: 700; }
.eff-read { background: rgba(59,130,246,0.2); color: #93c5fd; }
.eff-write { background: rgba(245,158,11,0.2); color: #fcd34d; }
.eff-irreversible { background: rgba(244,63,94,0.25); color: #fda4af; }

.agent-input-bar { display: flex; gap: 8px; }
.agent-input-bar input {
  flex: 1; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: #090e1a; color: var(--text); font-size: 0.84rem;
}
.agent-input-bar input:focus { outline: none; border-color: var(--emerald); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.78); backdrop-filter: blur(4px);
  z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: min(520px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 12px;
}
.confirm-card { border-color: var(--rose); }
.warn-pill {
  align-self: flex-start; font-size: 0.7rem; font-weight: 800; padding: 4px 10px; border-radius: 999px;
  background: rgba(244,63,94,0.18); color: #fda4af; border: 1px solid var(--rose);
}
.modal-sub { font-size: 0.82rem; color: var(--muted); }
.m-lbl { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; font-weight: 600; color: #cbd5e1; }
.m-inp {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: #090e1a; color: var(--text); font-size: 0.82rem;
}
.peer-row { display: flex; gap: 8px; }
.peer-pre {
  background: #090e1a; border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  font-size: 0.73rem; color: #cbd5e1; max-height: 200px; overflow: auto; white-space: pre-wrap;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .agent-pane { position: static; }
}
@media (max-width: 680px) {
  .workbench-grid, .row-2 { grid-template-columns: 1fr; }
}
