/* =========================================
   MESTO / SAKUGAMES - KESKITETTY TYYLITIEDOSTO
   (Sisältää pallopelien, voimailun ja valikoiden tyylit)
   ========================================= */

:root {
    --primary: #4E82A5;     /* Turnauksen pääväri (Sininen) */
    --primary-light: #F0F4F8;
    --bg: #F1F5F9;          /* Sivuston taustaväri */
    --text: #0F172A;        /* Päätekstin väri */
    --muted: #64748B;       /* Aputekstien väri */
    --border: #CBD5E1;      /* Reunaviivojen väri */
    --white: #FFFFFF;       /* Valkoinen tausta */
    --success: #10B981;
    --error: #EF4444;
}

/* --- PERUSASETUKSET --- */
html {
    overflow-y: scroll; /* Estää sivun hyppimisen datan latautuessa */
}

body { 
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg); 
    color: var(--text); 
    margin: 0; 
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main { 
    flex: 1; 
}

.container { 
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 12px; 
    width: 100%;
    box-sizing: border-box; 
}

/* --- YLÄTUNNISTE (Dynaaminen asettelu) --- */
.site-header { 
    background-color: var(--primary);
    color: var(--white);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    padding-left: max(16px, calc((100% - 1200px) / 2 + 16px)) !important; 
    padding-right: max(16px, calc((100% - 1200px) / 2 + 16px)) !important; 
}

.header-title { 
    white-space: normal !important; 
    overflow: visible !important; 
    text-overflow: clip !important; 
    flex: 3 !important; 
    font-size: clamp(14px, 4.5vw, 22px) !important; 
    line-height: 1.1; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    text-align: center; 
    padding: 0 10px; 
}

.header-spacer, .header-actions { 
    flex: 1 !important; 
    min-width: 44px; 
}

.header-actions { 
    justify-content: flex-end !important; 
}

/* --- TYÖKALUPALKKI (TOOLBAR) --- */
.toolbar { 
    background: var(--white); 
    padding: 12px; 
    border-radius: 12px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); 
    border: 1px solid var(--border);
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    align-items: center; 
    justify-content: space-between;
    margin: 20px 0;
}

.search-wrapper { 
    flex: 1; 
    min-width: 200px; 
}

.search-input { 
    width: 100%; 
    padding: 10px 16px; 
    border-radius: 8px; 
    border: 1px solid var(--border);
    background: #F8FAFC; 
    outline: none; 
    font-weight: 600; 
    font-size: 15px;
    box-sizing: border-box; 
    transition: all 0.2s;
}

.search-input:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 2px rgba(78, 130, 165, 0.2); 
}

.btn-group { display: flex; background: #F1F5F9; padding: 4px; border-radius: 8px; gap: 4px; }
.btn-view { 
    padding: 8px; border: none; background: transparent; cursor: pointer; border-radius: 6px; color: var(--muted);
    display: flex; align-items: center; transition: 0.2s;
}
.btn-view.active { background: var(--primary); color: var(--white); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }

.btn-print {
    padding: 10px 15px; background: var(--white); border: 1px solid var(--border); border-radius: 8px;
    color: var(--muted); cursor: pointer; font-weight: 700; font-size: 11px; text-transform: uppercase;
    display: flex; align-items: center; gap: 5px; white-space: nowrap; transition: 0.2s;
}
.btn-print:hover { background: var(--primary); color: var(--white); border-color: var(--primary); }


/* --- TAULUKOT JA KORTIT (Pallopelit) --- */
.section-header { 
    border-left: 6px solid var(--primary); 
    padding-left: 15px; 
    margin: 30px 0 15px 0; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    flex-wrap: wrap; 
    gap: 10px; 
}
.section-title { font-size: 22px; font-weight: 900; color: var(--primary); margin: 0; text-transform: uppercase; }

.grid-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.standings-container { order: 1; align-self: start; width: 100%; min-width: 0; }
.match-column { order: 2; min-width: 0; width: 100%; }

@media (min-width: 1024px) { 
    .grid-layout { grid-template-columns: 7fr 5fr; } 
    .match-column { order: 1; }
    .standings-container { order: 2; }
}

.card { background: var(--white); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.card-header { background: var(--primary); color: var(--white); padding: 10px 15px; font-weight: 800; text-transform: uppercase; font-size: 12px; }

.standings-table { width: 100%; border-collapse: collapse; font-size: 11px; table-layout: auto; }
.standings-table th { background: #F8FAFC; color: var(--muted); padding: 10px 4px; text-align: center; border-bottom: 1px solid var(--border); font-weight: 900; text-transform: uppercase; font-size: 9px; }
.standings-table td { padding: 12px 4px; border-bottom: 1px solid #F1F5F9; text-align: center; }
.standings-table .team-cell { text-align: left; font-weight: 800; color: var(--text); padding-left: 12px; width: 45%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
.standings-table tr:hover { background-color: #F8FAFC; cursor: pointer; }
.font-black { font-weight: 900; color: var(--text); }


/* --- TOISTOVOIMAPUNNERRUS (Ja muut laajat sarjataulukot) --- */
.page-header { margin-bottom: 24px; text-align: center; }
.page-title { font-size: 32px; font-weight: 900; color: var(--primary); margin: 0 0 12px 0; text-transform: uppercase; letter-spacing: 1px; }

.table-wrapper { 
    background: var(--white); border-radius: 12px; border: 1px solid var(--border); 
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); overflow-x: auto; -webkit-overflow-scrolling: touch; 
}
.table-wrapper table { width: 100%; border-collapse: collapse; border-spacing: 0; text-align: left; min-width: 600px; }
.table-wrapper thead th { background-color: var(--primary); color: var(--white); padding: 15px; font-weight: 900; text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; white-space: nowrap; border-right: 1px solid rgba(255, 255, 255, 0.1); border-bottom: 1px solid rgba(0, 0, 0, 0.1); }
.table-wrapper thead th:last-child { border-right: none; }
.table-wrapper td { padding: 12px 15px; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text); font-weight: 600; line-height: 1.4; border-right: 1px solid #E2E8F0; }
.table-wrapper td:last-child { border-right: none; }
.table-wrapper tr:nth-child(even) td { background-color: #F8FAFC; }
.table-wrapper tr:nth-child(odd) td { background-color: var(--white); }
.table-wrapper tr:hover td { background-color: var(--primary-light); }

/* Voimailun saraketyylit ja mitalit */
.col-rank { width: 50px; text-align: center; font-size: 18px; font-weight: 900; }
.col-name { font-weight: 800; font-size: 15px; }
.col-school { font-weight: 700; color: var(--text); } 
.col-reps { font-size: 18px; font-weight: 900; color: var(--primary); text-align: center; background: rgba(78, 130, 165, 0.05); }

.rank-1 { color: #D4AF37; text-shadow: 0 1px 2px rgba(0,0,0,0.2); font-size: 22px; }
.rank-2 { color: #9CA3AF; text-shadow: 0 1px 2px rgba(0,0,0,0.2); font-size: 20px; }
.rank-3 { color: #B08D57; text-shadow: 0 1px 2px rgba(0,0,0,0.2); font-size: 19px; }

.col-participants { font-size: 13px; color: var(--text); font-weight: 500; font-style: italic; }
.team-total-reps { font-size: 20px; font-weight: 900; color: var(--primary); text-align: center; background: rgba(78, 130, 165, 0.08); }


/* --- LISTANÄKYMÄ (Pallopelit) --- */
.list-container { background: var(--white); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.list-row { display: flex; align-items: center; padding: 10px; border-bottom: 1px solid #F1F5F9; gap: 8px; }
.list-row:last-child { border-bottom: none; }
.list-row:hover { background-color: #F8FAFC; }

.list-datetime { width: 70px; flex-shrink: 0; line-height: 1.1; }
.list-date { font-size: 8px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.list-time { font-size: 12px; font-weight: 900; color: var(--text); }

.list-id { width: 25px; flex-shrink: 0; font-size: 10px; color: var(--muted); text-align: center; font-weight: 600; }
.list-field { width: 25px; flex-shrink: 0; font-size: 10px; font-weight: 800; text-align: center; background: #F1F5F9; border-radius: 4px; padding: 2px 0; }

.list-team-home { flex: 1; text-align: right; font-weight: 800; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-team-away { flex: 1; text-align: left; font-weight: 800; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-score { width: 45px; text-align: center; font-weight: 900; font-size: 13px; flex-shrink: 0; background: #F8FAFC; padding: 4px 0; border-radius: 6px; }
.list-score.played { background: var(--primary); color: white; }


/* --- KORTTINÄKYMÄ (GRID) --- */
.match-list { display: flex; flex-direction: column; gap: 10px; }
.match-card { background: var(--white); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.match-meta { background: #F8FAFC; padding: 6px 12px; font-size: 9px; font-weight: 800; color: var(--muted); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #F1F5F9; text-transform: uppercase; }
.match-body { padding: 12px; display: grid; grid-template-columns: 5fr 2fr 5fr; align-items: center; text-align: center; gap: 8px; }
.team-name { font-weight: 900; font-size: 13px; line-height: 1.2; word-break: break-word; color: var(--text); }
.score-box { background: #F1F5F9; color: var(--muted); padding: 6px 4px; border-radius: 8px; font-weight: 900; font-size: 16px; text-align: center; white-space: nowrap; min-width: 45px; }
.score-box.played { background: var(--primary); color: white; }


/* --- TILA-INDIKAATTORIT (PALLUKAT JA TAGIT) --- */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.upcoming { background-color: #fde930; } 
.status-dot.playing { background-color: #10B981; box-shadow: 0 0 0 0 rgba(161, 229, 140, 0.7); animation: pulse-dot 1.5s infinite cubic-bezier(0.66, 0, 0, 1); }
.status-dot.played { background-color: #4E82A5; } 

@keyframes pulse-dot { to { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0); } }

.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; border-radius: 20px; font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }
.status-ongoing { background: #FEF3C7; color: #D97706; border: 1px solid #FCD34D; }
.status-finished { background: #D1FAE5; color: #059669; border: 1px solid #6EE7B7; }


/* --- MUUT & ANIMAATIOT --- */
.spinner { width: 32px; height: 32px; border: 3px solid #f3f3f3; border-top: 3px solid var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 50px auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); font-weight: 600; background: var(--white); border-radius: 12px; border: 1px solid var(--border); }
.update-time { text-align: right; font-size: 11px; font-weight: 800; color: var(--muted); margin-top: 10px; text-transform: uppercase; }


/* --- MOBIILIOPTIMOINTI --- */
@media (max-width: 640px) {
    .list-row { padding: 10px 4px; gap: 4px; }
    .list-datetime { width: 55px; }
    .list-time { font-size: 11px; }
    .list-field { width: 22px; font-size: 9px; }
    .list-team-home, .list-team-away { font-size: 11px; }
    .list-score { width: 40px; font-size: 12px; }
    .hide-mobile { display: none !important; }
    
    .table-wrapper th, .table-wrapper td { padding: 10px 8px; font-size: 12px; }
    .page-title { font-size: 24px; }
    .col-rank { font-size: 14px; }
}


/* --- TULOSTUS --- */
@media print {
    .no-print { display: none !important; }
    body { background: white; }
    .container { max-width: 100%; width: 100%; padding: 0; margin-top: 0; }
    .grid-layout { display: block; }
    .card { box-shadow: none; border: 1px solid #eee; margin-bottom: 20px; }
    .standings-container { align-self: auto; }
    .list-container { border: 1px solid #eee; box-shadow: none; }
    .hide-mobile { display: flex !important; }
}