:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #e63946;
    --green: #22c55e;
    --orange: #f59e0b;
    --red: #ef4444;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

header.top {
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #7f1d1d, #1d1d3a);
    border-bottom: 1px solid var(--panel-border);
}

header.top h1 {
    margin: 0 0 0.15rem;
    font-size: 1.4rem;
}

header.top p {
    margin: 0;
    color: #e2e8f0;
    font-size: 0.9rem;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

.stages {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.stage-item {
    display: flex;
    gap: 4px;
    flex: 1 1 170px;
}

.stage-btn,
.stage-copilote {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--text);
    text-decoration: none;
    border-radius: 8px;
    font-family: inherit;
    cursor: pointer;
}

.stage-btn {
    flex: 1;
    min-width: 0;
    text-align: center;
    padding: 0.65rem 0.5rem;
    font-size: 0.9rem;
}

.stage-btn:not(:disabled):hover,
.stage-copilote:hover {
    border-color: var(--accent);
}

.stage-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.stage-btn.active {
    border-color: var(--accent);
    background: rgba(230, 57, 70, 0.15);
    font-weight: 600;
}

.stage-copilote {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    font-size: 1.05rem;
}

.route-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 1rem;
    margin: -0.5rem 0 1rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.route-legend .rl-line {
    position: relative;
    display: inline-block;
    width: 26px;
    height: 14px;
    margin-right: 0.35rem;
    vertical-align: middle;
    border-radius: 2px;
    background: #fff;
}

.route-legend .rl-line::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 4px;
    transform: translateY(-50%);
    background: currentColor;
}

.route-legend .rl-special { color: #38bdf8; }
.route-legend .rl-liaison { color: #111827; }

.route-legend .rl-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-right: 0.2rem;
    vertical-align: middle;
    border-radius: 50%;
    font-size: 0.7rem;
    color: #fff;
}

.route-legend .rl-start { background: #22c55e; }
.route-legend .rl-finish { background: #111827; }
.route-legend .rl-assist { background: #dc2626; }
.route-legend .rl-regroup { background: #f59e0b; }
.route-legend .rl-hotel { background: #6366f1; }
.route-legend .rl-parc { background: #2563eb; font-weight: 700; }

.map-wrap {
    position: relative;
    margin-bottom: 1rem;
}

#map {
    height: 60vh;
    min-height: 380px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
}

.locate-btn {
    position: absolute;
    z-index: 1000;
    left: 0.6rem;
    bottom: 0.6rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: var(--panel);
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

.locate-btn:hover { border-color: var(--accent); }
.locate-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
}

.self-dot {
    position: relative;
    width: 22px;
    height: 22px;
}

.self-dot-core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border-radius: 50%;
    background: #3b82f6;
    border: 3px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.5);
}

.self-dot-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.45);
    animation: self-dot-pulse 2s ease-out infinite;
}

@keyframes self-dot-pulse {
    0% { transform: scale(0.6); opacity: 0.8; }
    100% { transform: scale(2.4); opacity: 0; }
}

.legend {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 0.6rem;
}

.legend .card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.7rem 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.legend .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: none;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}

.legend .info { flex: 1; min-width: 0; }

.legend .name {
    font-weight: 600;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.legend .team {
    color: var(--muted);
    font-size: 0.8rem;
}

.legend .status {
    font-size: 0.78rem;
    margin-top: 0.15rem;
}

.status.fresh { color: var(--green); }
.status.stale { color: var(--orange); }
.status.old, .status.never { color: var(--red); }

.legend .gmaps-link {
    display: inline-block;
    margin-top: 0.15rem;
    font-size: 0.8rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    text-decoration: none;
}

.legend .gmaps-link:hover { border-color: var(--accent); }

footer.foot {
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
    padding: 1.5rem 1rem 2rem;
}

footer.foot a { color: var(--muted); }
footer.foot a:hover { color: var(--text); }

/* Mode copilote — page de sélection d'étape (/copilote) */
.copilote-warn {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--text);
    border-radius: 8px;
    padding: 0.7rem 0.85rem;
    font-size: 0.85rem;
    line-height: 1.5;
}

.copilote-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.7rem;
    margin: 1rem 0;
}

.copilote-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.85rem;
}

.copilote-card .cc-label {
    font-weight: 600;
    margin-bottom: 0.6rem;
}

.copilote-card .cc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.copilote-card .cc-progress {
    margin-top: 0.55rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.copilote-card .cc-missing {
    font-size: 0.8rem;
    color: var(--red);
}

.copilote-card .cc-missing code {
    background: var(--bg);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}

.copilote-storage {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.copilote-back {
    margin-top: 1.5rem;
    font-size: 0.85rem;
}

.copilote-back a { color: var(--muted); }

/* Page suivi (pilote) */
.tracker {
    max-width: 480px;
    margin: 2rem auto;
    padding: 1.25rem;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    text-align: center;
}

.tracker h1 { font-size: 1.2rem; margin-top: 0; }

.tracker .big-btn {
    display: block;
    width: 100%;
    padding: 1.1rem;
    font-size: 1.15rem;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    margin: 1rem 0 0.5rem;
    background: var(--green);
    color: #06240f;
}

.tracker .big-btn.active { background: var(--red); color: #fff; }

.tracker .state {
    font-size: 0.9rem;
    color: var(--muted);
    margin-top: 0.6rem;
    line-height: 1.5;
}

.tracker .warning {
    margin-top: 1rem;
    font-size: 0.82rem;
    color: var(--orange);
    text-align: left;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}

.tracker h2 {
    font-size: 1.05rem;
    margin: 0 0 0.5rem;
}

.tracker .lead {
    text-align: left;
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0 0 0.9rem;
    line-height: 1.5;
}

.tracker .steps {
    text-align: left;
    padding-left: 1.2rem;
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.6;
}

.tracker .steps li { margin-bottom: 0.9rem; }

.tracker .field {
    margin: 0.5rem 0;
}

.tracker .field-label {
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.2rem;
}

.tracker .field-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
    word-break: break-all;
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    cursor: pointer;
}

.tracker .field-value:active { border-color: var(--accent); }

.tracker .field input[type="url"],
.tracker .field input[type="text"],
.tracker .field input[type="password"],
.tracker .field select {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    color: var(--text);
}

.tracker .field input[type="color"] {
    width: 100%;
    height: 2.4rem;
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 0.2rem;
}

.tracker .field input:focus,
.tracker .field select:focus {
    outline: none;
    border-color: var(--accent);
}

.tracker .field-errors {
    list-style: none;
    margin: 0.3rem 0 0;
    padding: 0;
    color: var(--red);
    font-size: 0.78rem;
    text-align: left;
}

.flash {
    max-width: 1100px;
    margin: 0 auto 1rem;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    font-size: 0.88rem;
}

.flash-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: var(--green);
}

.flash-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: var(--red);
    text-align: left;
}

.login-box { margin-top: 3rem; }

/* Administration */
main.admin {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

.admin-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.btn {
    display: inline-block;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--text);
    text-decoration: none;
    padding: 0.55rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
    background: var(--green);
    border-color: var(--green);
    color: #06240f;
    font-weight: 600;
}

.btn-muted { color: var(--muted); }

.btn-small {
    padding: 0.35rem 0.6rem;
    font-size: 0.78rem;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--red);
}

.admin-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th, .admin-table td {
    padding: 0.6rem 0.7rem;
    border-bottom: 1px solid var(--panel-border);
    text-align: left;
    white-space: nowrap;
}

.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: rgba(255,255,255,0.03); }

.admin-table .dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.admin-table .copy-link {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--muted);
}

.admin-actions {
    display: flex;
    gap: 0.4rem;
}

.admin-actions form { margin: 0; }

.admin-form .field-value { text-align: left; }

.tracker .hint {
    text-align: left;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 1rem;
}

/* Installation PWA */
/* Réserve de la place en bas de page quand le bouton flottant est affiché,
   pour qu'il ne recouvre pas le pied de page (liens copilote / admin). */
body.has-pwa-btn {
    padding-bottom: 4.5rem;
}

.pwa-install-btn {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 0.7rem 1.1rem;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.pwa-install-btn:active { transform: translateY(1px); }

.pwa-hint {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 4.5rem;
    z-index: 51;
    max-width: 420px;
    margin: 0 auto;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.9rem 1rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.pwa-hint p {
    margin: 0 0 0.7rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text);
}

.pwa-hint-close {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    cursor: pointer;
}
