:root {
  --bg: #0b0f16;
  --bg-soft: #111827;
  --card: #111a26;
  --card-2: #16202e;
  --border: #21303f;
  --text: #e6edf5;
  --muted: #8399ae;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --ok: #2ea043;
  --ko: #da3633;
  --warn: #d29922;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 21px; margin: 0; letter-spacing: -0.2px; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 10px; }

/* layout ------------------------------------------------------------------ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #0a121c;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff;
}
.brand strong { display: block; font-size: 14px; }
.brand small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 9px;
  color: #b8c7d9; font-size: 13.5px;
}
.nav a:hover { background: #131e2b; text-decoration: none; color: #fff; }
.nav a.active { background: #16263c; color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav .ico { width: 16px; text-align: center; color: var(--muted); font-size: 13px; }
.nav a.active .ico { color: var(--accent); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.who { display: flex; align-items: center; gap: 9px; }
.who strong { display: block; font-size: 12px; word-break: break-all; }
.who small { color: var(--muted); font-size: 11px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #1d2c3e; display: grid; place-items: center;
  font-weight: 600; font-size: 12px; color: #cfe1f5;
}

.main { flex: 1; padding: 22px 26px 40px; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.sub { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.client-switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.client-switch select { width: auto; padding: 5px 8px; }

.banner {
  background: #1d2a12; border: 1px solid #3d4d1f; color: #d6e6b8;
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 12.5px;
}
.banner code { color: #f0f6e0; }

.footer { margin-top: 26px; color: #56697e; font-size: 11.5px; }

/* cards ------------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-weight: 600; letter-spacing: 0.1px; }

.grid { display: grid; gap: 16px; }
.grid > .card { margin-bottom: 0; min-width: 0; }
.grid > .span-2 { grid-column: 1 / -1; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-stack { grid-template-columns: minmax(0, 1fr); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); margin-bottom: 16px; }

.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; }
.kpi-value { font-size: 25px; font-weight: 650; letter-spacing: -0.5px; }
.kpi-foot { color: var(--muted); font-size: 11.5px; }
.ok { color: var(--ok); }
.ko { color: var(--ko); }

.empty { text-align: center; padding: 44px 18px; }
.steps { margin: 0; padding-left: 18px; color: #c3d2e2; font-size: 13px; }
.steps li { margin-bottom: 8px; }

/* forms ------------------------------------------------------------------- */
label { display: block; font-size: 12.5px; color: #b8c7d9; margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%;
  margin-top: 5px;
  background: #0d1621;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
}
textarea { resize: vertical; line-height: 1.55; }
.stack textarea { margin-bottom: 8px; }
textarea.mono { font-family: var(--mono); font-size: 12px; line-height: 19px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #24446b; border-color: var(--accent); }
input[type=file] { color: var(--muted); font-size: 12px; margin-top: 5px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; margin: 0; }
.stack > * { display: block; }
.stack label { display: block; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.mode {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px;
  cursor: pointer; margin: 0; background: #0d1621; position: relative;
}
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode.selected, .mode:has(input:checked) { border-color: var(--accent); background: #10213a; }
.mode-name { display: block; font-weight: 600; color: var(--text); font-size: 13px; }
.mode-rate { display: block; color: var(--accent); font-size: 11.5px; font-family: var(--mono); }
.mode-desc { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input, .inline-form select { margin-top: 0; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form.wrap > * { flex: 1 1 140px; }

/* buttons ----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; border: 1px solid transparent;
  padding: 8px 14px; font-size: 13px; font-weight: 550; cursor: pointer;
  background: #1b2836; color: var(--text); font-family: inherit;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn-primary { background: var(--accent-2); color: #fff; }
.btn-danger { background: #3a1d1d; color: #ffb4ae; border-color: #5a2b2b; }
.btn-ghost { background: transparent; border-color: var(--border); color: #c3d2e2; }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-actions form { display: inline; margin: 0; }

/* tables ------------------------------------------------------------------ */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); font-weight: 600; padding: 7px 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 9px 8px; border-bottom: 1px solid #192534; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #0f1924; }
.table-compact td { padding: 6px 8px; font-size: 12.5px; }
/* les tableaux denses (admin) peuvent déborder sur les écrans étroits */
.card > .table, .card > .log-list { max-width: 100%; }
.card:has(> .table) { overflow-x: auto; }
.row-actions { flex-wrap: nowrap; }
.row-actions .btn-sm { white-space: nowrap; }
.w-progress { min-width: 130px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
  background: #1b2836; color: #b8c7d9;
}
.badge-running, .badge-sent { background: #10321b; color: #6ee787; }
.badge-queued, .badge-pending { background: #1f2a3c; color: #9cc4ff; }
.badge-paused { background: #33280e; color: #e3b341; }
.badge-failed { background: #3a1d1d; color: #ff9c95; }
.badge-done { background: #1a2740; color: #a9c7f5; }
.badge-canceled, .badge-skipped { background: #22262b; color: #94a3b3; }
.tag { font-size: 10px; background: #24243a; color: #b0a8f0; padding: 1px 6px; border-radius: 5px; }
.pill { font-size: 11px; padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border); }
.pill-warn { background: #33280e; color: #e3b341; border-color: #4d3b12; }
.pill-live { background: #10321b; color: #6ee787; border-color: #1c502c; }

/* progress ---------------------------------------------------------------- */
.progress { height: 6px; background: #16212e; border-radius: 4px; overflow: hidden; margin-bottom: 4px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), #58a6ff); transition: width .4s ease; }
.progress-lg { height: 10px; margin: 6px 0 12px; }
.progress-legend { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-ok { background: var(--ok); }
.dot-ko { background: var(--ko); }
.dot-idle { background: #3b82f6; }
.dot-skip { background: #64748b; }

/* charts ------------------------------------------------------------------ */
.chart { width: 100%; height: 170px; }
.chart-lg { height: 220px; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .bar-sent { fill: #2f81f7; }
.chart .bar-failed { fill: #da3633; }
.chart .axis { stroke: #21303f; stroke-width: 1; }
.chart .label { fill: #6b8299; font-size: 9px; font-family: var(--mono); }
.chart .empty-note { fill: #56697e; font-size: 11px; }

/* misc -------------------------------------------------------------------- */
.alert { padding: 10px 13px; border-radius: 9px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #3a1d1d; color: #ffb4ae; border: 1px solid #5a2b2b; }
.message-preview {
  background: #0d1621; border: 1px solid var(--border); border-radius: 9px;
  padding: 12px 14px; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 12.5px; color: #d5e4f5; margin: 0 0 12px;
}
.meta-list { list-style: none; padding: 0; margin: 0; color: var(--muted); font-size: 12.5px; }
.meta-list li { padding: 4px 0; border-bottom: 1px dashed #1b2836; }
.meta-list li strong { color: var(--text); }
.counter { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.counter.over { color: var(--warn); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 14px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.link { color: var(--accent); }

.log-list { max-height: 430px; overflow: auto; font-size: 12px; }
.log-row { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid #16212e; }
.log-time { color: #5f7488; flex: 0 0 108px; }
.log-msg { color: #c3d2e2; word-break: break-word; }
.log-error .log-msg { color: #ff9c95; }
.probe-result {
  background: #0d1621; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-family: var(--mono); font-size: 11.5px; color: #9fb6cc;
  margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; min-height: 34px;
}

/* auth -------------------------------------------------------------------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(circle at 50% 0%, #16243a 0%, #0b0f16 55%); }
.auth-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 26px 26px 20px; box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.brand-lg { padding: 0 0 18px; }
.auth-card h2 { margin: 0 0 14px; font-size: 16px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: relative; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { flex-direction: row; align-items: center; justify-content: space-between; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .grid > .span-2 { grid-column: auto; }
  .main { padding: 16px; }
}
