:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #5d6b7a;
  --accent: #1f4e79;
  --accent-soft: #e8eff6;
  --ok: #1a7f52;
  --ok-soft: #e4f3ec;
  --warn: #9a6500;
  --warn-soft: #fbf1dc;
  --danger: #a32b2b;
  --danger-soft: #fae9e9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(18, 28, 40, .06), 0 4px 16px rgba(18, 28, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d;
    --surface: #1a212a;
    --surface-alt: #202934;
    --border: #2f3a47;
    --text: #e8edf3;
    --muted: #9babbb;
    --accent: #6fa8dc;
    --accent-soft: #1e2d3d;
    --ok: #5fcb98;
    --ok-soft: #16332a;
    --warn: #e0b35c;
    --warn-soft: #33290f;
    --danger: #ef8e8e;
    --danger-soft: #3a1f1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }

/* ------------------------------------------------------------- mise en page */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: .7rem 16px;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; margin-right: .5rem; }
.brand span { color: var(--muted); font-weight: 500; font-size: .85rem; display: block; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  padding: .4rem .7rem;
  border-radius: 7px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 550;
  font-size: .92rem;
}
.nav a:hover { background: var(--surface-alt); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.whoami { font-size: .85rem; color: var(--muted); text-align: right; }
.whoami strong { display: block; color: var(--text); }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.lede { color: var(--muted); max-width: 70ch; }

/* ------------------------------------------------------------------- blocs */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .85rem; }
.grid { display: grid; gap: 1rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.stat .value { font-size: 1.75rem; font-weight: 680; letter-spacing: -.02em; }
.stat .label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.stat.pending .value { color: var(--warn); }
.stat.approved .value { color: var(--ok); }
.stat.rejected .value { color: var(--danger); }

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

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .65rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-total td { font-weight: 650; border-top: 2px solid var(--border); background: var(--surface-alt); }

/* ------------------------------------------------------------------- badges */

.badge {
  display: inline-block; padding: .18rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border); }
.badge.demo { background: var(--accent-soft); color: var(--accent); }
.badge.lock { background: var(--surface-alt); color: var(--muted); }

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

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--border);
  padding: .5rem .9rem; background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; gap: .4rem;
}
button:hover, .btn:hover { background: var(--surface-alt); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(1.08); background: var(--ok); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-link { background: none; border: none; color: var(--accent); padding: .2rem; text-decoration: underline; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input, select, textarea {
  font: inherit; width: 100%; padding: .5rem .6rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[aria-invalid="true"] { border-color: var(--danger); }
textarea { min-height: 72px; resize: vertical; }
.field { margin-bottom: .85rem; }
.fields { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.filters { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }

/* ------------------------------------------------------------------ messages */

.notice { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; font-size: .92rem; }
.notice.error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.notice.success { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.notice.info { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; }

/* ----------------------------------------------------------- authentification */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 1.25rem; }

/* ------------------------------------------------------------------ journal */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--border); padding: 0 0 1rem 1rem; margin-left: .4rem; position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: -5px; top: .4rem;
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.timeline li.approved::before { background: var(--ok); }
.timeline li.rejected::before { background: var(--danger); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline .when { font-size: .82rem; color: var(--muted); }
.timeline .what { font-weight: 600; }
.quote { border-left: 3px solid var(--border); padding-left: .7rem; color: var(--muted); margin: .35rem 0 0; font-style: italic; }

/* ------------------------------------------------------------------- modale */

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
  background: var(--surface); color: var(--text); max-width: 460px; width: calc(100% - 32px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 16, 23, .55); }

.version-tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .9rem; }
.version-tabs a { padding: .3rem .65rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; font-size: .85rem; color: var(--muted); }
.version-tabs a.current { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.entry-row { border: 1px solid var(--border); border-radius: 8px; padding: .85rem; margin-bottom: .75rem; background: var(--surface-alt); }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .4rem; }
.days label { font-size: .75rem; text-align: center; }
.days input { text-align: center; padding: .4rem .2rem; }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .6rem; }

@media (max-width: 640px) {
  .topbar-inner { padding: .6rem 16px; }
  .whoami { text-align: left; }
  main { padding: 1rem 16px 3rem; }
  .days { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 8px; top: 8px; background: var(--surface); padding: .5rem; z-index: 50; border-radius: 6px; }

/* ------------------------------------------------------------ bandeau d'aperçu */

.preview-bar {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent);
  color: var(--accent);
  font-size: .9rem;
  position: sticky;
  top: 0;
  z-index: 19;
}
.preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  /* Aligné sur la largeur du contenu principal, sans conteneur supplémentaire. */
  padding: .6rem max(16px, calc((100% - 1180px) / 2));
}
.preview-bar button { border-color: var(--accent); color: var(--accent); background: var(--surface); }
