:root {
  --bg-dark: #090d16;
  --bg-panel: #111827;
  --bg-card: #1a2333;
  --bg-input: #0d1422;
  --border: #26334d;
  --text-main: #f3f6fc;
  --text-muted: #94a3b8;
  --emerald: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --cyan: #06b6d4;
  --purple: #a855f7;
  --indigo: #6366f1;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at 15% 0%, #152238 0%, var(--bg-dark) 65%);
  color: var(--text-main);
  min-height: 100vh;
  padding: 18px 24px 36px;
  line-height: 1.45;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 20px;
  margin-bottom: 16px;
  backdrop-filter: blur(12px);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.shield-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.3);
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-hf {
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-open {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.engine-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.engine-selector select {
  background: transparent;
  color: var(--text-main);
  border: none;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.engine-selector select option {
  background: var(--bg-panel);
  color: var(--text-main);
}

/* KPI Ribbon */
.kpi-ribbon {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
}

.kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 800;
  margin: 4px 0 2px;
  font-family: 'JetBrains Mono', monospace;
}

.kpi-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.text-emerald { color: #34d399; }
.text-amber { color: #fbbf24; }
.text-cyan { color: #22d3ee; }
.text-purple { color: #c084fc; }

/* Main Grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 1.05fr 1.15fr 1.05fr;
  gap: 16px;
}

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

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.panel-header h2 {
  font-size: 1.02rem;
  font-weight: 700;
}

.panel-subtitle {
  font-size: 0.77rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  background: rgba(99, 102, 241, 0.16);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.pill-privacy {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}

.pill-tabpfn {
  background: rgba(6, 182, 212, 0.16);
  color: #22d3ee;
  border-color: rgba(6, 182, 212, 0.35);
}

/* Scenario Chips */
.scenario-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.scenario-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 2px;
}

.chip {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover, .chip.active {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border-color: #10b981;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-row label {
  font-size: 0.79rem;
  font-weight: 600;
  color: #e2e8f0;
}

.mono-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  padding: 2px 7px;
  border-radius: 5px;
}

textarea, input, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 9px;
  padding: 10px 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.77rem;
  line-height: 1.45;
  resize: vertical;
}

textarea:focus, input:focus {
  outline: none;
  border-color: #10b981;
}

.rate-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
}

.rate-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rate-field label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 0.81rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #04130d;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.25);
}

.btn-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #180e00;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-full {
  width: 100%;
  padding: 11px;
}

.btn-xs {
  padding: 5px 10px;
  font-size: 0.73rem;
}

/* Delta Cards */
.delta-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.delta-card {
  background: var(--bg-card);
  border-left: 4px solid var(--amber);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 0.78rem;
}

.delta-card.in-scope {
  border-left-color: var(--emerald);
}

.delta-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 4px;
}

.delta-cost {
  font-family: 'JetBrains Mono', monospace;
  color: #fbbf24;
  font-weight: 700;
}

.delta-card.in-scope .delta-cost {
  color: #34d399;
}

.delta-reason {
  color: var(--text-muted);
  font-size: 0.74rem;
}

/* Change Order Box */
.change-order-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.co-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.co-header h3 {
  font-size: 0.86rem;
  font-weight: 700;
}

.co-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.co-actions {
  display: flex;
  gap: 6px;
}

/* Telemetry Box */
.telemetry-box {
  background: #070b12;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
}

.telemetry-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.trace-pre {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: #34d399;
  white-space: pre-wrap;
  max-height: 92px;
  overflow-y: auto;
}

/* Canvas & TabPFN Table */
.canvas-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.canvas-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 4px;
}

.legend-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-emerald { background: #10b981; }
.dot-red { background: #ef4444; }

canvas {
  width: 100%;
  height: auto;
  display: block;
}

.tabular-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tabular-header h3 {
  font-size: 0.84rem;
  font-weight: 700;
}

.table-scroll {
  max-height: 185px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}

.invoice-table th, .invoice-table td {
  padding: 7px 9px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.invoice-table th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.risk-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.69rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
}

.risk-low { background: rgba(16, 185, 129, 0.16); color: #34d399; }
.risk-med { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.risk-high { background: rgba(239, 68, 68, 0.2); color: #f87171; }

.pricing-card {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(6, 182, 212, 0.1));
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 10px;
  padding: 11px 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pricing-left h4 {
  font-size: 0.84rem;
  margin: 4px 0 2px;
}

.pricing-left p {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.roi-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 800;
  color: #34d399;
  background: rgba(16, 185, 129, 0.18);
  padding: 8px 12px;
  border-radius: 10px;
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .kpi-ribbon {
    grid-template-columns: repeat(2, 1fr);
  }
}
