/* ===== Défi Km – pages publiques (saisie, accueil) et administration ===== */
:root {
    --primary: #E61C51;
    --primary-dark: #b8123e;
    --accent: #FF8216;
    --ink: #1f2430;
    --muted: #667085;
    --line: #e4e7ec;
    --bg: #f4f7fb;
    --card: #ffffff;
    --ok: #1f9d55;
    --warn: #b54708;
    --danger: #d92d20;
    --radius: 12px;
    --font: 'Poppins', Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.5; font-size: 15px; }
a { color: var(--primary); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: clamp(24px, 4vw, 34px); }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
small, .muted { color: var(--muted); }
code { background: #eef2f6; padding: 1px 6px; border-radius: 4px; font-size: .9em; word-break: break-all; }

/* ---------- Composants ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04); padding: 20px; margin-bottom: 18px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 9px; border: 1px solid transparent; font: inherit; font-weight: 600;
    background: var(--primary); color: #fff; cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: #f2f4f7; }
.btn.danger { background: #fff; color: var(--danger); border-color: #fda29b; }
.btn.danger:hover { background: #fef3f2; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 14px 22px; font-size: 18px; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .help { font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url],
input[type=datetime-local], input[type=color], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid #d0d5dd; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input[type=color] { padding: 2px; height: 40px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(230, 28, 81, .35); border-color: var(--primary); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.alert { padding: 11px 14px; border-radius: 9px; margin-bottom: 14px; border: 1px solid; }
.alert.success { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.alert.error { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.alert.warning { background: #fffaeb; border-color: #fedf89; color: var(--warn); }
.alert.info { background: #eff8ff; border-color: #b2ddff; color: #175cd3; }

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f9fafb; }
.table tr.deleted td { color: #98a2b3; text-decoration: line-through; }
.table-wrap { overflow-x: auto; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f2f4f7; color: #344054; }
.badge.active { background: #ecfdf3; color: #067647; }
.badge.draft { background: #fffaeb; color: var(--warn); }
.badge.archived { background: #f2f4f7; color: #667085; }
.badge.demo { background: #f4ebff; color: #6941c6; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

/* ---------- Saisie des km (mobile d'abord) ---------- */
.encode-page { min-height: 100vh; background: linear-gradient(180deg, #87cdee 0%, #d9eef8 45%, var(--bg) 100%); padding: 18px 0 40px; }
.encode-head { text-align: center; margin-bottom: 16px; }
.encode-head .logos { display: flex; justify-content: center; align-items: center; gap: 18px; margin-bottom: 10px; }
.encode-head .logos img { max-height: 70px; max-width: 45%; object-fit: contain; }
.encode-head h1 { color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, .25); margin: 0; }
.encode-head p { margin: 4px 0 0; color: #0b3b52; font-weight: 600; }
.team-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.team-picker label { margin: 0; }
.team-picker input { position: absolute; opacity: 0; pointer-events: none; }
.team-picker .opt {
    display: flex; align-items: center; gap: 8px; padding: 10px; border: 2px solid var(--line); border-radius: 10px;
    background: #fff; cursor: pointer; font-weight: 600; min-height: 56px;
}
.team-picker .opt img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; padding: 3px; }
.team-picker input:checked + .opt { border-color: var(--primary); background: #fff0f4; }
.team-picker input:focus-visible + .opt { outline: 2px solid var(--primary); }
.km-input { display: flex; align-items: center; gap: 10px; }
.km-input input { font-size: 30px; font-weight: 800; text-align: center; padding: 12px; }
.km-input span { font-size: 22px; font-weight: 700; }
.team-info { background: #f2f8fc; border-radius: 9px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.result { text-align: center; }
.result .big { font-size: 40px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.history ul { list-style: none; margin: 0; padding: 0; }
.history .edit-row { display: flex; gap: 6px; }
.history .edit-row input { width: 110px; }
dialog { border: 0; border-radius: 14px; padding: 22px; max-width: 420px; width: calc(100% - 32px); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .5); }

/* ---------- Accueil ---------- */
.home-hero { background: linear-gradient(180deg, #87cdee, #d9eef8); padding: 50px 0 40px; text-align: center; }
.home-hero img.brand { width: min(240px, 60vw); }
.home-hero h1 { font-size: clamp(30px, 5vw, 48px); margin: 16px 0 6px; }
.home-hero p { font-size: 18px; color: #234; max-width: 640px; margin: 0 auto 22px; }
.features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin: 30px 0; }
.container.wide { max-width: 1180px; }
.features .card { padding: 24px 26px; margin: 0; font-size: 16px; }
@media (max-width: 1000px) { .features { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .features { grid-template-columns: 1fr; } }
.features .card h3 { color: var(--primary); }

/* ---------- Administration ---------- */
.admin-top { background: #101828; color: #fff; }
.admin-top .container { display: flex; align-items: center; gap: 18px; min-height: 58px; flex-wrap: wrap; }
.admin-top a { color: #d0d5dd; text-decoration: none; font-weight: 600; font-size: 14px; }
.admin-top a:hover, .admin-top a.on { color: #fff; }
.admin-top .brand { color: #fff; font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.admin-top .brand img { width: 28px; }
.admin-top nav { display: flex; gap: 16px; flex-wrap: wrap; flex: 1; }
.admin-top form { margin: 0; }
.admin-top .who { font-size: 13px; color: #98a2b3; }
.admin-main { padding-top: 24px; padding-bottom: 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }
.challenge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.challenge-card { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.challenge-card .logo { height: 54px; display: flex; align-items: center; }
.challenge-card .logo img { max-height: 54px; max-width: 160px; object-fit: contain; }
.challenge-card h3 { margin: 0; }
.challenge-card .links { margin-top: auto; }
.inline-form { display: inline; margin: 0; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.thumb { border: 2px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; cursor: pointer; display: block; margin: 0; font-weight: 600; }
.thumb input { margin-right: 6px; }
.thumb:has(input:checked) { border-color: var(--primary); background: #fff0f4; }
.thumb .imgs { display: flex; gap: 4px; align-items: flex-end; height: 70px; margin-bottom: 6px; overflow: hidden; }
.thumb .imgs img { height: 60px; width: auto; }
.thumb .decor-img { height: 70px; width: 100%; object-fit: cover; object-position: left center; border-radius: 6px; margin-bottom: 6px; }
.logo-preview { max-height: 70px; max-width: 220px; background: #f2f4f7; padding: 6px; border-radius: 8px; }
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.qr-card { text-align: center; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff; break-inside: avoid; }
.qr-card .qr { display: flex; justify-content: center; margin: 10px 0; }
.qr-card .url { font-size: 11px; word-break: break-all; color: var(--muted); }
.calib { position: relative; overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 70vh; background: #eee; }
.calib-inner { position: relative; transform-origin: 0 0; }
.calib img { display: block; width: 100%; }
.calib .mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--primary); }
.calib .mark.end { background: #1f9d55; }
.calib .hline { position: absolute; left: 0; right: 0; height: 2px; background: #175cd3; }
.calib .mark span, .calib .hline span { position: absolute; background: inherit; color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 3px; white-space: nowrap; top: 4px; left: 4px; }

@media print {
    .admin-top, .tabs, .no-print, .page-head .btn-row { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; }
}

/* ---------- Administration sur mobile ---------- */
@media (max-width: 760px) {
    body { font-size: 14px; }
    .admin-top .container { gap: 6px 12px; padding-top: 8px; padding-bottom: 8px; }
    .admin-top nav { order: 3; width: 100%; flex: none; flex-wrap: nowrap; overflow-x: auto; gap: 16px; padding: 4px 0; -webkit-overflow-scrolling: touch; }
    .admin-top nav a { white-space: nowrap; }
    .admin-top .who { margin-left: auto; }
    .admin-main { padding-top: 16px; }
    .page-head h1 { font-size: 22px; }
    .page-head .btn-row { width: 100%; }
    .card { padding: 14px; }
    .table th, .table td { padding: 7px 6px; }
    .table td.btn-row { flex-wrap: nowrap; }
    .btn.big { font-size: 16px; }
    .challenge-grid { grid-template-columns: 1fr; }
    .thumbs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Onglet Équipes : édition sur la ligne ---------- */
.team-add { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: flex-end; }
.team-add .field { flex: 1 1 140px; }
.team-add .field:first-of-type { flex-basis: 200px; }
.team-add .field:last-child { flex: 0 0 auto; }
.team-preview { height: 72px; width: auto; max-width: none; display: block; } /* max-width: none : sinon l'image est réduite à la largeur de la colonne */
.team-table .team-preview { height: 80px; }
.team-table td.preview-cell { width: 70px; min-width: 70px; padding-top: 4px; padding-bottom: 4px; }
.team-preview.big { height: 77px; margin: 0 6px 12px 0; }
.team-table input, .team-table select { padding: 6px 8px; }
.team-table select { min-width: 115px; }
.team-table th, .team-table td { padding-left: 6px; padding-right: 6px; }
.team-table tr.changed td { background: #fffaeb; }

.admin-footer { color: var(--muted); font-size: 12px; text-align: right; padding-bottom: 20px; }
