/* XJ Copro — styles natifs, thème clair/sombre */
:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel2: #f0f2f5; --text: #1d2330; --muted: #667085; --border: #dfe3ea;
  --accent: #2f6f5e; --accent-2: #e6f1ed; --accent-text: #ffffff;
  --danger: #b42318; --danger-bg: #fdecea; --warn: #9a6700; --warn-bg: #fff4d6; --ok: #2f7d32; --ok-bg: #e8f5e9; --info-bg: #eaf1fb; --info: #1d4f91;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #12151b; --panel: #1a1f27; --panel2: #222833; --text: #e6e9ef; --muted: #98a2b3; --border: #2e3542;
  --accent: #5fb39a; --accent-2: #1f3330; --accent-text: #0e1512;
  --danger: #f97066; --danger-bg: #3a1d1b; --warn: #fdb022; --warn-bg: #3a2e12; --ok: #6ce9a6; --ok-bg: #163322; --info-bg: #182a44; --info: #84adff;
  --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #12151b; --panel: #1a1f27; --panel2: #222833; --text: #e6e9ef; --muted: #98a2b3; --border: #2e3542;
    --accent: #5fb39a; --accent-2: #1f3330; --accent-text: #0e1512;
    --danger: #f97066; --danger-bg: #3a1d1b; --warn: #fdb022; --warn-bg: #3a2e12; --ok: #6ce9a6; --ok-bg: #163322; --info-bg: #182a44; --info: #84adff;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.45; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
p { margin: .4rem 0 .8rem; }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; height: 56px; padding: 0 1rem;
  background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand .logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); margin-right: .3rem; }
.copro-name { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.burger { display: none; cursor: pointer; font-size: 1.4rem; }
.sidebar { position: fixed; top: 56px; bottom: 0; left: 0; width: 230px; overflow-y: auto; padding: .8rem .6rem;
  background: var(--panel); border-right: 1px solid var(--border); }
.sidebar a { display: flex; justify-content: space-between; align-items: center; padding: .5rem .75rem; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.sidebar a:hover { background: var(--panel2); text-decoration: none; }
.sidebar a.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.pill { background: var(--danger); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .45rem; font-weight: 700; }
.main { margin-left: 230px; padding: 1.4rem 1.8rem 4rem; max-width: 1400px; }
.main-public { max-width: 420px; margin: 8vh auto; padding: 1rem; }
@media (max-width: 900px) {
  .burger { display: block; }
  .copro-name { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; z-index: 30; box-shadow: var(--shadow); }
  .navtoggle:checked ~ .sidebar { transform: none; }
  .main { margin-left: 0; padding: 1rem .8rem 4rem; }
}

/* Composants */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .8rem; margin-bottom: 1rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .82rem; color: var(--muted); }

.btn, button { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-size: .9rem; padding: .45rem .85rem; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover, button:hover { filter: brightness(1.07); text-decoration: none; }
.btn.secondary, button.secondary { background: var(--panel); color: var(--text); border-color: var(--border); }
.btn.danger, button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small, button.small { padding: .2rem .55rem; font-size: .8rem; }
button.ghost, a.ghost { background: transparent; color: var(--text); border: 1px solid transparent; padding: .35rem .6rem; }
button.ghost:hover, a.ghost:hover { background: var(--panel2); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; }
form.inline { display: inline; }

label { display: block; font-size: .85rem; font-weight: 600; margin: .55rem 0 .2rem; }
label.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
input, select, textarea { width: 100%; font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); }
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 90px; }
.form-row { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; background: var(--panel2); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.c, th.c { text-align: center; }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
tr.muted td { color: var(--muted); }
tbody tr:hover { background: var(--panel2); }
td input, td select { padding: .25rem .4rem; }

.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--panel2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.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); }
.badge.info { background: var(--info-bg); color: var(--info); }
.pos { color: var(--ok); } .neg { color: var(--danger); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.info { background: var(--info-bg); color: var(--info); }
.alert { padding: .7rem 1rem; border-radius: 8px; margin: .6rem 0; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.chart-box { position: relative; height: 280px; }
.qr { background: #fff; padding: 12px; border-radius: 8px; display: inline-block; }
.qr img, .qr svg { display: block; width: 200px; height: 200px; }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; padding-left: 2rem; position: relative; margin-bottom: .5rem; }
.steps li::before { content: counter(s); position: absolute; left: 0; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--accent-2); color: var(--accent); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
details summary { cursor: pointer; font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt0 { margin-top: 0; }
.photo-input { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.2rem; text-align: center; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); }
.login-card h1 { text-align: center; }
@media print { .sidebar, .topbar, .no-print, .flash { display: none !important; } .main { margin: 0; } }
@media (max-width: 600px) {
  .top-actions a.ghost { display: none; }
  .top-actions button.ghost { padding: .35rem .4rem; }
  .brand { font-size: .95rem; }
}
