:root {
  --bg-primary: #0f1117;
  --bg-secondary: #121725;
  --bg-card: #1a1d27;
  --bg-card-hover: #1f2235;
  --border: #2a2d3e;
  --text-primary: #e2e8f0;
  --text-muted: #64748b;
  --accent-blue: #3b82f6;
  --accent-teal: #14b8a6;
  --accent-green: #22c55e;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text-primary);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at 12% 0%, #162341 0%, var(--bg-primary) 45%);
}

.page-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(to bottom, rgba(59, 130, 246, 0.06), rgba(20, 184, 166, 0));
}

.container {
  position: relative;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: linear-gradient(145deg, rgba(26, 29, 39, 0.95), rgba(18, 23, 37, 0.95));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.card:hover {
  border-color: #345087;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  background: linear-gradient(130deg, rgba(59, 130, 246, 0.2), rgba(20, 184, 166, 0.2));
  border: 1px solid #2b4d8a;
}

.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.brand h1 {
  margin: 4px 0 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

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

.inline-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

select,
button {
  background: #101827;
  border: 1px solid #314368;
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit;
}

button {
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  border-color: var(--accent-blue);
}

.status-stack {
  display: grid;
  gap: 2px;
  min-width: 180px;
  font-size: 12px;
  color: var(--text-muted);
}

.api-source {
  margin: 10px 2px 22px;
  color: var(--text-muted);
  font-size: 12px;
}

section {
  margin-bottom: 18px;
}

.section-title {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8fa7ce;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.metric-card h3 {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-value {
  margin: 0;
  font-size: clamp(1.5rem, 1.1rem + 1.2vw, 2rem);
  font-weight: 800;
}

.metric-sub {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.pipeline-funnel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pipeline-stage {
  min-width: 120px;
  flex: 1;
  position: relative;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, #151b2d, #101523);
  cursor: pointer;
}

.pipeline-stage .label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #97a6bf;
}

.pipeline-stage .count {
  margin: 8px 0 0;
  font-size: 26px;
  font-weight: 700;
}

.pipeline-stage .rate {
  margin: 6px 0 0;
  font-size: 12px;
  color: #8aa2cd;
}

.stage-draft {
  border-color: #3f4a60;
}

.stage-sent {
  border-color: #2f58a3;
}

.stage-opened {
  border-color: #2874b8;
}

.stage-clicked {
  border-color: #2187a4;
}

.stage-replied {
  border-color: #1d9a86;
}

.stage-meeting {
  border-color: #2da166;
}

.split-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.status-badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.badge-healthy {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.badge-critical {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.progress-wrap {
  margin-bottom: 12px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: #101626;
  border: 1px solid #253454;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 0.35s ease;
}

.progress-fill-blue {
  background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.progress-fill-teal {
  background: linear-gradient(90deg, #0d9488, #2dd4bf);
}

.progress-fill-green {
  background: linear-gradient(90deg, #16a34a, #4ade80);
}

.progress-fill-amber {
  background: linear-gradient(90deg, #d97706, #f59e0b);
}

.with-threshold .threshold {
  position: absolute;
  top: -19px;
  transform: translateX(-50%);
  font-size: 10px;
  color: #8fa7ce;
}

.with-threshold .threshold::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 14px;
  width: 1px;
  height: 18px;
  background: rgba(143, 167, 206, 0.5);
}

.warmup-main {
  margin: 0 0 12px;
  font-size: 24px;
  font-weight: 700;
}

.detail-line {
  margin: 6px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8fa7ce;
  padding: 8px 10px;
  border-bottom: 1px solid #2f4168;
}

tbody td {
  padding: 10px;
  font-size: 14px;
  border-bottom: 1px solid rgba(47, 65, 104, 0.35);
}

tbody tr:hover {
  background: rgba(53, 83, 139, 0.12);
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.badge-active {
  color: var(--accent-green);
  background: rgba(34, 197, 94, 0.15);
}

.badge-inactive {
  color: #99a7c1;
  background: rgba(128, 138, 158, 0.16);
}

.badge-use {
  color: var(--accent-teal);
  background: rgba(20, 184, 166, 0.16);
}

.badge-idle {
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.14);
}

.n8n .pipeline-stage {
  min-width: 190px;
}

.n8n .pipeline-stage.active {
  border-color: #16a34a;
  background: linear-gradient(160deg, rgba(14, 76, 56, 0.55), rgba(13, 20, 30, 1));
}

.n8n .pipeline-stage.in-use {
  border-color: #2dd4bf;
  box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.3), inset 0 0 18px rgba(20, 184, 166, 0.18);
}

.n8n .pipeline-stage.idle {
  opacity: 0.74;
}

.attention-card {
  border-color: #734b1b;
}

.flag-group {
  margin-bottom: 14px;
}

.flag-group h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.flag-line {
  margin: 5px 0;
  color: #d0dae9;
  font-size: 13px;
}

/* ------------------------------------------------------------------ */
/* Action Centre                                                        */
/* ------------------------------------------------------------------ */

.action-centre-card {
  border-color: #2a3350;
}

.action-centre-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.action-centre-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ac-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 8px;
  border-left: 3px solid transparent;
}

.ac-red {
  background: rgba(239, 68, 68, 0.08);
  border-left-color: var(--accent-red);
}

.ac-amber {
  background: rgba(245, 158, 11, 0.07);
  border-left-color: var(--accent-amber);
}

.ac-green {
  background: rgba(34, 197, 94, 0.07);
  border-left-color: var(--accent-green);
}

.ac-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.5;
}

.ac-icon {
  flex-shrink: 0;
  font-size: 16px;
  margin-top: 1px;
}

.ac-text {
  color: #d0dae9;
}

.ac-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.ac-badge-red {
  background: rgba(239, 68, 68, 0.18);
  color: var(--accent-red);
}

.ac-badge-amber {
  background: rgba(245, 158, 11, 0.18);
  color: var(--accent-amber);
}

.ac-badge-green {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
}

/* Pipeline stage extras */
.stage-review {
  border-color: #4a5a7a;
}

.stage-approved {
  border-color: #1f6b3a;
}

.stage-parked {
  border-color: #3d3d5c;
  opacity: 0.75;
}

.mono {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.flag-quote {
  font-style: italic;
  color: #8fa7ce;
  padding-left: 12px;
}

.chart-container {
  position: relative;
  height: 180px;
}

.chart-container--tall {
  height: 260px;
}

.hidden {
  display: none;
}

/* ------------------------------------------------------------------ */
/* Pipeline RAG visual                                                  */
/* ------------------------------------------------------------------ */

.rag-card {
  padding: 18px 20px 20px;
}

.rag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.rag-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.rag-legend span + span {
  margin-right: 8px;
}

.rag-pip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rag-pip.state-live {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

.rag-pip.state-on {
  background: #3b82f6;
}

.rag-pip.state-off {
  background: #2f3650;
}

.rag-pip.state-manual {
  background: transparent;
  border: 2px dashed #f59e0b;
  width: 8px;
  height: 8px;
}

.rag-track {
  display: flex;
  align-items: center;
  overflow-x: auto;
  padding: 6px 0 4px;
  gap: 0;
  scrollbar-width: none;
}

.rag-track::-webkit-scrollbar {
  display: none;
}

.rag-node-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.rag-dot {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  letter-spacing: 0;
  transition: box-shadow 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.rag-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: center;
  line-height: 1.3;
  transition: color 0.3s ease;
  white-space: nowrap;
}

.rag-connector {
  flex: 1;
  min-width: 12px;
  max-width: 36px;
  height: 2px;
  border-radius: 1px;
  transition: background 0.3s ease;
  flex-shrink: 1;
  margin-bottom: 22px;
}

/* Node dot states */
.rag-dot.state-off {
  background: #131720;
  border-color: #2a2f46;
  color: #3a4460;
}

.rag-dot.state-on {
  background: rgba(59, 130, 246, 0.12);
  border-color: #3b82f6;
  color: #3b82f6;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
}

.rag-dot.state-live {
  background: rgba(34, 197, 94, 0.18);
  border-color: #22c55e;
  color: #22c55e;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.45), 0 0 28px rgba(34, 197, 94, 0.15);
  animation: rag-pulse 2.2s ease-in-out infinite;
}

.rag-dot.state-manual {
  background: rgba(245, 158, 11, 0.08);
  border-color: #f59e0b;
  border-style: dashed;
  color: #f59e0b;
}

.rag-dot.state-manual-active {
  background: rgba(245, 158, 11, 0.18);
  border-color: #f59e0b;
  border-style: solid;
  color: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
  animation: rag-pulse-amber 2.2s ease-in-out infinite;
}

@keyframes rag-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(34, 197, 94, 0.45), 0 0 28px rgba(34, 197, 94, 0.15); }
  50%       { box-shadow: 0 0 20px rgba(34, 197, 94, 0.7),  0 0 40px rgba(34, 197, 94, 0.25); }
}

@keyframes rag-pulse-amber {
  0%, 100% { box-shadow: 0 0 12px rgba(245, 158, 11, 0.4); }
  50%       { box-shadow: 0 0 20px rgba(245, 158, 11, 0.65); }
}

/* Connector line states */
.rag-line-off    { background: #252a3f; }
.rag-line-on     { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.rag-line-live   { background: linear-gradient(90deg, #16a34a, #22c55e); }
.rag-line-manual { background: linear-gradient(90deg, rgba(245,158,11,0.5), rgba(245,158,11,0.8)); }

@media (max-width: 1220px) {
  .cards-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .container {
    padding: 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .cards-grid,
  .split-2 {
    grid-template-columns: 1fr;
  }

  .pipeline-stage {
    min-width: 140px;
  }
}
