:root {
  --bg: #0f172a;
  --panel: #0b1220;
  --panel-2: #131d32;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --running: #f59e0b;
  --ok: #22c55e;
  --error: #ef4444;
  --accent: #38bdf8;
  --border: #334155;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #1e293b, var(--bg));
}

body.auth-locked {
  overflow: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: radial-gradient(circle at top right, #1e293b, #0b1220 65%);
  z-index: 1000;
}

#app-shell {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 220ms ease, transform 220ms ease;
}

body.auth-ready #app-shell {
  opacity: 1;
  transform: translateY(0);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 0.6rem;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.95), rgba(17, 24, 39, 0.75));
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 1rem;
}

.login-card h1 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); }
.login-card input {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  border-radius: 0.5rem;
  padding: 0.6rem;
}
.login-card button {
  border: 1px solid rgba(56, 189, 248, 0.5);
  background: rgba(56, 189, 248, 0.18);
  color: #dbeafe;
  border-radius: 0.5rem;
  padding: 0.55rem 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:disabled {
  cursor: wait;
  opacity: 0.75;
}

.login-status,
.login-error {
  min-height: 1.1rem;
  font-size: 0.92rem;
}

.login-status {
  color: #93c5fd;
}

.login-status.loading::before {
  content: '';
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid rgba(147, 197, 253, 0.35);
  border-top-color: #93c5fd;
  border-radius: 999px;
  display: inline-block;
  margin-right: 0.45rem;
  vertical-align: -0.1rem;
  animation: spin 0.8s linear infinite;
}

.login-error { color: #fca5a5 !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.6rem;
  border-bottom: 1px solid var(--border);
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(8px);
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  border-radius: 0.6rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.topbar h1 { margin: 0; font-size: 1.35rem; }
.topbar p { margin: 0.25rem 0 0; color: var(--muted); }

.chip {
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
}

.chip-live {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.12);
}

.chip-stale {
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.12);
}

.chip-offline {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.12);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(320px, 0.9fr);
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.95), rgba(17, 24, 39, 0.75));
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 1rem;
}

.panel-head h2 { margin: 0; }
.panel-head p { margin: 0.2rem 0 0.85rem; color: var(--muted); }

.flow-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.flow-step {
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  color: #bfdbfe;
  background: linear-gradient(90deg, rgba(56,189,248,0.08), rgba(34,197,94,0.05));
  position: relative;
  overflow: hidden;
}

.flow-step::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 15%, rgba(125, 211, 252, 0.2) 50%, transparent 85%);
  transform: translateX(-120%);
  animation: sweep 3.2s linear infinite;
}

.graph-stage {
  position: relative;
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background:
    linear-gradient(rgba(148, 163, 184, 0.06) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px) 0 0 / 32px 32px,
    rgba(15, 23, 42, 0.75);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.graph-stage:active {
  cursor: grabbing;
}

.graph-controls {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  z-index: 12;
  display: flex;
  gap: 0.35rem;
}

.zoom-btn {
  border: 1px solid var(--border);
  background: rgba(2, 6, 23, 0.78);
  color: #e2e8f0;
  border-radius: 0.55rem;
  min-width: 2rem;
  height: 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.zoom-reset {
  min-width: 4.8rem;
  padding: 0 0.6rem;
  font-size: 0.84rem;
}

.graph-viewport {
  position: absolute;
  inset: 0;
  width: 1320px;
  height: 920px;
  transform-origin: 0 0;
  will-change: transform;
}

.flow-links,
.nodes-layer {
  position: absolute;
  inset: 0;
}

.flow-links {
  pointer-events: none;
}

.binding-diagnostics {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 13;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  font-size: 0.68rem;
  padding: 0.35rem 0.45rem;
  border-radius: 0.45rem;
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(2, 6, 23, 0.78);
  pointer-events: none;
}

.graph-link {
  fill: none;
  stroke: rgba(56, 189, 248, 0.85);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 10 10;
  animation: dash 1.5s linear infinite;
}

.graph-link.back {
  stroke: rgba(148, 163, 184, 0.55);
  stroke-dasharray: 6 12;
}

.graph-node {
  position: absolute;
  width: 220px;
  min-height: 128px;
  border-radius: 0.85rem;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.92));
  color: var(--text);
  text-align: left;
  padding: 0.65rem;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.graph-node:hover,
.graph-node.active {
  transform: translateY(-2px);
  border-color: rgba(125, 211, 252, 0.9);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.node-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.node-name { margin: 0; font-size: 1rem; }
.node-role { margin: 0.4rem 0 0.6rem; color: var(--muted); font-size: 0.82rem; line-height: 1.35; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 0 0 6px rgba(148, 163, 184, 0.08);
}

.status-ok { background: var(--ok); box-shadow: 0 0 10px rgba(34, 197, 94, 0.95); }
.status-running { background: var(--running); box-shadow: 0 0 10px rgba(245, 158, 11, 0.95); }
.status-error { background: var(--error); box-shadow: 0 0 10px rgba(239, 68, 68, 0.95); }

.tools-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tool-badge {
  border: 1px solid #475569;
  background: rgba(148, 163, 184, 0.08);
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 0.12rem 0.5rem;
  color: #cbd5e1;
}

.detail-panel h2 { margin-top: 0; }

.node-detail.empty {
  color: var(--muted);
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 0.8rem;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.detail-header h3 { margin: 0; font-size: 1.05rem; }

.status-pill {
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  border: 1px solid currentColor;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.status-pill.ok { color: var(--ok); }
.status-pill.running { color: var(--running); }
.status-pill.error { color: var(--error); }

.detail-block { margin-bottom: 0.95rem; }
.detail-block h4 { margin: 0 0 0.35rem; font-size: 0.86rem; color: #bfdbfe; }

.detail-list {
  margin: 0;
  padding-left: 1rem;
  color: #d1d5db;
  font-size: 0.86rem;
  line-height: 1.45;
}

.inline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.source-chip { font-size: 0.72rem; }
.source-real { color: #86efac; border-color: rgba(34, 197, 94, 0.55); background: rgba(34, 197, 94, 0.12); }
.source-mixed { color: #fcd34d; border-color: rgba(245, 158, 11, 0.55); background: rgba(245, 158, 11, 0.12); }
.source-fallback { color: #fca5a5; border-color: rgba(239, 68, 68, 0.55); background: rgba(239, 68, 68, 0.12); }
.source-unavailable { color: #cbd5e1; border-color: rgba(148, 163, 184, 0.5); background: rgba(148, 163, 184, 0.12); }

.activity-layout { padding-top: 0; }
.activity-list li { margin-bottom: 0.5rem; }
.activity-meta {
  display: block;
  color: #93c5fd;
  font-size: 0.74rem;
}

.agent-activity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
}

.agent-activity-card {
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.6rem;
  background: rgba(2, 6, 23, 0.4);
}

.agent-activity-card h4 {
  margin: 0 0 0.45rem;
  color: #bfdbfe;
  text-transform: capitalize;
}

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

@keyframes dash {
  to { stroke-dashoffset: -20; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes sweep {
  to { transform: translateX(120%); }
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .graph-stage { min-height: 520px; }
}

@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .flow-strip { grid-template-columns: repeat(2, 1fr); }
  .graph-stage { min-height: 420px; }
  .graph-controls { right: 0.55rem; top: 0.55rem; }
  .zoom-btn { min-width: 1.9rem; height: 1.9rem; }
  .zoom-reset { min-width: 4.4rem; font-size: 0.78rem; }
  .graph-node { width: 188px; }
}
