:root {
    /* Palette Premium */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;

    --bg-body: #f8fafc;
    --bg-panel: #ffffff;
    --bg-hover: #f1f5f9;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -4px rgba(0, 0, 0, 0.02);

    --radius: 16px;

    /* Toast Colors */
    --success: #10b981;
    --error: #ef4444;
    --info: #3b82f6;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 20px;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    padding: 16px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
    background: var(--bg-body);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

.dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Main Grid - 3 Columns Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr; /* Left | Center | Right */
    gap: 24px;
    flex: 1;
    min-height: 0;
}

.left-column {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.center-column {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 0;
    overflow-y: hidden; /* Prevent scroll on column itself */
}

.panel {
    background: var(--bg-panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.panel:hover {
    box-shadow: var(--shadow-md);
}

.panel-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge {
    background-color: #eef2ff;
    color: var(--primary);
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
    border: 1px solid rgba(99, 102, 241, 0.1);
}

/* Leaderboard Panel */
.leaderboard-panel {
    flex: 1; /* Take remaining height in center column */
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-wrapper {
    flex: 1;
    overflow-y: auto; /* Scroll only inside the table wrapper */
    padding: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 10;
    text-align: left;
    padding: 14px 20px;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.05em;
}

td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
    transition: background-color 0.3s ease;
}

tr:hover td {
    background-color: var(--bg-hover);
}

tr:last-child td {
    border-bottom: none;
}

.rank-col { width: 50px; text-align: center; font-weight: 600; color: var(--text-muted); }
.level-col { width: 50px; text-align: center; font-weight: 700; color: var(--secondary); font-size: 0.8rem; }
.score-col { width: 80px; font-weight: 700; color: var(--primary); font-feature-settings: "tnum"; }
.actions-col { width: 40px; text-align: right; }

.player-name {
    font-weight: 600;
    display: block;
    cursor: pointer;
    color: var(--text-main);
    transition: color 0.2s;
}

.player-name:hover {
    color: var(--primary);
}

/* Chart Panel */
.chart-panel {
    flex: 1; /* Take available space */
    min-height: 200px; /* Minimum height to be usable */
    display: flex;
    flex-direction: column;
}

.chart-container {
    flex: 1;
    position: relative;
    padding: 16px;
    min-height: 0;
}

/* Controls Panel */
.controls-panel {
    flex: 0 0 auto; /* Take only needed space */
    overflow-y: visible;
}

.controls-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.main-form-grid {
    display: flex;
    flex-direction: row;
    gap: 12px;
    background: #f8fafc;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.form-group.small-group {
    flex: 0 0 80px;
}

.form-group.action-group {
    flex: 0 0 120px;
}

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

input, select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.9rem;
    background: var(--bg-panel);
    color: var(--text-main);
    transition: all 0.2s;
    font-family: inherit;
    height: 38px;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0 16px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-block {
    width: 100%;
}

.separator {
    height: 1px;
    background: var(--border-light);
    width: 100%;
    margin: 10px 0;
}

.secondary-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.admin-col {
    background: #f8fafc;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.inline-form {
    display: flex;
    gap: 10px;
    flex-direction: row;
    align-items: center;
}

.inline-form input {
    flex: 1;
}

.grid-form {
    display: grid;
    gap: 12px;
}

.btn-icon {
    background: white;
    color: var(--text-muted);
    border: 1px solid var(--border);
    width: 42px;
    height: 42px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef2ff;
}

.delete-btn {
    background: transparent;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* Activity Feed */
.activity-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.activity-feed {
    flex: 1;
    overflow-y: auto; /* Scroll only inside the feed */
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.activity-item {
    display: flex;
    gap: 12px;
    position: relative;
    padding-bottom: 16px;
}

.activity-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 32px;
    bottom: 0;
    width: 2px;
    background: var(--border-light);
}

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eef2ff;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 1;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

.activity-item.activity-rank-up .activity-icon {
    background: #dcfce7;
    color: #16a34a;
}

.activity-item.activity-rank-down .activity-icon {
    background: #fee2e2;
    color: #dc2626;
}

.activity-content {
    flex: 1;
    padding-top: 4px;
}

.activity-text {
    font-size: 0.9rem;
    color: var(--text-main);
    line-height: 1.4;
}

.activity-text strong {
    font-weight: 600;
}

.activity-time {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
}

.empty-state {
    text-align: center;
    color: var(--text-light);
    font-size: 0.9rem;
    padding: 40px 0;
    font-style: italic;
}

/* ═══════════════════════════════════════════
   MODAL OVERLAY (partagée admin + joueur)
   ═══════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.2s;
}
.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.modal-overlay.hidden .modal-content,
.modal-overlay.hidden .player-modal-content {
    transform: scale(0.96) translateY(8px);
}

/* ═══════════════════════════════════════════
   MODAL ADMIN (inchangée)
   ═══════════════════════════════════════════ */
.modal-content {
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: scale(1) translateY(0);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 20px 24px;
    background: white;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-main);
    font-weight: 700;
}
.close-modal {
    background: var(--bg-body);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}
.close-modal:hover { background: var(--border); color: var(--text-main); }
.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}
.admin-section { display: flex; flex-direction: column; gap: 12px; }

/* ═══════════════════════════════════════════
   MODAL JOUEUR — nouveau design
   ═══════════════════════════════════════════ */
.player-modal-content {
    background: #fff;
    border-radius: 24px;
    width: min(860px, 94vw);
    box-shadow: 0 32px 64px -12px rgba(15,23,42,0.18), 0 0 0 1px rgba(15,23,42,0.06);
    overflow: hidden;
    transform: scale(1) translateY(0);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

/* --- Hero --- */
.player-modal-hero {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px 28px 20px;
    background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
    border-bottom: 1px solid var(--border-light);
    position: relative;
}
.player-modal-avatar {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
    letter-spacing: -0.02em;
}
.player-modal-hero-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 0;
}
.player-modal-hero-info h2 {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.02em;
}
.player-modal-level-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--primary);
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.04em;
    width: fit-content;
    text-transform: uppercase;
}
.player-modal-close {
    position: absolute;
    top: 18px;
    right: 20px;
    background: rgba(15,23,42,0.07);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.18s;
    flex-shrink: 0;
}
.player-modal-close:hover { background: rgba(15,23,42,0.13); color: var(--text-main); }

/* --- Barre XP --- */
.player-modal-xp {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 28px;
    background: #fff;
    border-bottom: 1px solid var(--border-light);
}
.player-modal-xp-bar-bg {
    flex: 1;
    height: 7px;
    background: #e2e8f0;
    border-radius: 99px;
    overflow: hidden;
}
.player-modal-xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 99px;
    transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
    width: 0%;
}
.player-modal-xp-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* --- Corps : 2 colonnes --- */
.player-modal-body {
    display: grid;
    grid-template-columns: 1fr 220px;
    min-height: 0;
}

/* --- Colonne gauche : succès --- */
.player-modal-left {
    padding: 20px 24px;
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}
.player-modal-right {
    padding: 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Titre de section */
.player-modal-section-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
}

/* Grille succès */
.player-achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}
.ach-empty {
    font-size: 0.8rem;
    color: var(--text-light);
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

/* Item succès */
.pach-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1.5px solid transparent;
    transition: all 0.18s;
    min-width: 0;
}
.pach-item.pach-unlocked {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border-color: #86efac;
}
.pach-item.pach-locked {
    background: #f8fafc;
    border-color: #e2e8f0;
    opacity: 0.55;
    filter: grayscale(0.4);
}
.pach-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}
.pach-item.pach-locked .pach-icon { color: var(--text-light); }
.pach-icon svg { width: 18px; height: 18px; }
.pach-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}
.pach-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pach-item.pach-locked .pach-name { color: var(--text-muted); }
.pach-desc {
    font-size: 0.68rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pach-check {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    background: #22c55e;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

/* Graphique doughnut */
.player-modal-chart-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    position: relative;
}
.player-modal-chart-wrap canvas {
    max-width: 100%;
    max-height: 180px;
}

/* ═══════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════ */
#toast-container {
    position: fixed;
    bottom: 32px;
    right: 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 2000;
}
.toast {
    background: white;
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 280px;
    animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    border-left: 4px solid var(--primary);
}

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }
    .left-column { grid-row: 1 / 3; }
    .center-column { grid-column: 2; }
    .activity-panel { grid-column: 2; }
}

@media (max-width: 900px) {
    html, body { overflow: auto; height: auto; }
    .app-container { height: auto; min-height: 100vh; }
    .dashboard-grid { grid-template-columns: 1fr; display: flex; flex-direction: column; }
    .left-column { order: 3; max-height: 500px; }
    .center-column { order: 1; }
    .activity-panel { order: 2; max-height: 400px; }
    .main-form-grid { flex-direction: column; align-items: stretch; }
    .form-group.small-group, .form-group.action-group { flex: auto; }

    .player-modal-content { width: 98vw; border-radius: 16px; }
    .player-modal-body { grid-template-columns: 1fr; }
    .player-modal-left { border-right: none; border-bottom: 1px solid var(--border-light); }
    .player-achievements-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .player-modal-chart-wrap canvas { max-height: 160px; }
}
