:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #17212b;
  --muted: #5d6b78;
  --border: #dde3e8;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #e3f3f1;
  --ok: #157347;
  --ok-soft: #e4f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1418;
    --surface: #171e24;
    --surface-2: #1c252c;
    --text: #e6edf2;
    --muted: #9aa8b4;
    --border: #2b3640;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --accent-soft: #123b37;
    --ok: #4ade80;
    --ok-soft: #143222;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --bad: #f87171;
    --bad-soft: #3d1715;
    --focus: #60a5fa;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1418;
  --surface: #171e24;
  --surface-2: #1c252c;
  --text: #e6edf2;
  --muted: #9aa8b4;
  --border: #2b3640;
  --accent: #2dd4bf;
  --accent-text: #062b27;
  --accent-soft: #123b37;
  --ok: #4ade80;
  --ok-soft: #143222;
  --warn: #fbbf24;
  --warn-soft: #3a2c0c;
  --bad: #f87171;
  --bad-soft: #3d1715;
  --focus: #60a5fa;
  --shadow: none;
}

* { box-sizing: border-box; }

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

h1, h2 { margin: 0 0 .25rem; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }

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

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .5rem .9rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { filter: brightness(1.07); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.small { padding: .25rem .6rem; font-size: .85rem; font-weight: 500; }
button.danger { background: var(--bad); color: #fff; }
button.link { background: none; border: 0; padding: .2rem .35rem; color: var(--accent); font-weight: 500; }
button.link.danger { color: var(--bad); background: none; }

input, select {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
select { padding: .35rem .4rem; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted, .hint { color: var(--muted); }
.hint { font-size: .88rem; margin: .15rem 0 .6rem; }
.error { color: var(--bad); min-height: 1.2em; margin: .5rem 0 0; font-size: .9rem; }
.empty { color: var(--muted); text-align: center; padding: 1rem; margin: 0; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.brand .sub { color: var(--muted); font-weight: 500; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
}

main { max-width: 1200px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 16px;
  min-width: 0;
}
.login { max-width: 380px; margin: 10vh auto; }
.login form { display: grid; gap: .5rem; }
.login button { margin-top: .4rem; }
label { font-size: .9rem; font-weight: 600; }

.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-weight: 500;
}
.tabs button[aria-current="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

.banner {
  border-radius: var(--radius);
  padding: .7rem .9rem;
  margin: 0 0 12px;
  background: var(--warn-soft);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: .92rem;
}
.banner.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.banner code { font-size: .85em; }

.section-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .6rem; }
.section-head .hint { margin: 0; flex-basis: 100%; }
.tools { display: flex; gap: .5rem; flex-wrap: wrap; }
.tools input { width: 240px; max-width: 100%; }
.count { color: var(--muted); font-weight: 500; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }

.tel { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; white-space: nowrap; }
.row-actions { white-space: nowrap; text-align: right; }

.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.why { display: block; font-size: .8rem; color: var(--muted); margin-top: .15rem; max-width: 22ch; }

.sect-list { margin: 0; padding: 0; list-style: none; font-size: .9rem; }
.sect-list .days { color: var(--muted); }
.none { color: var(--warn); font-size: .88rem; }

.grid th:first-child, .grid td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 150px; }
.grid tbody tr:hover td:first-child { background: var(--surface-2); }
.grid td { padding: .35rem .3rem; }
.grid select { min-width: 110px; font-size: .86rem; }
.grid select.empty-day { border-style: dashed; color: var(--muted); }
.grid select.saving { opacity: .5; }
.grid .week select { border-color: var(--accent); }
.grid .sect-name { display: block; }
.grid .load { display: block; font-size: .78rem; color: var(--muted); margin-top: .1rem; }
.grid .load.none { color: var(--warn); }
.grid tr.no-circuit td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols .card { margin-bottom: 0; }

.inline { display: flex; gap: .5rem; }
.lookup { margin-top: .75rem; font-size: .92rem; }
.lookup .verdict { font-weight: 600; margin: 0 0 .35rem; }
.lookup ul { margin: 0; padding-left: 1.1rem; color: var(--muted); }

.audit { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; font-size: .88rem; }
.audit li { padding: .45rem 0; border-bottom: 1px solid var(--border); }
.audit time { color: var(--muted); font-size: .8rem; display: block; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
  width: min(440px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog form { display: grid; gap: .35rem; }
dialog h2 { margin-bottom: .5rem; }
dialog .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; }
#confirm-body ul { margin: .3rem 0; padding-left: 1.1rem; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: .6rem 1rem;
  border-radius: 8px;
  font-size: .92rem;
  max-width: calc(100vw - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .cols { grid-template-columns: 1fr; }
  .brand .sub { display: none; }
  .tools { width: 100%; }
  .tools input { flex: 1; width: auto; }

  /* Tableau des chefs en cartes */
  table.chefs thead { display: none; }
  table.chefs, table.chefs tbody, table.chefs tr, table.chefs td { display: block; width: 100%; }
  table.chefs tr { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; margin-bottom: .6rem; }
  table.chefs td { border: 0; padding: .2rem 0; }
  table.chefs td.name { font-weight: 600; }
  table.chefs .row-actions { text-align: left; }
  .why { max-width: none; }
}
