* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --gradient-fire: linear-gradient(135deg, #FF7A00 0%, #FF004D 50%, #7000FF 100%);
    --gradient-cool: linear-gradient(135deg, #7000FF 0%, #00D4FF 100%);
    --card: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.12);
    --muted: #907d9e;
    --ok: #7be07b;
    --warn: #ffb547;
    --err: #ff7a93;
}
body {
    font-family: 'Fredoka', system-ui, sans-serif;
    background: #07030f;
    background-image:
        radial-gradient(circle at 20% 8%, rgba(178, 0, 255, 0.22), transparent 50%),
        radial-gradient(circle at 80% 92%, rgba(255, 0, 77, 0.20), transparent 50%),
        linear-gradient(180deg, #14082a 0%, #07030f 100%);
    color: #f5f0ff;
    min-height: 100dvh;
    padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
}
#app { max-width: 720px; margin: 0 auto; }
.hidden { display: none !important; }

/* Header */
.admin-header {
    display: flex; align-items: center; gap: 14px;
    padding: 4px 0 18px;
}
.btn-back {
    flex-shrink: 0;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 14px;
    background: var(--card);
    border: 1px solid var(--card-border);
    color: #fff; font-size: 1.3rem; text-decoration: none;
}
.btn-back:active { transform: scale(0.92); background: rgba(255,255,255,0.14); }
.admin-titles { flex: 1; min-width: 0; }
.admin-titles h1 { font-size: 1.55rem; font-weight: 900; text-transform: uppercase; line-height: 1; }
.admin-titles .highlight {
    background: var(--gradient-fire);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.admin-titles p { color: #cab5e6; font-size: 0.86rem; margin-top: 4px; }

.admin-live-dot {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px;
    background: rgba(123, 224, 123, 0.12);
    border: 1px solid rgba(123, 224, 123, 0.35);
    border-radius: 999px;
    color: var(--ok);
    font-size: 0.7rem; font-weight: 800; letter-spacing: 1px;
}
.admin-live-dot .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 10px var(--ok);
    animation: livePulse 1.2s ease-in-out infinite;
}
.admin-live-dot.paused { color: var(--warn); background: rgba(255, 181, 71, 0.12); border-color: rgba(255, 181, 71, 0.35); }
.admin-live-dot.paused .dot { background: var(--warn); box-shadow: 0 0 10px var(--warn); animation: none; }
@keyframes livePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.admin-main { display: flex; flex-direction: column; gap: 22px; }

/* Refus admin */
.admin-denied {
    background: var(--card); border: 1px solid var(--card-border);
    border-radius: 22px; padding: 32px 22px;
    display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center;
}
.admin-denied i { font-size: 2.6rem; color: var(--err); }
.admin-denied h2 { font-size: 1.4rem; font-weight: 900; }
.admin-denied p { color: var(--muted); font-size: 0.95rem; }
.denied-debug {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px 12px;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.75rem;
    color: #cab5e6;
    white-space: pre-wrap;
    word-break: break-all;
    text-align: left;
    max-height: 220px; overflow-y: auto;
}

/* KPI cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 4px;
}
.kpi-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 14px;
    display: flex; align-items: center; gap: 12px;
    position: relative; overflow: hidden;
}
.kpi-card::before {
    content: ''; position: absolute; inset: 0;
    background: var(--bg, transparent); opacity: 0.18; pointer-events: none;
}
.kpi-online { --bg: radial-gradient(circle at 0% 0%, #7be07b 0%, transparent 60%); }
.kpi-sockets { --bg: radial-gradient(circle at 0% 0%, #00D4FF 0%, transparent 60%); }
.kpi-lobbies { --bg: radial-gradient(circle at 0% 0%, #FF7A00 0%, transparent 60%); }
.kpi-users { --bg: radial-gradient(circle at 0% 0%, #B200FF 0%, transparent 60%); }

.kpi-icon {
    width: 42px; height: 42px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 1.1rem; color: #fff;
}
.kpi-online .kpi-icon { color: var(--ok); }
.kpi-sockets .kpi-icon { color: #00D4FF; }
.kpi-lobbies .kpi-icon { color: #FF7A00; }
.kpi-users .kpi-icon { color: #B200FF; }
.kpi-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kpi-value { font-size: 1.5rem; font-weight: 900; color: #fff; line-height: 1; }
.kpi-value.flash { animation: kpiFlash 0.4s ease; }
@keyframes kpiFlash {
    0% { transform: scale(1); color: #fff; }
    50% { transform: scale(1.15); color: var(--ok); }
    100% { transform: scale(1); color: #fff; }
}
.kpi-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Cartes — chacune nettement séparée avec un peu de respiration en plus
   et un titre détaché du contenu par un trait fin. */
.admin-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 20px;
    display: flex; flex-direction: column; gap: 16px;
}
.admin-card h3 {
    font-size: 1rem; font-weight: 800;
    display: flex; align-items: center; gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.admin-card h3 small {
    margin-left: auto; font-size: 0.72rem; color: var(--muted); font-weight: 500;
}

.sys-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.sys-grid > div {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex; flex-direction: column; gap: 2px;
}
.sys-grid span { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.sys-grid strong { font-size: 0.95rem; font-weight: 700; color: #fff; }

/* Services */
.services-list { display: flex; flex-direction: column; gap: 8px; }
.service-row {
    display: flex; align-items: center; gap: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 10px 12px;
}
.service-row .svc-name { flex: 1; font-weight: 700; font-size: 0.92rem; }
.service-row .svc-info { font-size: 0.75rem; color: var(--muted); }
.service-status {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
    box-shadow: 0 0 8px transparent;
    transition: background 0.2s, box-shadow 0.2s;
}
.service-status.up { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.service-status.down { background: var(--err); box-shadow: 0 0 8px var(--err); }
.svc-test-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cab5e6; border-radius: 8px;
    padding: 6px 10px; font-size: 0.78rem; font-family: inherit; font-weight: 700;
    cursor: pointer; transition: background 0.15s;
}
.svc-test-btn:hover { background: rgba(255, 255, 255, 0.16); }
.svc-test-btn:active { transform: scale(0.96); }
.svc-ms { font-size: 0.72rem; color: var(--muted); min-width: 38px; text-align: right; }

/* Lobbies */
.lobbies-list, .users-list { display: flex; flex-direction: column; gap: 8px; }
.lobby-row, .user-row {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 0.88rem;
}
.lobby-code {
    font-family: 'Fredoka', monospace; font-weight: 900;
    background: rgba(255, 255, 255, 0.08);
    padding: 4px 10px; border-radius: 8px;
    letter-spacing: 2px; font-size: 0.85rem;
}
.lobby-game { color: var(--muted); }
.lobby-players { margin-left: auto; font-weight: 700; font-size: 0.82rem; }
.lobby-players i { margin-right: 4px; color: var(--muted); }
.lobby-badge {
    font-size: 0.7rem; padding: 3px 8px; border-radius: 999px;
    background: rgba(255, 255, 255, 0.08); color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.lobby-badge.in_game { background: rgba(255, 0, 77, 0.18); color: var(--err); }
.lobby-badge.waiting { background: rgba(0, 212, 255, 0.18); color: #00D4FF; }

.user-name { font-weight: 700; }
.user-email { color: var(--muted); font-size: 0.78rem; }
.user-badge {
    margin-left: auto; font-size: 0.7rem; padding: 3px 8px; border-radius: 999px;
    background: rgba(255, 255, 255, 0.08); color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.user-badge.premium { background: linear-gradient(135deg, #FF7A00, #FFD700); color: #1a0a00; }
.user-badge.admin { background: linear-gradient(135deg, #FF004D, #7000FF); color: #fff; }

.empty-row { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 8px 0; }

/* Boutons */
.btn-update {
    margin-top: 4px;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%;
    border: none; border-radius: 14px;
    padding: 13px 18px;
    background: linear-gradient(135deg, #7000FF 0%, #B200FF 50%, #FF004D 100%);
    background-size: 200% 200%;
    color: #fff;
    font-family: inherit; font-weight: 800; font-size: 0.95rem;
    cursor: pointer; text-decoration: none;
    box-shadow: 0 8px 22px rgba(178, 0, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    transition: transform 0.12s, background-position 0.4s;
}
.btn-update:active { transform: scale(0.97); }
.btn-update:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.ghost-btn {
    background: transparent; border: 1px solid rgba(255, 255, 255, 0.18);
    color: #cab5e6; border-radius: 8px;
    padding: 4px 10px; font-family: inherit; font-size: 0.8rem; font-weight: 700;
    cursor: pointer;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.admin-footer {
    text-align: center; color: var(--muted); font-size: 0.8rem;
    padding: 6px 0;
}

/* ---------- Filtres (onglets) ---------- */
.filter-tabs {
    display: flex; gap: 6px; align-items: center;
    padding-bottom: 4px;
}
.filter-tab {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--muted);
    border-radius: 999px;
    padding: 6px 12px;
    font-family: inherit; font-size: 0.78rem; font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.filter-tab:hover { color: #fff; }
.filter-tab.active {
    background: linear-gradient(135deg, #7000FF, #B200FF);
    color: #fff;
    border-color: transparent;
}

/* ---------- Erreurs JS ---------- */
.errors-list { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.error-row {
    background: rgba(255, 0, 77, 0.06);
    border: 1px solid rgba(255, 0, 77, 0.20);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex; flex-direction: column; gap: 6px;
    position: relative;
}
.error-row.is-seen { background: rgba(255, 255, 255, 0.03); border-color: rgba(255, 255, 255, 0.08); opacity: 0.78; }
.error-row .err-head {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.78rem; color: var(--muted);
}
.err-occ {
    background: var(--err); color: #1a0006;
    padding: 1px 7px; border-radius: 999px;
    font-weight: 900; font-size: 0.7rem;
}
.error-row.is-seen .err-occ { background: var(--muted); color: #1a0a2a; }
.err-when { margin-left: auto; }
.err-message {
    font-size: 0.88rem; font-weight: 700; color: #fff;
    word-wrap: break-word; overflow-wrap: anywhere;
}
.err-meta { font-size: 0.72rem; color: var(--muted); }
.err-stack {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.7rem; color: #cab5e6;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    padding: 6px 8px;
    white-space: pre-wrap; word-break: break-all;
    max-height: 100px; overflow-y: auto;
    display: none;
}
.error-row.expanded .err-stack { display: block; }
.err-actions { display: flex; gap: 6px; margin-top: 2px; }
.err-actions button {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cab5e6; border-radius: 8px;
    padding: 4px 10px; font-family: inherit; font-size: 0.74rem; font-weight: 700;
    cursor: pointer;
}
.err-actions button:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.err-actions .danger:hover { background: rgba(255, 0, 77, 0.18); color: var(--err); }

/* ---------- Signalements ---------- */
.reports-list { display: flex; flex-direction: column; gap: 10px; max-height: 520px; overflow-y: auto; }
.report-row {
    background: rgba(255, 122, 0, 0.06);
    border: 1px solid rgba(255, 122, 0, 0.25);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 8px;
}
.report-row.is-resolved { background: rgba(123, 224, 123, 0.04); border-color: rgba(123, 224, 123, 0.2); }
.report-row.is-dismissed { background: rgba(255, 255, 255, 0.03); border-color: rgba(255, 255, 255, 0.08); opacity: 0.7; }
.report-head {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.78rem; color: var(--muted);
}
.report-reason {
    background: var(--warn); color: #1a0a00;
    padding: 2px 9px; border-radius: 999px;
    font-weight: 900; font-size: 0.72rem; text-transform: uppercase;
}
.report-row.is-resolved .report-reason { background: var(--ok); color: #002a00; }
.report-row.is-dismissed .report-reason { background: var(--muted); color: #1a0a2a; }
.report-target {
    font-size: 0.78rem; font-weight: 700;
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 9px; border-radius: 999px;
    color: #fff;
}
.report-snapshot {
    font-size: 0.88rem; color: #fff;
    background: rgba(0, 0, 0, 0.3); border-radius: 10px;
    padding: 8px 12px; font-style: italic;
    word-wrap: break-word; overflow-wrap: anywhere;
}
.report-meta { font-size: 0.74rem; color: var(--muted); }
.report-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.report-actions button {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cab5e6; border-radius: 8px;
    padding: 6px 12px; font-family: inherit; font-size: 0.78rem; font-weight: 700;
    cursor: pointer;
}
.report-actions .danger { color: var(--err); border-color: rgba(255, 0, 77, 0.4); }
.report-actions .danger:hover { background: rgba(255, 0, 77, 0.18); color: #fff; }
.report-actions .ok { color: var(--ok); border-color: rgba(123, 224, 123, 0.4); }
.report-actions .ok:hover { background: rgba(123, 224, 123, 0.18); color: #fff; }
.report-actions button:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }

/* ---------- Analytics ---------- */
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi-grid-3 .kpi-card { padding: 12px 10px; }
.kpi-grid-3 .kpi-value { font-size: 1.25rem; }
.kpi-grid-3 .kpi-label { font-size: 0.7rem; }
.analytics-events-list {
    display: flex; flex-direction: column; gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 6px;
}
.analytics-events-list .ae-row {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 0.84rem;
    background: rgba(255, 255, 255, 0.03);
}
.analytics-events-list .ae-name { flex: 1; color: #fff; font-weight: 600; }
.analytics-events-list .ae-bar {
    height: 6px; border-radius: 3px;
    background: linear-gradient(90deg, #7000FF, #B200FF, #FF004D);
    min-width: 4px;
}
.analytics-events-list .ae-count {
    font-weight: 900; color: #fff;
    background: rgba(178, 0, 255, 0.18); padding: 2px 8px; border-radius: 999px;
    font-size: 0.78rem;
    min-width: 36px; text-align: center;
}

/* ---------- Historique parties ---------- */
.games-list {
    display: flex; flex-direction: column; gap: 8px;
    max-height: 520px; overflow-y: auto;
}
.game-row {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 6px;
}
.game-row-head {
    display: flex; align-items: center; gap: 10px;
    flex-wrap: wrap;
}
.game-badge {
    background: var(--gradient-fire, linear-gradient(135deg, #FF7A00, #FF004D, #7000FF));
    color: #fff; font-weight: 900; font-size: 0.7rem;
    padding: 3px 10px; border-radius: 999px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.game-host {
    font-size: 0.78rem; color: var(--muted);
    display: inline-flex; align-items: center; gap: 4px;
}
.game-group {
    font-size: 0.7rem;
    background: rgba(112, 0, 255, 0.18);
    color: #b08aff;
    padding: 2px 8px; border-radius: 999px;
    font-weight: 700;
}
.game-when {
    margin-left: auto;
    font-size: 0.74rem; color: var(--muted);
}
.game-row-body {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: 0.86rem;
}
.game-winner {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.18), rgba(255, 122, 0, 0.10));
    border: 1px solid rgba(255, 215, 0, 0.32);
    border-radius: 10px;
    padding: 4px 10px;
    color: #FFD700;
    font-weight: 700; font-size: 0.82rem;
}
.game-players {
    color: #cab5e6;
    display: inline-flex; align-items: center; gap: 6px;
}
.game-duration {
    color: var(--muted);
    font-size: 0.78rem;
}
.game-code {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.76rem; color: var(--muted);
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
}

/* Petit format mobile */
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .sys-grid { grid-template-columns: 1fr; }
    .kpi-value { font-size: 1.3rem; }
    .admin-titles h1 { font-size: 1.3rem; }
}
