:root,
[data-theme="dark"] {
  --bg: #0e141b;
  --bg2: #161d26;
  --bg3: #1e2733;
  --fg: #e6ecf2;
  --muted: #7e8ea0;
  --accent: #4cc9f0;
  --accent-dim: #2b5a72;
  --success: #5fce5f;
  --warn: #f4b93a;
  --error: #ff6b6b;
  --border: #2a3340;

  --overlay-bg: rgba(22, 29, 38, 0.85);
  --overlay-bg-strong: rgba(22, 29, 38, 0.92);
  --overlay-bg-faint: rgba(22, 29, 38, 0.72);
  --toast-bg: rgba(22, 29, 38, 0.96);
  --satellite-bg: rgba(14, 20, 27, 0.92);
  --backdrop-bg: rgba(6, 10, 14, 0.72);
  --shadow-strong: 0 30px 80px rgba(0, 0, 0, 0.6);
  --shadow-med: 0 10px 34px rgba(0, 0, 0, 0.65);
  --shadow-soft: -6px 0 28px rgba(0, 0, 0, 0.35);
  --btn-save-fg: #0b141c;
  --row-hover-bg: rgba(255, 255, 255, 0.03);
  --row-hover-strong: rgba(255, 255, 255, 0.06);
  --graph-glow: rgba(76, 201, 240, 0.08);
  --node-bg: #1e2733;
  --scheme: dark;
}

/* ============ Sidebar común ============ */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 64px;
  z-index: 40;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.8rem 0;
  gap: 0.5rem;
}
.app-sidebar .nav-item {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.58rem;
  letter-spacing: 0.3px;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
  user-select: none;
}
.app-sidebar .nav-item-icon { font-size: 1.3rem; line-height: 1; }
.app-sidebar .nav-item:hover {
  background: var(--row-hover-bg);
  color: var(--fg);
}
.app-sidebar .nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.app-sidebar .sep { flex: 1; }
.app-sidebar .sidebar-brand {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #0e141b;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.6rem;
  font-size: 1.15rem;
}

/* shift global del contenido para dejar lugar al sidebar */
body.with-sidebar { padding-left: 64px; }
body.with-sidebar > header { left: 64px !important; }

@media (max-width: 640px) {
  .app-sidebar {
    top: auto;
    right: 0;
    bottom: 0;
    width: auto;
    height: 54px;
    flex-direction: row;
    justify-content: space-around;
    padding: 0.3rem 0.5rem;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .app-sidebar .sep, .app-sidebar .sidebar-brand { display: none; }
  .app-sidebar .nav-item { width: 56px; height: 46px; }
  body.with-sidebar { padding-left: 0; padding-bottom: 54px; }
  body.with-sidebar > header { left: 0 !important; }
}

[data-theme="light"] {
  --bg: #f5f7fa;
  --bg2: #ffffff;
  --bg3: #eef2f7;
  --fg: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-dim: #dbeafe;
  --success: #16a34a;
  --warn: #b45309;
  --error: #dc2626;
  --border: #d6dde6;

  --overlay-bg: rgba(255, 255, 255, 0.92);
  --overlay-bg-strong: rgba(255, 255, 255, 0.96);
  --overlay-bg-faint: rgba(248, 250, 252, 0.82);
  --toast-bg: rgba(255, 255, 255, 0.98);
  --satellite-bg: rgba(255, 255, 255, 0.96);
  --backdrop-bg: rgba(15, 23, 42, 0.35);
  --shadow-strong: 0 30px 80px rgba(15, 23, 42, 0.22);
  --shadow-med: 0 10px 34px rgba(15, 23, 42, 0.18);
  --shadow-soft: -6px 0 28px rgba(15, 23, 42, 0.12);
  --btn-save-fg: #ffffff;
  --row-hover-bg: rgba(15, 23, 42, 0.04);
  --row-hover-strong: rgba(15, 23, 42, 0.06);
  --graph-glow: rgba(2, 132, 199, 0.1);
  --node-bg: #ffffff;
  --scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}
header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
header h1 .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: heartbeat 2s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.stats { display: flex; gap: 1.5rem; align-items: center; }
.stat {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  line-height: 1.1;
}
.stat label { font-size: 0.65rem; }
.stat b { font-size: 1.05rem; font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
.stat b.offline { color: var(--warn); font-size: 0.8rem; font-weight: 500; }
.stat b.online  { color: var(--success); font-size: 0.8rem; font-weight: 500; }

.nav-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  letter-spacing: 0.4px;
  transition: background 0.15s;
}
.nav-link:hover { background: var(--accent-dim); }

main {
  display: grid;
  grid-template-rows: minmax(260px, 1fr) 340px;
  height: calc(100vh - 60px);
}

.graph {
  position: relative;
  min-height: 580px;
  background:
    radial-gradient(ellipse 80% 60% at 50% 50%, rgba(76,201,240,0.06) 0%, transparent 70%),
    var(--bg);
  overflow: hidden;
}
#links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  transition: opacity 0.3s;
  text-align: center;
}
.node.offline { opacity: 0.45; }

.avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.8rem;
  border: 3px solid rgba(255,255,255,0.12);
  user-select: none;
  transition: box-shadow 0.25s, transform 0.25s;
  background-size: cover;
}
.node.working .avatar {
  box-shadow: 0 0 40px var(--accent), inset 0 0 20px rgba(76,201,240,0.3);
  border-color: var(--accent);
  animation: nodepulse 1.4s ease-in-out infinite;
}
@keyframes nodepulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.name { font-size: 1.2rem; font-weight: 600; }
.role { font-size: 0.78rem; color: var(--muted); max-width: 180px; }
.status {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 0.2rem 0.7rem;
  border-radius: 12px;
  background: var(--border);
  color: var(--muted);
  min-width: 70px;
  text-align: center;
}
.status.working { background: var(--accent); color: #001; animation: statusblink 1.2s ease-in-out infinite; }
.status.error   { background: var(--error); color: #fff; }
@keyframes statusblink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.6; }
}

/* enlaces svg */
#links .link {
  stroke: var(--border);
  stroke-width: 1.5;
  fill: none;
}
#links .link.active {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-dasharray: 10 8;
  animation: flow 0.7s linear infinite;
  filter: drop-shadow(0 0 8px var(--accent));
}
@keyframes flow {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -18; }
}

/* timeline */
.timeline {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tl-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.tl-head h2 {
  margin: 0;
  font-size: 0.72rem; font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}
.tl-head button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 0.4px;
}
.tl-head button:hover { color: var(--fg); border-color: var(--muted); }

#events {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}
#events li {
  padding: 0.55rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 78px 150px 1fr 70px;
  gap: 1rem;
  align-items: start;
  font-size: 0.88rem;
  animation: rowin 0.25s ease-out;
}
@keyframes rowin {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
#events li .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.82rem; padding-top: 1px; }
#events li .flow {
  display: flex; align-items: center; gap: 0.4rem;
  font-weight: 600; font-size: 0.86rem;
}
#events li .flow .arrow { color: var(--muted); font-weight: 400; }
#events li .flow .chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.82rem;
}
#events li .flow .chip .mini {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
}
#events li .content { color: var(--fg); line-height: 1.45; word-break: break-word; }
#events li .content .lbl {
  display: inline-block;
  font-size: 0.66rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  margin-right: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  vertical-align: 1px;
}
#events li .content .lbl.prompt   { background: var(--accent-dim); color: var(--accent); }
#events li .content .lbl.response { background: #264426; color: var(--success); }
#events li .content .lbl.error    { background: #4a1e1e; color: var(--error); }
#events li .elapsed { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: 0.82rem; padding-top: 1px; }
#events li.error { background: rgba(255,107,107,0.04); }

#events::-webkit-scrollbar { width: 8px; }
#events::-webkit-scrollbar-track { background: var(--bg2); }
#events::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
