:root {
  --red: #c8102e; --red-dark: #9e0c24; --ink: #1f2328; --muted: #6b7280; --line: #e5e7eb;
  --bg: #f4f5f7; --card: #fff; --side: #1c1f24; --side-ink: #c9ced6;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7; --err: #b91c1c; --err-bg: #fee2e2; --info-bg: #e0f2fe; --info: #075985;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--red); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .25rem; } h2 { font-size: 1.15rem; margin: 0 0 .75rem; } h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; }
.right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }

/* ---- layout admin ---- */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: block; padding: 4px 10px 18px; color: #fff; font-weight: 800; letter-spacing: .5px; line-height: 1.1; }
.brand span { color: var(--red); display: block; font-size: 1.2rem; } .brand small { display:block; color: var(--side-ink); font-weight: 400; font-size: .75rem; margin-top: 4px; letter-spacing: 0; }
.side nav a { display: flex; gap: 10px; align-items: center; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; margin-bottom: 2px; }
.side nav a:hover { background: #2a2f36; text-decoration: none; color: #fff; }
.side nav a.active { background: var(--red); color: #fff; }
.side nav .sep { border-top: 1px solid #2f343c; margin: 10px 4px; }
.side .who { margin-top: 20px; padding: 10px; font-size: .8rem; border-top: 1px solid #2f343c; }
.side .who button { background: none; border: 0; color: var(--side-ink); padding: 0; cursor: pointer; text-decoration: underline; font: inherit; }
.main { padding: 26px 32px 60px; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; } .crumbs a { color: var(--muted); }
.btn.menu-toggle { display: none; }

/* ---- composants ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; } .card.flush > h2 { padding: 16px 20px 0; }
.grid { display: grid; gap: 18px; } .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)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 1.7rem; font-weight: 700; line-height: 1.2; } .kpi .l { color: var(--muted); font-size: .85rem; }
.kpi.red .v { color: var(--red); } .kpi.ok .v { color: var(--ok); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--red); color: #fff; border-color: var(--red); } .btn.primary:hover { background: var(--red-dark); }
.btn.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { color: var(--err); border-color: #fecaca; } .btn.danger:hover { background: var(--err-bg); }
.btn.sm { padding: 4px 10px; font-size: .85rem; } .btn.lg { padding: 12px 20px; font-size: 1.05rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--red); cursor: pointer; font: inherit; }
form.inline { display: inline; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafafa; white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
table.t tr:hover td { background: #fcfcfd; }
table.t tr.cancelled td { color: var(--muted); text-decoration: line-through; }
table.t tfoot td { font-weight: 700; background: #fafafa; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge.ok, .badge.sent, .badge.open { background: var(--ok-bg); color: var(--ok); }
.badge.error, .badge.cancelled, .badge.invalid, .badge.wrong_event { background: var(--err-bg); color: var(--err); }
.badge.pending, .badge.queued, .badge.sending, .badge.already, .badge.closed { background: var(--warn-bg); color: var(--warn); }
.badge.no_email, .badge.archived, .badge.reset { background: #e5e7eb; color: #4b5563; }
.progress { height: 8px; background: #eef0f3; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.flash.success { background: var(--ok-bg); color: var(--ok); border-color: #bbf7d0; } .flash.error { background: var(--err-bg); color: var(--err); border-color: #fecaca; } .flash.info { background: var(--info-bg); color: var(--info); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---- formulaires ---- */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; } .field .hint { font-size: .8rem; color: var(--muted); margin-top: 3px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200,16,46,.25); border-color: var(--red); }
textarea { min-height: 120px; resize: vertical; } textarea.code { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; min-height: 280px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; } .check input { width: auto; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; } .filters > * { flex: 0 1 auto; } .filters input[type=search] { min-width: 240px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.active { color: var(--red); border-color: var(--red); } .tabs a:hover { text-decoration: none; color: var(--ink); }
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; } dl.info dt { color: var(--muted); } dl.info dd { margin: 0; font-weight: 500; }
.thumb { max-width: 100%; max-height: 220px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---- barres (stats) ---- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.bars .b { flex: 1 0 18px; background: var(--red); border-radius: 3px 3px 0 0; position: relative; min-height: 2px; }
.bars .b:hover { background: var(--red-dark); }
.bars-labels { display: flex; gap: 3px; font-size: .7rem; color: var(--muted); overflow: hidden; } .bars-labels span { flex: 1 0 18px; writing-mode: vertical-rl; transform: rotate(180deg); height: 70px; }

/* ---- page de contrôle ---- */
.scan-input { font-size: 1.3rem !important; padding: 14px !important; letter-spacing: 1px; }
.scan-result { border-radius: 14px; padding: 26px; text-align: center; color: #fff; min-height: 190px; display: flex; flex-direction: column; justify-content: center; transition: background .15s; background: #9ca3af; }
.scan-result .big { font-size: 2.2rem; font-weight: 800; } .scan-result .who { font-size: 1.3rem; margin-top: 6px; } .scan-result .det { opacity: .9; margin-top: 4px; }
.scan-result.ok { background: #16a34a; } .scan-result.already { background: #d97706; } .scan-result.invalid, .scan-result.wrong_event, .scan-result.cancelled { background: #dc2626; }
#camera { width: 100%; max-width: 420px; border-radius: 10px; overflow: hidden; }

/* ---- connexion / espace client ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #24282e 0%, #111 60%); }
.auth .card { width: 100%; max-width: 410px; padding: 28px; }
.logo-text { font-weight: 900; letter-spacing: .5px; line-height: 1; font-size: 1.4rem; color: #444; text-align: center; margin-bottom: 18px; } .logo-text span { color: var(--red); display: block; font-size: 1.7rem; }
.portal-head { background: #fff; border-bottom: 1px solid var(--line); }
.portal-head .in { max-width: 960px; margin: auto; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.portal-head .logo-text { margin: 0; text-align: left; font-size: 1rem; } .portal-head .logo-text span { font-size: 1.25rem; }
.portal { max-width: 960px; margin: auto; padding: 24px 20px 60px; }
.ticket-card { display: grid; grid-template-columns: 1fr auto; gap: 16px; }
.qr-list { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.qr-list figure { margin: 0; text-align: center; font-size: .8rem; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; }
.qr-list img { width: 128px; height: 128px; display: block; } .qr-list figure.used { opacity: .45; }
details summary { cursor: pointer; font-weight: 600; color: var(--red); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .btn.menu-toggle { display: inline-flex; margin-bottom: 12px; }
  .main { padding: 16px 16px 50px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .ticket-card { grid-template-columns: 1fr; }
}
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .filters input[type=search] { min-width: 0; width: 100%; } }
.filters input:not([type=checkbox]):not([type=radio]), .filters select { width: auto; max-width: 100%; }
.filters > div { display: flex; flex-direction: column; }
