/* ============================================================================
   VARIÁVEIS GLOBAIS & NOVO LAYOUT DOS TILES
============================================================================ */

:root {
    --bg-dark: #0a0a0a;
    --tile-bg: #1a1a1a;
    --orange: #FF5722;
    --green: #4CAF50;
    --blue: #00BCD4;
    --red: #FF1744;
    --text-main: #ffffff;
    --text-dim: #aaaaaa;
}

/* ============================================================================
   RESET & BASE
============================================================================ */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    background: #0d1117;
    color: #e6edf3;
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ============================================================================
   TELA DE SETUP / CONFIGURAÇÃO (primeira tela)
============================================================================ */
#app-content {
    padding: 16px;
}

#setup {
    max-width: 1100px;
    margin: 0 auto 60px;
    padding: 0 16px;
}

#setup h1 {
    font-size: 2.8rem;
    font-weight: 900;
    color: #FF5722;
    text-align: center;
    margin: 20px 0 30px;
}

#setup .btn-logout {
    background: #E91E63;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
}

#addParticipant {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin: 24px 0 32px;
}

#addParticipant input,
#addParticipant select {
    padding: 14px 16px;
    font-size: 1.1rem;
    border-radius: 8px;
    border: 1px solid #444;
    background: #161b22;
    color: #e6edf3;
}

#addParticipant label {
    font-size: 1rem;
    align-self: center;
    white-space: nowrap;
    color: #aaa;
}

#addBtn {
    grid-column: 1 / -1;
    padding: 16px;
    font-size: 1.3rem;
    font-weight: bold;
    background: #FF5722;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 8px;
}

#addBtn:hover { background: #E64A19; }

#participantListContainer {
    margin: 40px 0 60px;
}

#participantListContainer h2 {
    font-size: 2.1rem;
    color: #FF5722;
    margin-bottom: 16px;
    text-align: center;
}

#participantListContainer p {
    text-align: center;
    color: #888;
    margin: 0 0 20px;
    font-size: 1rem;
}

#participantList {
    max-height: 60vh;
    overflow-y: auto;
    list-style: none;
    padding: 0;
    margin: 0;
    border: 1px solid #30363d;
    border-radius: 12px;
    background: #161b22;
}

#participantList li {
    padding: 16px 20px;
    border-bottom: 1px solid #30363d;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.15rem;
}

#participantList li:last-child { border-bottom: none; }

.participant-actions button {
    background: none;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    margin-left: 16px;
}

.participant-actions .edit-btn   { color: #4CAF50; }
.participant-actions .delete-btn { color: #E63946; }

#participantList::-webkit-scrollbar {
    width: 10px;
}

#participantList::-webkit-scrollbar-track {
    background: #0d1117;
    border-radius: 0 12px 12px 0;
}

#participantList::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 5px;
    border: 2px solid #0d1117;
}

#participantList::-webkit-scrollbar-thumb:hover {
    background: #777;
}

#startScanBtn {
    display: block;
    width: 100%;
    max-width: 600px;
    margin: 40px auto;
    padding: 20px 40px;
    font-size: 1.9rem;
    font-weight: bold;
    background: #FF5722;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}

#startScanBtn:hover { background: #E64A19; }

/* ============================================================================
   RESPONSIVIDADE – SETUP
============================================================================ */
@media (max-width: 768px) {
    #addParticipant {
        grid-template-columns: 1fr;
    }
    #setup h1 { font-size: 2.4rem; }
    #startScanBtn { font-size: 1.7rem; padding: 18px 30px; }
}

/* ============================================================================
   DASHBOARD
============================================================================ */
#dashboard { 
    height: 100vh; 
    width: 100vw; 
    display: flex; 
    flex-direction: column; 
    overflow-x: hidden;
}

#main-container {
    display: flex;
    flex: 1;
    height: 100%;
    width: 100vw;
    overflow-x: hidden;
}

#monitor-panel {
    width: 100%;
    padding: 15px 25px;
    overflow-y: auto;
    background: #101010;
}

#header {
    display: grid;
    grid-template-columns: 140px 2fr 1fr 180px;
    align-items: center;
    padding: 12px 20px;
    background: #181818;
    border-radius: 14px;
    margin-bottom: 16px;
    gap: 16px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
}

#logo { width: 120px; height: auto; }

.header-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#current-class-name { font-size: 1.9rem; font-weight: 900; color: #FF9800; }
#daily-leader        { font-size: 1.7rem; color: #FF5722; }
#daily-calories-leader { font-size: 1.6rem; color: #4CAF50; }
#timer               { font-size: 5.2rem; font-weight: 900; color: #4CAF50; text-align: right; }
#leaderboard-top     { font-size: 1.8rem; color: #FFC107; text-align: right; grid-column: 2 / 4; }

/* Rankings */
#weekly-rankings {
    background: #1e1e1e;
    border-radius: 14px;
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr 280px;
    gap: 20px;
    align-items: start;
    margin-top: 10px;
    width: 100%;
    box-sizing: border-box;
}

.ranking-block {
    background: #252525;
    border-radius: 12px;
    padding: 18px 22px;
    border-left: 6px solid;
}

.ranking-block.pontos { border-left-color: #FF5722; }
.ranking-block.calorias { border-left-color: #4CAF50; }
.ranking-block.vo2ZoneActive { border-left-color: #FF1744; }

.ranking-block h3 {
    margin: 0 0 10px 0;
    font-size: 1.6rem;
    color: #ddd;
    text-transform: uppercase;
}

.ranking-list {
    font-size: 1.45rem;
    line-height: 1.6;
    color: #eee;
}

.ranking-list .position-1 { color: #FFD700; font-weight: 900; font-size: 1.9rem; }
.ranking-list .position-2 { color: #C0C0C0; font-weight: 800; font-size: 1.7rem; }
.ranking-list .position-3 { color: #CD7F32; font-weight: 800; font-size: 1.6rem; }

.ranking-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
}

#resetWeeklyBtn, #fullRankingBtn, #exportPdfBtn {
    padding: 12px 20px;
    font-size: 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    border: none;
}

#resetWeeklyBtn { background: #d32f2f; color: white; }
#fullRankingBtn { background: #2196F3; color: white; }
#exportPdfBtn { background: #FF9800; color: white; }

#resetWeeklyBtn:hover { background: #b71c1c; }
#fullRankingBtn:hover { background: #1976D2; }
#exportPdfBtn:hover { background: #F57C00; }

/* ============================================================================
   NOVO LAYOUT DOS TILES - VERSÃO MAIOR (fontes e tiles aumentados)
============================================================================ */

#participants {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 40px;
    padding: 30px;
    justify-content: center;
    background: var(--bg-dark);
}

/* Base para 5+ pessoas - já maior que antes */
.tile {
    background: var(--tile-bg);
    border-radius: 36px;
    padding: 35px;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    box-shadow: 0 30px 60px rgba(0,0,0,0.9);
    border: 5px solid var(--orange);
    position: relative;
    transition: all 0.4s ease;
}

.name { font-size: 3rem; font-weight: 800; text-transform: uppercase; line-height: 1; color: var(--text-main); transition: all 0.4s; }
.bpm { font-size: 8.5rem; font-weight: 900; line-height: 1; letter-spacing: -4px; color: var(--text-main); transition: all 0.4s; }
.zone-label { font-size: 1.8rem; font-weight: bold; margin-top: 10px; text-transform: uppercase; transition: all 0.4s; }
.stat-value { font-size: 2.2rem; font-weight: bold; transition: all 0.4s; }
.vo2-badge { font-size: 1.8rem; padding: 18px; transition: all 0.4s; }
.epoc { font-size: 1.6rem; transition: all 0.4s; }

/* 1 pessoa → GIGANTE */
#participants.count-1 .tile {
    max-width: 1100px;
    padding: 60px;
}
#participants.count-1 .name { font-size: 6rem; }
#participants.count-1 .bpm { font-size: 16rem; letter-spacing: -10px; }
#participants.count-1 .zone-label { font-size: 4rem; }
#participants.count-1 .stat-value { font-size: 4.5rem; }
#participants.count-1 .vo2-badge { font-size: 3.5rem; padding: 30px; }
#participants.count-1 .epoc { font-size: 3rem; }
#participants.count-1 .avatar-container { width: 200px; height: 200px; }

/* 2 pessoas → muito grande */
#participants.count-2 .tile {
    max-width: 850px;
    padding: 50px;
}
#participants.count-2 .name { font-size: 5rem; }
#participants.count-2 .bpm { font-size: 13rem; }
#participants.count-2 .zone-label { font-size: 3.2rem; }
#participants.count-2 .stat-value { font-size: 3.5rem; }
#participants.count-2 .vo2-badge { font-size: 2.8rem; }
#participants.count-2 .avatar-container { width: 160px; height: 160px; }

/* 3-4 pessoas → grande */
#participants.count-3-4 .tile {
    max-width: 650px;
    padding: 40px;
}
#participants.count-3-4 .name { font-size: 4rem; }
#participants.count-3-4 .bpm { font-size: 10.5rem; }
#participants.count-3-4 .zone-label { font-size: 2.5rem; }
#participants.count-3-4 .stat-value { font-size: 2.8rem; }
#participants.count-3-4 .avatar-container { width: 130px; height: 130px; }

/* Leader ainda maior */
.tile.leader {
    transform: scale(1.1);
    box-shadow: 0 40px 80px rgba(255, 87, 34, 0.6);
}

/* Elementos comuns */
.profile-header { display: flex; align-items: center; gap: 30px; margin-bottom: 30px; }
.avatar-container { position: relative; width: 100px; height: 100px; transition: all 0.4s; }
.avatar { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 5px solid var(--orange); background: #333; }
.rank-badge { position: absolute; bottom: -8px; right: -8px; background: var(--orange); color: white; font-size: 1.2rem; font-weight: bold; padding: 8px 14px; border-radius: 16px; border: 4px solid var(--tile-bg); }
.user-info { flex: 1; }
.device { font-size: 1.3rem; color: var(--blue); margin-top: 8px; font-weight: 500; }

.main-stats { background: rgba(255,255,255,0.05); border-radius: 30px; padding: 30px; text-align: center; margin-bottom: 30px; }
.bpm span { font-size: 2rem; color: var(--text-dim); margin-left: 10px; font-weight: normal; }

.progress-bar { height: 24px; background: #333; border-radius: 12px; overflow: hidden; margin: 30px 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--green), #FF9800, var(--red)); transition: width 0.4s ease; }

.grid-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px; }
.stat-box { background: rgba(255,255,255,0.08); padding: 20px; border-radius: 20px; text-align: center; }
.stat-label { font-size: 1.1rem; color: var(--text-dim); text-transform: uppercase; margin-bottom: 6px; letter-spacing: 0.8px; }

.vo2-badge { background: rgba(255, 23, 68, 0.25); color: var(--red); padding: 18px; border-radius: 24px; text-align: center; font-weight: 800; margin-bottom: 20px; border: 3px solid rgba(255, 23, 68, 0.4); }

.epoc { text-align: center; color: var(--orange); font-weight: 700; }

.tile.disconnected, .tile.inactive-alert { opacity: 0.7; }
.tile.disconnected .bpm, .tile.inactive-alert .bpm { color: var(--text-dim) !important; }

/* ============================================================================
   OUTROS ELEMENTOS
============================================================================ */
.compact-mode #header,
.compact-mode #weekly-rankings {
    display: none !important;
}

.compact-mode #monitor-panel {
    padding-top: 10px;
}

#toggleCompactBtn {
    position: fixed;
    top: 20px;
    right: 80px;
    z-index: 999;
    background: #673AB7;
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

#toggleCompactBtn:hover {
    background: #512DA8;
    transform: scale(1.1);
}

#addNewParticipantBtn, #backBtn {
    position: fixed;
    bottom: 25px;
    font-size: 1.2rem;
    padding: 15px 30px;
    border-radius: 40px;
    z-index: 100;
}

#addNewParticipantBtn { left: 25px; background: #4CAF50; }
#backBtn { right: 25px; background: #E63946; }

#full-ranking-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

#full-ranking-modal > div {
    background: #222;
    color: #eee;
    padding: 30px;
    border-radius: 16px;
    max-width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    width: 1000px;
}

#full-ranking-modal span {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 40px;
    cursor: pointer;
    color: #aaa;
}

#full-ranking-modal span:hover {
    color: white;
}

.admin-table th { background: #0d1117; color: #FF5722; }
.admin-table tr:hover { background: #1e1e1e; }
.modal-content h3 { color: #FF9800; margin: 20px 0 10px; }

#monitor-panel, #participants, #weekly-rankings, #header {
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}