:root {
  --bg: #0b1020;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #1e3a8a33, transparent 60%),
              radial-gradient(900px 500px at -10% 10%, #7c3aed33, transparent 60%),
              linear-gradient(180deg, #0b1020, #070b18);
  --panel: rgba(17, 24, 39, 0.7);
  --panel-border: #1f2a44;
  --panel-2: #0a1226;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --green: #22c55e;
  --emerald: #10b981;
  --purple: #a78bfa;
  --blue: #60a5fa;
  --amber: #f59e0b;
  --red: #ef4444;
  --pink: #ec4899;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --topbar-h: 64px;
}

body[data-theme="light"] {
  --bg: #f8fafc;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #93c5fd55, transparent 60%),
              radial-gradient(900px 500px at -10% 10%, #c4b5fd55, transparent 60%),
              linear-gradient(180deg, #f8fafc, #eef2ff);
  --panel: rgba(255, 255, 255, 0.85);
  --panel-border: #e2e8f0;
  --panel-2: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100vh;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, Arial, sans-serif;
  overflow: hidden;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--panel-border);
  gap: 16px;
  backdrop-filter: blur(8px);
  background: linear-gradient(180deg, rgba(11,16,32,0.92), rgba(11,16,32,0.6));
}
body[data-theme="light"] .topbar {
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.6));
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 1.05rem; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 0.78rem; }
.logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5, #ec4899);
  color: white; font-weight: 800; box-shadow: var(--shadow);
}
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.group {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border: 1px solid var(--panel-border);
  border-radius: 12px; background: var(--panel); backdrop-filter: blur(6px);
}
label { color: var(--muted); font-size: 0.78rem; }
button, select, input[type="text"], input[type="number"], input:not([type]) {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 5px 10px; font-size: 0.83rem; font-family: inherit; outline: none;
}
button { cursor: pointer; transition: transform 0.05s ease, border-color 0.2s, background 0.2s; }
button:hover { border-color: var(--blue); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border-color: transparent; color: white; font-weight: 600;
  box-shadow: 0 6px 18px rgba(99,102,241,0.35);
}
button.ghost { background: transparent; }
button.small { padding: 3px 6px; font-size: 0.75rem; }
button.link { background: transparent; border: none; color: var(--blue); padding: 0; cursor: pointer; text-decoration: underline; }
.badge {
  display: inline-block; padding: 2px 6px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--panel-border);
  font-size: 0.72rem; color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.graph-panel { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.graph-toolbar {
  display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
}
.pill {
  display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 0.7rem;
  background: linear-gradient(135deg, #1e3a8a55, #6366f155);
  border: 1px solid var(--panel-border);
}
.pill.ghost { background: var(--panel-2); color: var(--muted); }
.pill.warn { background: linear-gradient(135deg, #b45309, #f59e0b); color: white; }

#graphCanvas {
  position: relative; flex: 1; min-height: 0;
  background:
    radial-gradient(700px 300px at 70% 20%, rgba(99,102,241,0.10), transparent 70%),
    radial-gradient(500px 250px at 20% 70%, rgba(236,72,153,0.08), transparent 70%);
  overflow: hidden;
}
#graphSvg { display: block; width: 100%; height: 100%; cursor: grab; }
#graphSvg.panning { cursor: grabbing; }

.zoom-controls {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; gap: 6px; align-items: center;
  padding: 5px 8px; background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 10px;
  backdrop-filter: blur(8px); z-index: 5;
}
.zoom-controls button { padding: 3px 8px; font-size: 0.78rem; min-width: 30px; }

/* SVG nodes */
.node-rect {
  fill: rgba(15, 26, 50, 0.95);
  stroke: #334155; stroke-width: 1.5;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.35));
  transition: stroke 0.2s, transform 0.15s;
}
body[data-theme="light"] .node-rect { fill: #ffffff; stroke: #cbd5e1; }
.node-group { cursor: pointer; }
.node-group:hover .node-rect { stroke: var(--blue); }
.node-group.flash .node-rect {
  animation: nodeFlash 0.6s ease;
}
@keyframes nodeFlash {
  0% { stroke-width: 1.5; }
  40% { stroke-width: 4; }
  100% { stroke-width: 1.5; }
}

.node-title { fill: var(--text); font: 700 12px "Inter", system-ui, sans-serif; }
.node-sub   { fill: var(--muted); font: 400 10px "Inter", system-ui, sans-serif; }

.node-rect.topic    { stroke: #2563eb; }
.node-rect.internal { stroke: #7c3aed; }
.node-rect.store    { stroke: #16a34a; }
.node-rect.thread   { stroke: #f59e0b; }
.node-rect.sink     { stroke: #ec4899; }

/* Edges */
.edge-path {
  fill: none;
  stroke: #64748b;
  stroke-width: 1.8;
  stroke-dasharray: 6 5;
  opacity: 0.85;
  animation: dashFlow 2s linear infinite;
}
@keyframes dashFlow {
  to { stroke-dashoffset: -22; }
}

/* Records */
.record-dot {
  cursor: pointer; pointer-events: all;
}
.record-dot circle.user     { fill: url(#gradUser); filter: drop-shadow(0 0 6px rgba(34,197,94,0.7)); }
.record-dot circle.internal { fill: url(#gradInternal); filter: drop-shadow(0 0 6px rgba(167,139,250,0.7)); }
.record-dot circle.late     { fill: url(#gradLate); filter: drop-shadow(0 0 6px rgba(239,68,68,0.7)); }
.record-dot text { fill: white; font: 700 9px sans-serif; pointer-events: none; user-select: none; }

/* Zones */
.zone-rect { fill-opacity: 0.07; stroke-opacity: 0.55; stroke-width: 1.5; stroke-dasharray: 6 5; rx: 18; }
.zone-rect.streams { fill: #6366f1; stroke: #818cf8; }
.zone-rect.brokers { fill: #0ea5e9; stroke: #38bdf8; }
.zone-rect.disk    { fill: #16a34a; stroke: #4ade80; }
.zone-rect.sortie  { fill: #ec4899; stroke: #f472b6; }
.zone-label { font: 700 11px "Inter", system-ui, sans-serif; letter-spacing: 1px; text-transform: uppercase; }
.zone-label.streams { fill: #c7d2fe; }
.zone-label.brokers { fill: #bae6fd; }
.zone-label.disk    { fill: #bbf7d0; }
.zone-label.sortie  { fill: #fbcfe8; }
body[data-theme="light"] .zone-label { fill: #334155; }
body[data-theme="light"] .zone-rect { fill-opacity: 0.10; }

/* Dragging */
.node-group { cursor: grab; }
.node-group.dragging { cursor: grabbing; }
.node-group.dragging .node-rect { stroke-width: 3; filter: drop-shadow(0 12px 24px rgba(0,0,0,0.5)); }

/* Partition lanes inside source node */
.partition-cell { fill: #334155; }
.partition-cell.consumed { fill: var(--green); }
.partition-cell.head { fill: var(--amber); }
.partition-label { fill: var(--muted); font: 500 8px monospace; }

/* Legend */
.legend {
  display: flex; gap: 14px; padding: 8px 10px;
  border-top: 1px solid var(--panel-border); color: var(--muted); font-size: 0.78rem;
  align-items: center; flex-wrap: wrap;
}
.legend .hint { margin-left: auto; font-style: italic; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 6px; vertical-align: middle; }
.dot.user { background: #22c55e; }
.dot.internal { background: #a78bfa; }
.dot.late { background: #ef4444; }

/* Aside scrollable */
.side {
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto; overflow-x: hidden;
  padding-right: 4px;
}
.side::-webkit-scrollbar { width: 8px; }
.side::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

h3 { margin: 0 0 8px; font-size: 0.92rem; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.76rem; }

.metrics-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px;
}
.metric {
  background: var(--panel-2); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column;
}
.metric-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.4px; }
.metric-value { font-size: 1.1rem; font-weight: 700; }

#throughputCanvas {
  width: 100%; height: 70px; display: block; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--panel-border);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; }
.form-row input { min-width: 0; }

.mono {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 8px 10px; font-size: 12px;
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
  max-height: 200px; overflow: auto;
}
.mono.logs { max-height: 220px; }
.log-line { display: block; }
.log-info  { color: var(--text); }
.log-warn  { color: var(--amber); }
.log-error { color: var(--red); }
.log-debug { color: var(--muted); }
.log-emit  { color: var(--emerald); }
.log-time  { color: var(--muted); font-weight: 500; }

.tooltip {
  position: absolute; z-index: 30; pointer-events: none;
  background: rgba(2,6,23,0.95); color: #e5e7eb;
  border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 8px 10px; font-size: 0.78rem; max-width: 280px;
  box-shadow: var(--shadow);
}

/* Toasts */
#toastContainer {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 100; pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px; max-width: 460px;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--panel-border);
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  font-size: 0.85rem;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  display: flex; gap: 10px; align-items: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.hide { opacity: 0; transform: translateY(-8px); }
.toast .ico {
  width: 22px; height: 22px; flex: 0 0 22px;
  border-radius: 999px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.8rem;
}
.toast.info  .ico { background: #6366f1; color: white; }
.toast.warn  .ico { background: #f59e0b; color: white; }
.toast.error .ico { background: #ef4444; color: white; }
.toast.emit  .ico { background: #10b981; color: white; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  html, body { overflow: auto; }
  #graphCanvas { height: 520px; }
  .side { max-height: none; }
}

/* Pedagogie modal */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.18s ease;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(2, 6, 23, 0.65);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: min(640px, 92vw);
  background: linear-gradient(180deg, #0f172a, #0b1224);
  color: var(--text);
  border: 1px solid #1f2a44;
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: popIn 0.22s cubic-bezier(.2,.9,.3,1.15);
}
body[data-theme="light"] .modal-card {
  background: linear-gradient(180deg, #ffffff, #f1f5f9);
  border-color: #e2e8f0;
  color: #0f172a;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #1f2a44;
  background: linear-gradient(180deg, rgba(99,102,241,0.18), transparent);
}
body[data-theme="light"] .modal-head { border-color: #e2e8f0; background: linear-gradient(180deg, rgba(99,102,241,0.12), transparent); }
.modal-phase {
  font: 700 10px "Inter", system-ui, sans-serif;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #4f46e5, #ec4899);
  color: white;
  flex: 0 0 auto;
}
.modal-head h2 {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.modal-close {
  background: transparent; border: none; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 14px 16px;
  max-height: 60vh;
  overflow: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-body section h4 {
  margin: 0 0 4px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 700;
}
.modal-body section p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
}
.modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid #1f2a44;
  background: rgba(2, 6, 23, 0.35);
}
body[data-theme="light"] .modal-foot { border-color: #e2e8f0; background: rgba(241,245,249,0.7); }
.modal-foot label { display: flex; align-items: center; gap: 6px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn  {
  from { transform: translateY(10px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0)   scale(1);    opacity: 1; }
}

