:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d8dde6;
  --border-soft: #e5e5e5;
  --text: #1c1c1c;
  --muted: #666;
  --primary: #1f4b99;
  --primary-soft: #eef2f8;
  --zebra: #f5f7fb;
  --cumul: #e8edf5;
  --danger: #9b1c1c;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

header.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

header.app-header h1 {
  font-size: 1.35rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.card, form.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="date"],
input[type="text"],
input[type="password"],
select,
button,
.btn {
  font: inherit;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

button,
.btn {
  background: var(--primary);
  color: #fff;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button:hover,
.btn:hover { filter: brightness(1.06); }

button.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}

button.secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.err { color: var(--danger); margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13px; }

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.chip:hover { border-color: var(--primary); color: var(--primary); }

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.filters .field { min-width: 120px; }

.filters .dates-group.hidden { display: none; }
.dates-inner { gap: 12px; }
.hint-export { margin: 12px 0 0; }
.flash-err, .flash-note, .table-wrap { margin-top: 12px; }
.login-form { margin-top: 16px; }

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

button:disabled,
.btn-afficher:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.btn-afficher.is-ready {
  box-shadow: 0 0 0 2px rgba(31, 75, 153, 0.25);
}

/* Multi-select (SC + mots-clés) */
.ms-wrap { position: relative; min-width: 220px; }

.ms-trigger {
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.ms-trigger .badge {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}

.ms-panel {
  display: none;
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 280px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(31, 75, 153, 0.12);
  padding: 10px;
}

.ms-panel.open { display: block; }

.ms-panel .ms-search {
  width: 100%;
  margin-bottom: 8px;
}

.ms-panel .ms-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.ms-panel .ms-tools button {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  background: var(--primary-soft);
  color: var(--primary);
}

.ms-list {
  max-height: 260px;
  overflow: auto;
  border-top: 1px solid var(--border-soft);
  padding-top: 6px;
}

.ms-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
}

.ms-item:hover { background: var(--primary-soft); }
.ms-item.hidden { display: none; }

.ms-item .pct {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ms-item .mo {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* Detail toggle */
.toggle-field { min-width: 140px; }
.toggle-label { margin-bottom: 6px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  margin: 0;
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-ui {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #c5cdd8;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.15s ease;
}
.toggle input:checked + .toggle-ui {
  background: var(--primary);
}
.toggle input:checked + .toggle-ui::after {
  transform: translateX(18px);
}
.toggle-text { font-size: 13px; }

.scroll {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
}

th, td {
  border-bottom: 1px solid var(--border-soft);
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th {
  position: sticky;
  top: 0;
  background: var(--primary-soft);
  z-index: 2;
  font-weight: 600;
  padding: 0;
}

.th-sort {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.th-sort:hover {
  background: rgba(31, 75, 153, 0.08);
  filter: none;
}

.th-ind {
  display: inline-block;
  width: 0.65em;
  color: var(--primary);
  opacity: 0.35;
  font-size: 11px;
  line-height: 1;
}

.th-ind::before { content: "⇅"; }

th.sorted .th-ind { opacity: 1; }
th.sorted.asc .th-ind::before { content: "▲"; }
th.sorted.desc .th-ind::before { content: "▼"; }

th.sorted {
  background: #e2e8f3;
}

tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:hover { background: #e9eef7; }

.login-wrap {
  max-width: 380px;
  margin: 48px auto;
}

.login-wrap h1 { margin-bottom: 8px; }

@media (max-width: 720px) {
  .shell { padding: 12px; }
  .ms-wrap { min-width: 100%; }
  .ms-panel { right: auto; width: min(100vw - 32px, 320px); }
}
