:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5d6673;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok: #1d7a46;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --danger: #b42318;
  --danger-bg: #fde8e6;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #191d23;
    --surface-2: #20252c;
    --border: #2d333b;
    --text: #e6e9ed;
    --muted: #9aa4b1;
    --accent: #6d93f2;
    --accent-text: #0d1117;
    --ok: #5cc98a;
    --ok-bg: #173323;
    --warn: #e8b34a;
    --warn-bg: #352a12;
    --danger: #f2796e;
    --danger-bg: #3a1a17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 0; }

/* ---------------------------------------------------------------- contrôles */

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.danger.primary { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.small { padding: 2px 8px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }

input[type="text"], input[type="password"], input[type="search"], select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 0;
}

label { font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

/* ---------------------------------------------------------------- connexion */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 28px;
}
.login-card h1 { margin: 4px 0 8px; }
.login-card .hint { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; }
.logo {
  width: 20px; height: 20px; border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
}

/* ---------------------------------------------------------------- structure */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--muted);
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.user { padding: 2px 10px; border-radius: 999px; background: var(--surface-2); margin-left: 8px; }

.view { max-width: 1200px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.section { padding: 16px 20px; margin-bottom: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { margin: 0; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 260px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.tile { padding: 16px 20px; }
.tile .label { color: var(--muted); font-size: 12.5px; }
.tile .value { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.tile .sub { color: var(--muted); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.grid-2 > .section { margin-bottom: 0; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- tableaux */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
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.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 4px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

.copy { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.copy code { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- formulaires */

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 160px; }
.field.wide { flex: 2 1 240px; }
.form-actions { margin-top: 10px; }
progress { width: 100%; margin-top: 12px; accent-color: var(--accent); }
input[type="file"] { padding: 4px 0; max-width: 100%; }

pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 6px;
  overflow-x: auto;
}

/* ---------------------------------------------------------------- dialogue */

.dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 32px rgb(0 0 0 / 25%);
}
.dialog::backdrop { background: rgb(0 0 0 / 40%); }
.dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { margin: 0; }
#dialog-body { display: flex; flex-direction: column; gap: 10px; }
#dialog-body p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------------------------------------------------------------- notifications */

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 16px rgb(0 0 0 / 20%);
  max-width: min(380px, calc(100vw - 32px));
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- petits écrans */

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .topbar-right { margin-left: auto; }
  #refreshed { display: none; }
  .view { padding: 16px; }
  .hide-sm { display: none; }
}
