:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1c2333;
  --muted: #64748b;
  --line: #dbe2ee;
  --accent: #1d4ed8;
  --accent-soft: #dbe7ff;
  --ok: #16a34a;
  --ko: #dc2626;
  --warn: #d97706;
  --mono: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg); color: var(--ink);
}
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--ko); font-weight: 600; }

/* ---------- connexion ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 36px 40px; width: 360px; box-shadow: 0 12px 40px rgba(28,35,51,.10);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.brand-big { font-size: 26px; font-weight: 800; }
.login-card label { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 4px; padding: 9px 11px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px;
}

/* ---------- structure ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  background: #101830; color: #fff; padding: 10px 18px;
}
.brand { font-weight: 800; font-size: 17px; margin-right: 8px; }
.who { opacity: .85; }
.countdown { font-variant-numeric: tabular-nums; opacity: .9; }
.countdown.low { color: #fca5a5; font-weight: 700; }
.badge {
  padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700;
  background: #334155; color: #e2e8f0;
}
.badge.ok { background: var(--ok); color: #fff; }
.badge.warn { background: var(--warn); color: #fff; }
.tabs {
  display: flex; gap: 4px; background: #101830; padding: 0 14px;
}
.tab {
  border: 0; background: transparent; color: #b9c2d8; font-size: 14.5px; font-weight: 600;
  padding: 10px 16px; cursor: pointer; border-radius: 8px 8px 0 0;
}
.tab.active { background: var(--bg); color: var(--ink); }
main { padding: 16px 18px; max-width: 1500px; margin: 0 auto; }

/* ---------- boutons, formulaires ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: #b6c2d9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--ko); border-color: #f3c1c1; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px;
}
.card label, .login-card label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
.card input, .card select, .card textarea {
  width: 100%; margin-top: 3px; padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.card .row label { flex: 1; }
.panel-title { font-weight: 700; margin-bottom: 6px; }
.panel-title.row { justify-content: flex-start; }
.small-label { font-size: 13px; display: flex; align-items: center; gap: 5px; }
.small-note { font-size: 12.5px; line-height: 1.5; }
.legend { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 99px; display: inline-block; margin-left: 10px; }
.dot.ok { background: var(--ok); } .dot.ko { background: var(--ko); }
.dot.off { background: #94a3b8; } .dot.add { background: #fff; border: 2px dashed #94a3b8; }

/* ---------- architecture ---------- */
.archi-wrap { display: flex; gap: 14px; align-items: stretch; }
#archi-svg {
  flex: 1; min-width: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
}
.nf-node { cursor: pointer; }
.nf-node rect {
  fill: #fff; stroke: #94a3b8; stroke-width: 1.6; rx: 10;
  filter: drop-shadow(0 2px 3px rgba(28,35,51,.08));
}
.nf-node.running rect { stroke: var(--ok); fill: #f2fbf5; }
.nf-node.exited rect, .nf-node.restarting rect { stroke: var(--ko); fill: #fef2f2; }
.nf-node.absent rect { stroke-dasharray: 5 4; fill: #f8fafc; }
.nf-node.selected rect { stroke-width: 3; }
.nf-node text { fill: var(--ink); font-weight: 700; font-size: 15px; text-anchor: middle; }
.nf-node .nf-ip { font-size: 10.5px; font-weight: 400; fill: var(--muted); font-family: var(--mono); }
.nf-node .nf-plus { font-size: 20px; fill: #94a3b8; font-weight: 400; }
.nf-node .nf-slice-badge { font-size: 9.5px; font-weight: 700; fill: #fff; text-anchor: middle; }
.nf-node.absent text { fill: #94a3b8; }
.nf-link { stroke: #b6c2d9; stroke-width: 1.6; fill: none; }
.nf-link.bus { stroke: #7c93be; stroke-width: 3.5; }
.nf-link.dashed { stroke-dasharray: 4 4; }
.nf-link-label { font-size: 11px; fill: var(--muted); font-weight: 600; text-anchor: middle; }
.nf-state-dot { r: 5; }
.nf-state-dot.running { fill: var(--ok); }
.nf-state-dot.exited, .nf-state-dot.restarting { fill: var(--ko); }
.nf-state-dot.other { fill: #94a3b8; }
.svg-cloud { fill: #eef3fb; stroke: #7c93be; stroke-width: 1.6; }
.svg-cloud-label { font-size: 13px; font-weight: 700; fill: var(--muted); text-anchor: middle; }

.nf-panel {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  height: fit-content;
}
.nf-panel h3 { margin: 0; font-size: 16px; }
.nf-panel .desc { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.nf-panel .kv { font-size: 13px; display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding: 3px 0; }
.nf-panel .actions { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }

/* ---------- configuration ---------- */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line); background: var(--panel); border-radius: 99px;
  padding: 5px 13px; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.editor {
  width: 100%; height: 480px; font-family: var(--mono); font-size: 13px;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  background: #0f172a; color: #d7e3f4; resize: vertical; tab-size: 2;
}
.logs {
  height: 480px; overflow: auto; margin: 0; font-family: var(--mono); font-size: 12px;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  background: #0f172a; color: #c8d6ea; white-space: pre-wrap; word-break: break-all;
}

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); background: #f8fafc;
}
.table td { padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.table tbody tr:hover { background: #f1f5fb; }
.sim-grid { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }

/* ---------- trace ---------- */
.filter { flex: 1; min-width: 220px; padding: 7px 10px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; }
.trace-grid { display: grid; grid-template-rows: 1fr auto; gap: 12px; }
.trace-list-wrap { max-height: 52vh; overflow: auto; border-radius: 10px; }
.trace-table { font-family: var(--mono); font-size: 12.5px; }
.trace-table td { padding: 4px 8px; white-space: nowrap; }
.trace-table td:last-child { white-space: normal; word-break: break-word; min-width: 300px; }
.trace-table tbody tr { cursor: pointer; }
.trace-table tr.selected { outline: 2px solid var(--accent); }
.proto-NGAP { background: #ede9fe; } .proto-NGAP:hover { background: #e2dbfc; }
.proto-HTTP2, .proto-HTTP { background: #dcfce7; } .proto-HTTP2:hover { background: #cdf5da; }
.proto-PFCP { background: #ffedd5; } .proto-PFCP:hover { background: #fee3bd; }
.proto-GTP, .proto-GTPv1-U { background: #dbeafe; } .proto-GTP:hover { background: #cbe2fc; }
.proto-ICMP { background: #fef9c3; }
.proto-SCTP { background: #f3e8ff; }
.proto-TCP, .proto-DNS, .proto-ARP { background: #fff; }
/* détail redimensionnable par l'utilisateur (poignée en bas à droite) */
.trace-detail { height: 44vh; min-height: 140px; resize: vertical; }

/* bascule de mode pédagogique / expert */
.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mode-btn { border: 0; background: var(--panel); color: var(--muted); font-size: 13px; font-weight: 600; padding: 6px 12px; cursor: pointer; }
.mode-btn.active { background: var(--accent); color: #fff; }

/* diagramme de flux (ladder) */
.flow-grid { display: grid; grid-template-rows: 1fr auto; gap: 12px; }
.flow-scroll { position: relative; max-height: 56vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.flow-empty { padding: 26px; color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 760px; }
#flow-svg { display: block; }
.flow-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; font-size: 12.5px; color: var(--muted); }
.flow-legend .phase { display: inline-flex; align-items: center; gap: 5px; }
.flow-legend .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
/* lanes */
.lane-line { stroke: #c3ccdd; stroke-width: 1.5; }
.lane-head rect { rx: 8; }
.lane-head text { text-anchor: middle; font-weight: 700; font-size: 13px; fill: var(--ink); }
.lane-head .lane-sub { font-weight: 400; font-size: 10px; fill: var(--muted); }
/* messages */
.msg { cursor: pointer; }
.msg .msg-line { stroke-width: 1.8; }
.msg .msg-label { font-size: 12px; fill: var(--ink); }
.msg .msg-time { font-size: 10px; fill: var(--muted); font-family: var(--mono); }
.msg:hover .msg-hit { fill: rgba(29,78,216,.07); }
.msg.selected .msg-hit { fill: rgba(29,78,216,.13); }
.msg.selected .msg-label { font-weight: 700; }
.phase-band text { font-size: 11px; font-weight: 700; fill: var(--muted); letter-spacing: .04em; }
.phase-band line { stroke: #e2e8f0; stroke-width: 1; }
.nfname { font-weight: 700; }
.nfname small { font-weight: 400; color: var(--muted); }

/* ---------- scénarios ---------- */
.scen-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; align-items: start; }
.scen-list { display: flex; flex-direction: column; gap: 10px; }
.scen-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.scen-item h3 { margin: 0 0 4px; font-size: 15.5px; }
.scen-item p { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.scen-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }

/* ---------- admin ---------- */
.admin-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.state-ok { color: var(--ok); font-weight: 700; }
.state-ko { color: var(--ko); font-weight: 700; }

/* ---------- modale ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(16, 24, 48, .55);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #101830; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 50; max-width: 70vw;
}
.toast.err { background: #7f1d1d; }

@media (max-width: 1100px) {
  .config-grid, .sim-grid, .scen-grid, .admin-grid { grid-template-columns: 1fr; }
  .archi-wrap { flex-direction: column; }
  .nf-panel { width: auto; }
}
