/* Bigz_Intelz — même langage visuel que BigzCrackz : papier chaud, encre comme
   couleur de marque, rouge réservé au danger. Polices système uniquement
   (la CSP interdit toute ressource distante).
   Le thème sombre est déclaré deux fois (choix explicite et préférence du
   système) : les deux blocs doivent rester identiques. */

:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --ink: #1d1a16;
  --ink-2: #5c554a;
  --muted: #7a7265;
  --line: #ddd3c0;
  --accent: #1d1a16;
  --accent-fg: #f6f1e7;
  --bar: #2f5d7c;
  --track: #e6dece;
  --danger: #a3392c;
  --danger-fg: #fffdf8;
  --ok: #2f6b3a;
  --warn: #8a5a00;
  --tlp-clear: #fffdf8;
  --tlp-green: #2e8b3d;
  --tlp-amber: #d99000;
  --tlp-red: #c0392b;
  --shadow: rgba(29, 26, 22, 0.18);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --radius: 6px;
}

:root[data-theme="dark"] {
  --bg: #0f0e0c;
  --surface: #1a1815;
  --surface-2: #24211c;
  --ink: #f1eadc;
  --ink-2: #c3baa9;
  --muted: #968d7d;
  --line: #37322a;
  --accent: #f1eadc;
  --accent-fg: #0f0e0c;
  --bar: #8fb8d4;
  --track: #2c2822;
  --danger: #e07a6c;
  --danger-fg: #0f0e0c;
  --ok: #7fc48a;
  --warn: #e3b55a;
  --tlp-clear: #f1eadc;
  --tlp-green: #4fb561;
  --tlp-amber: #e8a92a;
  --tlp-red: #e5604f;
  --shadow: rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0e0c;
    --surface: #1a1815;
    --surface-2: #24211c;
    --ink: #f1eadc;
    --ink-2: #c3baa9;
    --muted: #968d7d;
    --line: #37322a;
    --accent: #f1eadc;
    --accent-fg: #0f0e0c;
    --bar: #8fb8d4;
    --track: #2c2822;
    --danger: #e07a6c;
    --danger-fg: #0f0e0c;
    --ok: #7fc48a;
    --warn: #e3b55a;
    --tlp-clear: #f1eadc;
    --tlp-green: #4fb561;
    --tlp-amber: #e8a92a;
    --tlp-red: #e5604f;
    --shadow: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}

h1, h2, h3, .brand { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }

/* --------------------------------------------------------------- barre --- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem;
  padding: 0.7rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 1.25rem; text-decoration: none; margin: 0; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; flex: 1; }
.topbar nav a {
  padding: 0.35rem 0.55rem; font-size: 0.93rem; white-space: nowrap; border-radius: var(--radius);
  text-decoration: none; color: var(--ink-2);
}
.topbar nav a:hover { background: var(--surface-2); color: var(--ink); }
.topbar nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); }
.topbar-end { display: flex; align-items: center; gap: 0.5rem; }

main { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.title-row { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.title-row h1 { margin: 0; flex: 1; }

/* ------------------------------------------------------------- boutons --- */
.btn {
  font: inherit; cursor: pointer;
  padding: 0.4rem 0.85rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--danger); color: var(--danger-fg); border-color: var(--danger); }
.btn.sm { padding: 0.15rem 0.55rem; font-size: 0.85rem; }
:focus-visible { outline: 2px solid var(--bar); outline-offset: 2px; }

/* ---------------------------------------------------------- formulaires --- */
input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.4rem 0.55rem; width: 100%;
}
textarea { font-family: var(--mono); font-size: 0.9rem; resize: vertical; margin-bottom: 0.75rem; }
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--ink-2); }
label.check { flex-direction: row; align-items: center; gap: 0.4rem; padding-bottom: 0.45rem; }
label.check input { width: auto; }
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem;
  padding: 1rem; margin-bottom: 0.75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.filters label { min-width: 8.5rem; }
.filters label.grow { flex: 1 1 16rem; }
.cell-input { width: 5.5rem; padding: 0.15rem 0.35rem; }
select.cell-input { width: 8.5rem; }

/* -------------------------------------------------------------- cartes --- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.75rem; }
.tile .tile-value { font: 600 2.1rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.tile .tile-label { color: var(--ink-2); font-size: 0.85rem; margin-top: 0.3rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 0.75rem; margin-top: 0.75rem; }
.card h3 { margin-top: 0; }

/* Répartitions : une seule teinte (grandeur), chaque barre porte son libellé
   et sa valeur — rien ne se lit à la couleur seule. */
.bars { display: grid; grid-template-columns: minmax(6rem, max-content) 1fr max-content; gap: 0.4rem 0.75rem; align-items: center; margin: 0; }
.bars dt { color: var(--ink-2); font-size: 0.88rem; overflow-wrap: anywhere; }
.bars dd { margin: 0; }
.bars .num { font-variant-numeric: tabular-nums; font-size: 0.88rem; text-align: right; }
.track { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.track > span { display: block; height: 100%; min-width: 2px; background: var(--bar); border-radius: 0 4px 4px 0; }

/* ------------------------------------------------------------- tableaux --- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--ink-2); font-weight: 600; font-size: 0.8rem; white-space: nowrap; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.value { font-family: var(--mono); font-size: 0.84rem; max-width: 30rem; overflow-wrap: anywhere; }
td.empty { color: var(--muted); text-align: center; padding: 2rem; }
tr.revoked td.value { text-decoration: line-through; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem; margin-top: 0.75rem; }

/* -------------------------------------------------------------- repères --- */
.tlp { display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.tlp::before { content: ""; width: 0.65rem; height: 0.65rem; border-radius: 50%; border: 1px solid var(--ink-2); }
.tlp-clear::before { background: var(--tlp-clear); }
.tlp-green::before { background: var(--tlp-green); border-color: var(--tlp-green); }
.tlp-amber::before { background: var(--tlp-amber); border-color: var(--tlp-amber); }
.tlp-amber-strict::before { background: var(--tlp-amber); border: 2px solid var(--ink); }
.tlp-red::before { background: var(--tlp-red); border-color: var(--tlp-red); }

.conf { display: inline-flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.conf .track { width: 3.5rem; height: 6px; }
.conf .num { min-width: 1.6rem; text-align: right; font-variant-numeric: tabular-nums; }

.chip {
  display: inline-block; margin: 0.1rem 0.25rem 0.1rem 0; padding: 0.05rem 0.45rem;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 0.78rem; color: var(--ink-2); background: var(--surface-2); white-space: nowrap;
}
.pill { padding: 0.15rem 0.6rem; border-radius: 999px; border: 1px solid var(--line); font-size: 0.82rem; color: var(--ink-2); }
.status { font-weight: 600; white-space: nowrap; }
.status-ok { color: var(--ok); }
.status-error { color: var(--danger); }
.status-skipped { color: var(--muted); font-weight: 400; }
.status-expired, .status-warn { color: var(--warn); }
.banner { padding: 0.6rem 0.9rem; border: 1px solid var(--danger); border-radius: var(--radius); background: var(--surface); }

/* ----------------------------------------------------------- connexion --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.login-card { width: min(26rem, 100%); display: flex; flex-direction: column; gap: 0.9rem; padding: 1.75rem; }
.login-card .brand { font-size: 1.9rem; }
.login-card p { margin: 0; }

/* -------------------------------------------------------------- détail --- */
dialog {
  width: min(56rem, calc(100vw - 2rem)); max-height: calc(100vh - 3rem);
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); box-shadow: 0 12px 40px var(--shadow);
}
dialog::backdrop { background: var(--shadow); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.1rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface);
}
.dialog-head h2 { margin: 0; }
#detail-body { padding: 0.5rem 1.1rem 1.25rem; }
.detail-value { font-family: var(--mono); font-size: 1rem; overflow-wrap: anywhere; margin: 0.75rem 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; }
.facts dt { color: var(--ink-2); font-size: 0.88rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
pre {
  margin: 0; padding: 0.75rem; overflow: auto; max-height: 22rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  font: 0.8rem/1.45 var(--mono);
}
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.danger-zone input { flex: 1 1 14rem; width: auto; }

/* ----------------------------------------------------------- exploration --- */
.explore { display: flex; flex-direction: column; gap: 0.75rem; transition: opacity 0.15s; }
.explore.loading { opacity: 0.5; }
.explore .grid { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr)); gap: 0.75rem; }
.chart-sub { margin: -0.25rem 0 0.6rem; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--ink-2); stroke-width: 1; }
.chart text { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--bar); transition: fill 0.1s; }
.chart .bar.is-hover, .chart .bar.is-selected { fill: var(--ink); }
.chart .hit { fill: transparent; }
.chart .hit.pickable { cursor: pointer; }
.chart .hit:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.chart .marker { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker-label { fill: var(--ink-2); }
.track > span { transition: width 0.35s ease; }
.chart .pickable { cursor: pointer; }
.chart polygon.gridline { fill: none; }
.chart .line { fill: none; stroke: var(--bar); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--bar); fill-opacity: 0.14; }
.chart .radar-area { fill: var(--bar); fill-opacity: 0.2; stroke: var(--bar); stroke-width: 2; stroke-linejoin: round; }
.chart .radar-dot { fill: var(--bar); stroke: var(--surface); stroke-width: 2; }
.chart .axis-label { fill: var(--ink-2); }
.chart.radar svg { max-width: 31rem; margin: 0 auto; }
.chart .slice { fill: var(--bar); stroke: var(--surface); stroke-width: 2; stroke-linejoin: round; }
.chart .slice.other { fill: var(--muted); fill-opacity: 0.4; }
.chart .slice:hover, .chart .slice:focus-visible, .chart .tm-cell:hover, .chart .tm-cell:focus-visible { stroke: var(--ink); outline: none; }
.chart .donut-total { fill: var(--ink); font: 600 22px var(--serif); }
.chart .tm-cell { fill: var(--bar); stroke: transparent; stroke-width: 2; }
.chart .tm-label { fill: var(--ink); font-weight: 600; pointer-events: none; }
.chart .tm-value { fill: var(--ink-2); pointer-events: none; }
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; }
.donut .chart { flex: 0 0 13rem; }
.donut .legend { flex: 1 1 14rem; grid-template-columns: 1fr max-content max-content; }
.swatch { display: inline-block; width: 0.7rem; height: 0.7rem; margin-right: 0.45rem; border-radius: 2px; background: var(--bar); vertical-align: baseline; }
.swatch.other { background: var(--muted); opacity: 0.4; }

/* Sélecteurs de forme : un groupe de boutons, l'actif en encre pleine. */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 0.75rem; }
.seg button { font: inherit; font-size: 0.82rem; padding: 0.25rem 0.65rem; border: 0; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { background: var(--surface-2); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.seg-row { display: flex; flex-wrap: wrap; gap: 0 0.6rem; }

.tip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 22rem;
  padding: 0.4rem 0.6rem; border-radius: var(--radius);
  background: var(--ink); color: var(--bg); font-size: 0.82rem; line-height: 1.35;
  box-shadow: 0 4px 14px var(--shadow);
}
.tip strong { display: block; font-size: 0.95rem; font-variant-numeric: tabular-nums; }

/* Carte de chaleur : une seule teinte, intensité = volume ; le nombre reste
   écrit dans chaque case. */
.heat { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: 0.82rem; }
.heat th { background: none; border: 0; padding: 0.25rem 0.4rem; font-weight: 400; color: var(--ink-2); }
.heat thead th { text-align: center; vertical-align: bottom; }
.heat tbody th { text-align: right; white-space: nowrap; }
.heat td { position: relative; border: 0; padding: 0; text-align: center; min-width: 3.2rem; height: 2.1rem; background: var(--track); border-radius: 4px; }
.heat td.zero { background: none; }
.heat td::before { content: ""; position: absolute; inset: 0; border-radius: 4px; background: var(--bar); opacity: var(--k, 0); }
.heat td button {
  position: relative; width: 100%; height: 100%; border: 0; background: none; cursor: pointer;
  font: inherit; color: var(--ink); font-variant-numeric: tabular-nums; border-radius: 4px;
}
.heat td button:hover, .heat td.is-selected button { outline: 2px solid var(--ink); outline-offset: -2px; }

.pick { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.pick:hover { text-decoration: underline; color: var(--ink); }
.pick[aria-pressed="true"] { color: var(--ink); font-weight: 700; }
.chips-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; min-height: 1.6rem; margin-bottom: 0.6rem; }
.chip.removable { cursor: pointer; font: inherit; font-size: 0.8rem; color: var(--ink); }
.chip.removable:hover { border-color: var(--ink-2); }

.filters label.narrow { min-width: 5rem; flex: 0 1 5.5rem; }
.export-url { margin-top: 0.25rem; font-size: 0.82rem; color: var(--ink-2); overflow-wrap: anywhere; }
.card p.small { margin: 0; color: var(--ink-2); }
.inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }

/* ------------------------------------------------------------------ graphe --- */
.graph-box { height: 72vh; min-height: 26rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; transition: opacity 0.15s; }
.graph-box.loading { opacity: 0.5; }
.graph { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
.graph .edge { stroke: var(--line); stroke-width: 1; }
.graph .edge-served-by { stroke: var(--ink-2); stroke-dasharray: 4 3; }
.graph .edge.lit { stroke: var(--ink); stroke-width: 1.6; }
.graph .gnode { cursor: pointer; outline: none; }
.graph .node-indicator { fill: var(--bar); stroke: var(--surface); stroke-width: 1.5; }
.graph .node-malware { fill: var(--ink); stroke: var(--surface); stroke-width: 2; }
.graph .node-source { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.graph .node-asn { fill: var(--surface-2); stroke: var(--ink-2); stroke-width: 2; }
.graph .gnode:focus-visible .node, .graph .gnode.lit .node { stroke: var(--ink); stroke-width: 2.5; }
.graph .node-label { fill: var(--ink-2); font: 11px var(--sans); pointer-events: none; }
.graph .gnode.lit .node-label { fill: var(--ink); font-weight: 700; }
.graph.dim .gnode:not(.lit), .graph.dim .edge:not(.lit) { opacity: 0.12; }
.legend-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1.25rem; margin: 0.25rem 0 0.5rem; font-size: 0.85rem; color: var(--ink-2); }
.lg { display: inline-block; width: 0.75rem; height: 0.75rem; margin-right: 0.4rem; vertical-align: -0.05rem; box-sizing: border-box; }
.lg-indicator { border-radius: 50%; background: var(--bar); }
.lg-malware { border-radius: 50%; background: var(--ink); }
.lg-source { border: 2px solid var(--ink); border-radius: 2px; background: var(--surface); }
.lg-asn { border: 2px solid var(--ink-2); background: var(--surface-2); transform: rotate(45deg) scale(0.85); }
label.inline { flex-direction: row; align-items: center; gap: 0.5rem; }
label.inline select { width: auto; }
select.cell-input.wide { width: 13rem; }

.badge { display: inline-block; min-width: 1.2rem; padding: 0 0.35rem; margin-left: 0.2rem; border-radius: 999px; background: var(--danger); color: var(--danger-fg); font-size: 0.72rem; font-weight: 700; text-align: center; line-height: 1.2rem; }
.title-row.spaced { margin-top: 2rem; }
.title-row.spaced h2 { margin: 0; flex: 1; }
.pill:empty { display: none; }
tr.acked td { color: var(--muted); }
.card p.small + p.small, .card p.small + .inline-actions { margin-top: 0.6rem; }

/* ------------------------------------------------- configuration de flux --- */
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 0.35rem; }
.settings-form { display: flex; flex-direction: column; gap: 1rem; max-width: 34rem; margin: 1rem 0; }
.settings-form .field { display: flex; flex-direction: column; gap: 0.25rem; }
.settings-form .field p { margin: 0; }
.settings-form label.check { padding-bottom: 0; }
.form-actions { display: flex; gap: 0.6rem; }

@media (max-width: 640px) {
  main { padding: 1rem 1rem 3rem; }
  .topbar { padding: 0.6rem 1rem; }
  .bars { grid-template-columns: minmax(5rem, max-content) 1fr max-content; }
}

.table-scroll { overflow-x: auto; }
