:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #222b37;
  --border: #2c3744;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); margin-top: 8px; white-space: pre-wrap; }
.small { max-width: 120px; }
#run-maxtokens { max-width: 190px; }
.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}
.chk input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

input, button {
  font-family: inherit;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
input {
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 11px;
}
input:focus { outline: 1px solid var(--accent); }

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--accent-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.ghost:hover { background: var(--panel-2); }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* ---- App ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 10px 18px;
  font-weight: 600;
}
.tab.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
}

.panel { display: none; padding: 20px; }
.panel.active { display: block; }

.row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.row input[type=text]:not(.small) { flex: 1; min-width: 220px; }

/* ---- Cards / tables ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.pending { background: #334155; color: #cbd5e1; }
.badge.running { background: #1e3a8a; color: #bfdbfe; }
.badge.success { background: #14532d; color: #bbf7d0; }
.badge.error   { background: #7f1d1d; color: #fecaca; }
.badge.cancelled { background: #422006; color: #fed7aa; }
.badge.v       { background: var(--panel-2); color: var(--muted); }

/* Boutons d'action compacts dans les tables */
td.actions { display: flex; gap: 8px; }
td.actions button { padding: 6px 12px; }
button.ghost.danger { color: #fca5a5; border-color: #7f1d1d; }
button.ghost.danger:hover { background: #2a1414; }

/* Bouton Stopper dans l'en-tete d'un job */
.btn-stop { margin-left: auto; padding: 6px 12px; color: #fca5a5; border-color: #7f1d1d; }
.btn-stop:hover { background: #2a1414; }

/* ---- Job logs ---- */
.job { margin-bottom: 18px; }
.job-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.logs {
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: #c9d4e0;
}
.logs .err { color: var(--red); }

.step-pills { display: flex; gap: 6px; margin: 8px 0; }
.pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.pill.done { background: #14532d; color: #bbf7d0; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: min(900px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: transparent; color: var(--muted);
  font-size: 22px; line-height: 1; padding: 4px 10px;
}
.modal-close:hover { background: var(--panel-2); }

.kpis { display: flex; gap: 18px; flex-wrap: wrap; margin: 4px 0 14px; }
.kpi { background: var(--panel-2); border-radius: 10px; padding: 10px 14px; }
.kpi .v { font-size: 18px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--muted); }

pre.json {
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
}

/* ---- Reconsolidation ---- */
.cons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.cons-col h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.hint { font-size: 12px; margin: 8px 0 0; }

/* ---- Screener ---- */
.screener { display: flex; gap: 16px; align-items: flex-start; }
.screener-side {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  position: sticky;
  top: 12px;
}
.screener-side-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.small-btn { padding: 6px 10px; font-size: 12px; }
.screener-mode { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.screener-mode select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px;
}
.screener-filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.screener-main { flex: 1; min-width: 0; }
.screener-status { margin-bottom: 10px; }

.filt-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.filt-head { display: flex; justify-content: space-between; align-items: center; }
.filt-meta { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.filt-rm {
  background: transparent; color: var(--muted);
  padding: 0 6px; font-size: 16px; line-height: 1;
}
.filt-rm:hover { background: transparent; color: var(--red); }
.filt-name { font-size: 13px; font-weight: 600; margin: 4px 0 8px; }
.filt-slider { display: flex; align-items: center; gap: 8px; }
.filt-slider input[type=range] { flex: 1; accent-color: var(--accent); }
.filt-val { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }

/* ---- Filtre modal: dimensions + arbre ---- */
.filter-dims { display: flex; gap: 6px; margin: 12px 0; }
.dim-tab {
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; font-size: 13px;
}
.dim-tab.active { color: var(--text); background: var(--accent); border-color: var(--accent); }
#filter-search { width: 100%; margin-top: 4px; }
.filter-tree {
  max-height: 50vh; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; background: #0b0f14;
}
.ftnode { user-select: none; }
.ftrow { display: flex; align-items: center; padding: 3px 4px; border-radius: 6px; }
.ftrow:hover { background: var(--panel-2); }
.fttoggle {
  width: 16px; text-align: center; cursor: pointer; color: var(--muted);
  font-size: 9px; flex-shrink: 0; transition: transform .15s;
}
.fttoggle.open { transform: rotate(90deg); }
.fttoggle.leaf { visibility: hidden; }
.ftlabel { flex: 1; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ftadd {
  background: transparent; border: 1px solid var(--border); color: var(--accent);
  padding: 1px 9px; font-size: 14px; border-radius: 6px; line-height: 1.3;
}
.ftadd:hover { background: var(--accent); color: #fff; }
.ftchildren { padding-left: 16px; }
.ftchildren.collapsed { display: none; }

/* ---- Portefeuille ---- */
.pf-layout { display: flex; gap: 18px; align-items: flex-start; }
.pf-build { width: 420px; flex-shrink: 0; }
.pf-charts { flex: 1; min-width: 0; }
.pf-save-row { margin-top: 16px; }
.pf-w { width: 80px; padding: 5px 8px; text-align: right; }
.pf-build td.actions button { padding: 4px 9px; }

.pies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.pie-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.pie-card h4 { margin: 0 0 10px; font-size: 14px; }
.pie-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.pie-card-head h4 { margin: 0; }
.pie-expand {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; line-height: 1; padding: 3px 8px; cursor: pointer;
  flex-shrink: 0;
}
.pie-expand:hover { background: var(--panel-2); color: var(--text); }
.pie-body { display: flex; gap: 12px; align-items: center; }
.pie-svg { width: 150px; height: 150px; flex-shrink: 0; }
.pie-legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; max-height: 160px; overflow-y: auto; }
.pie-leg-row { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.pie-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.pie-leg-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.pie-leg-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- Camembert plein écran ---- */
.pie-fs h2 { margin: 0 0 18px; }
.pie-fs-body {
  display: flex; gap: 32px; align-items: center; flex-wrap: wrap;
  justify-content: center;
}
.pie-fs-svg {
  width: min(48vh, 480px); height: min(48vh, 480px);
  flex-shrink: 0;
}
.pie-fs-legend {
  flex: 1; min-width: 240px; max-width: 420px;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 70vh; overflow-y: auto;
}
.pie-fs-legend .pie-leg-row { font-size: 15px; gap: 10px; }
.pie-fs-legend .pie-dot { width: 14px; height: 14px; border-radius: 3px; }

/* ---- Interactivité des camemberts ---- */
.pie-slice { transition: opacity .12s ease, transform .12s ease; transform-origin: 80px 80px; }
.pie-slice.dim { opacity: .3; }
.pie-clickable { cursor: pointer; }
.pie-leg-row.pie-clickable:hover { color: var(--text); }
.pie-leg-row.hot { background: var(--panel-2); border-radius: 5px; }
.pie-leg-row.hot .pie-leg-label { color: var(--text); }

.pie-tip {
  position: fixed; z-index: 200; pointer-events: none;
  background: #0f172a; color: #f8fafc;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12.5px; line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); max-width: 260px;
}
.pie-tip-cta { margin-top: 3px; font-size: 11px; color: #93c5fd; }

/* ---- Détail des contributions d'une part ---- */
.contrib-view h2 { margin: 0 0 6px; }
.contrib-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.contrib-table th, .contrib-table td {
  padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.contrib-table th.num, .contrib-table td.num { text-align: right; }
.contrib-table td.num { font-variant-numeric: tabular-nums; }
.share-num { display: inline-block; min-width: 46px; }
.share-bar {
  display: inline-block; width: 90px; height: 8px; margin-left: 8px;
  background: var(--panel-2); border-radius: 4px; overflow: hidden; vertical-align: middle;
}
.share-bar > span { display: block; height: 100%; background: var(--accent, #3b82f6); }

