:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #171a21;
  --muted: #5b6370;
  --faint: #8c94a0;
  --line: #e0e3e8;
  --soft: #eceef2;
  --live: #17924F;
  --gate: #c27a0a;
  --raven: #6b5bd2;
  --apollo: #2f5bea;
  --artemis: #0e8f7e;
  --thoth: #a23b86;
  --neutral: #7a828e;
  --r: 8px;
  --sans: "Geist", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  min-height: 100vh;
}

/* Sidebar */
.side {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand i {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: conic-gradient(from 200deg, var(--raven), var(--apollo), var(--artemis), var(--thoth), var(--raven));
}

.brand b {
  font-size: 16px;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
}

.nav a:hover {
  background: var(--bg);
  color: var(--ink);
}

.nav a.active {
  background: var(--ink);
  color: #fff;
}

.me {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.me b {
  color: var(--ink);
  font-weight: 600;
}

/* Main Content */
.main {
  padding: 28px 36px 56px;
  max-width: 100%;
  width: 100%;
}

.head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

h1 {
  font-size: 24px;
  font-weight: 620;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 15px;
  font-weight: 620;
}

.meta {
  display: flex;
  gap: 18px;
  color: var(--muted);
  align-items: center;
}

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.section {
  margin-top: 28px;
}

.sec-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.sec-head small {
  color: var(--muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow-x: auto;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--faint);
  margin-right: 8px;
}

.dot.on {
  background: var(--live);
  border-color: var(--live);
}

.dot.pulse {
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

/* Metric Strip */
.strip {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  color: var(--muted);
}

.strip b {
  color: var(--ink);
  font-size: 18px;
  font-weight: 620;
  margin-right: 5px;
  font-variant-numeric: tabular-nums;
}

/* Pipeline SVG Flowmap */
.canvas {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background-color: var(--surface);
  background-image: radial-gradient(#d5d9e0 1px, transparent 1px);
  background-size: 20px 20px;
}

.flowmap {
  display: block;
  width: 100%;
  height: auto;
  min-height: 280px;
  max-height: 380px;
  font-family: var(--sans);
}

.flowmap .card {
  fill: #fff;
  stroke: var(--line);
  stroke-width: 1;
  transition: all 0.2s ease;
}

.flowmap .nm {
  font-size: 14px;
  font-weight: 600;
  fill: var(--ink);
}

.flowmap .rl {
  font-size: 11.5px;
  fill: var(--muted);
}

.flowmap .st {
  font-size: 11px;
  fill: var(--muted);
}

.flowmap .st.on {
  fill: var(--live);
  font-weight: 600;
}

.flowmap .edge {
  fill: none;
  stroke: #b4bac4;
  stroke-width: 1.5;
}

.flowmap .edge.live {
  stroke: var(--live);
  stroke-width: 2;
  stroke-dasharray: 6 6;
  animation: flow 1s linear infinite;
}

.flowmap .edge.gate {
  stroke: var(--gate);
  stroke-dasharray: 4 4;
}

.flowmap g[id^="node-"] {
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.flowmap g[id^="node-"]:hover {
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.08));
}

.flowmap g[id^="node-"].active-node .card {
  stroke: var(--apollo);
  stroke-width: 2;
}

.flowmap g[id^="node-"].is-working .card {
  stroke: var(--gate);
  stroke-width: 2;
  stroke-dasharray: 4 2;
  animation: pulse-border 1.5s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.4; }
}

/* Modal details */
.pipeline-drawer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 20px;
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.pipeline-drawer .info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pipeline-drawer .badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.flowmap .pt {
  font-size: 12px;
  fill: #8a5600;
  font-weight: 500;
}

@keyframes flow {
  to {
    stroke-dashoffset: -12;
  }
}

.legend {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.legend i {
  display: inline-block;
  width: 22px;
  border-top: 2px dashed var(--live);
  vertical-align: middle;
  margin-right: 8px;
}

.legend i.idle {
  border-top: 2px solid #b4bac4;
}

.legend i.gate {
  border-top-color: var(--gate);
}

.two {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
}

.empty {
  padding: 26px 20px;
  color: var(--muted);
  max-width: 60ch;
  font-size: 13.5px;
}

.empty b {
  display: block;
  color: var(--ink);
  font-weight: 600;
  margin-bottom: 2px;
}

details.panel summary {
  padding: 12px 20px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

details.panel summary::before {
  content: "+";
  display: inline-block;
  width: 18px;
  color: var(--muted);
}

details[open].panel summary::before {
  content: "–";
}

details[open].panel summary {
  border-bottom: 1px solid var(--line);
}

summary:focus-visible {
  outline: 2px solid var(--apollo);
  outline-offset: -2px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 20px;
  text-align: left;
  vertical-align: baseline;
  font-size: 13.5px;
}

th {
  font-weight: 500;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  border-top: 1px solid var(--soft);
}

tbody tr:first-child td {
  border-top: 0;
}

td.k {
  font-weight: 620;
}

td.sub {
  color: var(--muted);
}

.on-t {
  color: var(--live);
  font-weight: 600;
  white-space: nowrap;
}

.idle-t {
  color: var(--muted);
  white-space: nowrap;
}

/* Task Kanban */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.col {
  background: #eef0f4;
  border-radius: var(--r);
  padding: 12px;
  min-height: 220px;
}

.col h3 {
  font-size: 13.5px;
  font-weight: 620;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.col h3 span {
  margin-left: auto;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.col h3 i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.slot {
  border: 1.5px dashed #c5cad3;
  border-radius: 6px;
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
}

/* Forms & UI Controls */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span {
  font-weight: 600;
  font-size: 13px;
}

input[type=text],
input[type=password],
input[type=search],
input[type=file],
select {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd0d8;
  border-radius: 6px;
  padding: 7px 10px;
  min-height: 36px;
  width: 100%;
}

input[type=file]::file-selector-button {
  font: inherit;
  margin-right: 10px;
  border: 0;
  border-radius: 4px;
  background: var(--bg);
  padding: 4px 10px;
  cursor: pointer;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--apollo);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--ink);
  color: #fff;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn:hover {
  background: #2c313c;
}

.btn.ghost {
  background: #fff;
  color: var(--ink);
  border-color: #cbd0d8;
}

.btn.ghost:hover {
  background: var(--bg);
}

.import {
  padding: 20px;
}

.import p {
  color: var(--muted);
  margin: 4px 0 18px;
  max-width: 70ch;
}

.import form {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px auto;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.alert-box {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13.5px;
  line-height: 1.4;
}

.alert-success {
  background: rgba(23, 146, 79, 0.1);
  color: #0d5d33;
  border: 1px solid rgba(23, 146, 79, 0.3);
}

.alert-danger {
  background: rgba(200, 30, 30, 0.1);
  color: #9c1414;
  border: 1px solid rgba(200, 30, 30, 0.3);
}

/* Responsive */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .side {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 12px;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .me {
    margin: 0 0 0 auto;
    gap: 12px;
  }
  .main {
    padding: 20px 16px 40px;
  }
  .two,
  .import form,
  .tools {
    grid-template-columns: 1fr;
  }
  .board {
    grid-template-columns: 1fr 1fr;
  }
  table {
    min-width: 620px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flowmap .edge.live {
    animation: none;
  }
}
