/* Derby live page styles. Design tokens live in /css/_tokens.css. */
@import url("/css/_tokens.css");

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page); color: var(--text-primary); min-height: 100vh;
    transition: background-color 0.2s, color 0.2s;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white; padding: 1rem; text-align: center;
    box-shadow: var(--shadow-md);
}
.site-nav {
    display: flex; align-items: center; justify-content: space-between;
    max-width: 900px; margin: 0 auto; padding: 0.75rem 1rem;
}
.nav-logo { display: inline-flex; align-items: center; gap: 6px; font-size: 1.4rem; font-weight: 700; color: var(--text-primary); text-decoration: none; letter-spacing: -0.02em; }
.nav-logo-icon { flex-shrink: 0; }
.header h1 { font-size: 1.5rem; font-weight: 600; }
.header .subtitle { font-size: 0.875rem; opacity: 0.9; margin-top: 0.25rem; }

/* Theme toggle — inline variant; same class + icon-class contract as main site */
.theme-toggle {
    position: relative;
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem; line-height: 1;
    transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
}
.theme-toggle:hover { border-color: var(--primary); transform: scale(1.05); }
.theme-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.theme-toggle .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(0); }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0)      scale(1); }
[data-theme="light"] .theme-toggle .icon-sun  { opacity: 1; transform: rotate(0)     scale(1); }
[data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0); }

/* Container */
.container { max-width: 900px; margin: 0 auto; padding: 1rem; }

/* Status bar */
.status-bar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-surface); padding: 0.75rem 1rem; border-radius: 0.5rem;
    margin-bottom: 1rem; box-shadow: var(--shadow-sm);
}
.status-indicator { display: flex; align-items: center; gap: 0.5rem; }
.status-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--success); animation: pulse 2s infinite;
}
.status-dot.offline { background: var(--color-gray-300); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
.last-update { font-size: 0.75rem; color: var(--text-muted); }

/* Tabs */
.tabs {
    display: flex; background: var(--bg-surface); border-radius: 0.5rem;
    padding: 0.25rem; margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}
.tab {
    flex: 1; padding: 0.5rem 1rem; text-align: center;
    border: none; background: transparent; cursor: pointer;
    border-radius: 0.375rem; font-size: 0.875rem; font-weight: 500;
    color: var(--text-muted); transition: all 0.2s;
}
.tab.active { background: var(--primary); color: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Cards */
.card {
    background: var(--bg-surface); border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem; overflow: hidden;
}
.card-header {
    background: var(--bg-subtle); padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.card-body { padding: 1rem; }

/* Dashboard: Stats grid */
.tournament-info { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.info-item {
    text-align: center; padding: 0.75rem;
    background: var(--bg-subtle); border-radius: 0.5rem;
}
.info-item .label {
    font-size: 0.75rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.info-item .value { font-size: 1.5rem; font-weight: 700; color: var(--primary); }

/* Dashboard: Fights list */
.fights-list { list-style: none; }
.fight-item {
    display: flex; align-items: center; padding: 0.75rem;
    border-bottom: 1px solid var(--border-soft); gap: 0.5rem;
}
.fight-item:last-child { border-bottom: none; }
.fight-number { width: 2.5rem; font-size: 0.75rem; color: var(--text-muted); }
.fight-teams { flex: 1; display: flex; align-items: center; gap: 0.5rem; }
.fight-team {
    flex: 1; padding: 0.5rem; text-align: center; border-radius: 0.25rem;
    background: var(--bg-subtle); font-size: 0.875rem;
}
.fight-team.winner-green { background: var(--success); color: white; }
.fight-team.winner-red { background: var(--danger); color: white; }
.fight-team.loser { opacity: 0.6; }
.fight-vs { font-size: 0.75rem; color: var(--text-muted); }
.fight-outcome { width: 3rem; text-align: center; font-size: 0.75rem; font-weight: 600; }
.outcome-pending { color: var(--warning); }

/* Matches: Rounds */
.round {
    background: var(--bg-surface); border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 0.75rem; overflow: hidden;
}
.round-header {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.625rem 0.75rem; background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    cursor: pointer; user-select: none;
}
.round-header span { font-weight: 600; font-size: 0.875rem; }
.round-header .count { font-size: 0.75rem; color: var(--text-muted); font-weight: normal; }
.round-header .chevron { transition: transform 0.2s; font-size: 0.75rem; color: var(--text-muted); }
.round.collapsed .round-header .chevron { transform: rotate(-90deg); }
.round.collapsed .round-body { display: none; }

/* Matches: Fight rows (mobile) */
.match-fight { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border-soft); }
.match-fight:last-child { border-bottom: none; }
.fight-row {
    display: flex; align-items: center; gap: 0.375rem;
    font-size: 0.8125rem; line-height: 1.4;
}
/* Red row alignment handled by invisible spacers matching green row's dot + fight-num */
.result-dot {
    display: inline-block; width: 10px; height: 10px; min-width: 10px;
    border-radius: 50%; background: var(--color-gray-300); vertical-align: middle;
}
.result-dot.green-win { background: var(--success); }
.result-dot.red-win { background: var(--danger); }
.result-dot.draw { background: var(--color-gray-500); }
.fight-num { color: var(--text-muted); font-size: 0.75rem; min-width: 1.5rem; }
.team-id { font-weight: 600; min-width: 1.75rem; text-align: right; }
.team-id.green { color: var(--green-id); }
.team-id.red { color: var(--red-id); }
.team-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-name.green { color: var(--green-name); }
.team-name.red { color: var(--red-name); }
.dif-badge {
    background: var(--dif-bg); color: var(--dif-fg);
    padding: 0.125rem 0.375rem; border-radius: 0.25rem;
    font-size: 0.6875rem; font-weight: 500; white-space: nowrap;
}

/* Matches: Desktop table */
.desktop-table { display: none; }
@media (min-width: 768px) {
    .container { max-width: 1200px; }
    .site-nav { max-width: 1200px; }
    .match-fight { display: none; }
    .desktop-table { display: table; }
    .round-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
    .round-table thead th {
        padding: 0.5rem 0.75rem; text-align: left; font-weight: 600;
        font-size: 0.8125rem; color: var(--text-muted);
        border-bottom: 2px solid var(--border);
    }
    .round-table thead th.green-header { color: var(--green-id); border-bottom-color: var(--success); }
    .round-table thead th.red-header { color: var(--red-id); border-bottom-color: var(--danger); }
    .round-table thead th.center { text-align: center; }
    .round-table thead th.right { text-align: right; }
    .round-table tbody tr { border-bottom: 1px solid var(--border-soft); }
    .round-table tbody tr:nth-child(even) { background: var(--bg-subtle); }
    .round-table tbody tr:hover { background: var(--hover-row); }
    .round-table td { padding: 0.5rem 0.75rem; white-space: nowrap; }
    .round-table td.center { text-align: center; }
    .round-table td.right { text-align: right; }
    .round-table .green-id { color: var(--green-id); font-weight: 600; }
    .round-table .green-name { color: var(--green-name); }
    .round-table .red-id { color: var(--red-id); font-weight: 600; }
    .round-table .red-name { color: var(--red-name); }
    .round-table td.dim { color: var(--text-muted); }
    .round-table td.num-right { text-align: right; }
    .tournament-info { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
    .tournament-info { grid-template-columns: 1fr; }
}

/* Loading / Error */
.loading { text-align: center; padding: 3rem; color: var(--text-muted); }
.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { text-align: center; padding: 3rem; color: var(--text-muted); }

/* Scores tab — per-team pivot grid (see live-page.js: renderScores) */
.scores-table {
    width: 100%; border-collapse: collapse; font-size: 0.8125rem; margin-top: 0.5rem;
}
.scores-table thead th {
    padding: 0.5rem 0.5rem; text-align: center; font-weight: 600;
    color: var(--text-muted); border-bottom: 2px solid var(--border);
    font-size: 0.75rem; white-space: nowrap;
}
.scores-table thead th.scores-team-header { text-align: left; }
.scores-table tbody tr { border-bottom: 1px solid var(--border-soft); }
.scores-table tbody tr:nth-child(even) { background: var(--bg-subtle); }
.scores-table tbody tr:hover { background: var(--hover-row); }
.scores-team-cell { padding: 0.5rem 0.5rem; font-weight: 600; white-space: nowrap; }
.scores-team-cell .team-id { color: var(--text-primary); margin-right: 0.25rem; }
.scores-team-cell .team-name { color: var(--text-primary); }
.scores-cell {
    padding: 0.4rem 0.5rem; vertical-align: top; min-width: 200px;
    border-left: 1px solid var(--border-soft);
}
/* Mirrors the XAML TeamRoundCellTemplate grid: dot vertically centered across
   both rows, each side's team label + pin|weight horizontally centered within
   its equal-width column. */
.scores-cell-row {
    display: flex; gap: 0.5rem; align-items: center;
}
.scores-cell-row > .result-dot { flex-shrink: 0; }
.scores-cell-side { flex: 1 1 0; min-width: 0; text-align: center; }
.scores-cell-head {
    display: flex; justify-content: center; align-items: baseline; gap: 0.25rem;
    font-size: 0.8125rem; font-weight: 600; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scores-cell-head .team-id { font-weight: 700; }
.scores-cell-meta {
    font-size: 0.6875rem; line-height: 1.3; margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scores-cell-meta.green { color: var(--green-name); }
.scores-cell-meta.red   { color: var(--red-name); }
.scores-empty {
    padding: 0.4rem 0.5rem; text-align: center; color: var(--text-muted);
    border-left: 1px solid var(--border-soft);
}
.scores-total {
    padding: 0.5rem 0.75rem; font-weight: 700; color: var(--text-primary);
    border-left: 2px solid var(--border); font-size: 0.9375rem;
}
.scores-empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }

/* Mobile: collapse wide grid to one card per team with slot rows stacked */
@media (max-width: 720px) {
    .scores-table, .scores-table thead, .scores-table tbody,
    .scores-table tr, .scores-table th, .scores-table td {
        display: block;
    }
    .scores-table thead { display: none; }
    .scores-table tbody tr {
        margin-bottom: 0.75rem; padding: 0.5rem;
        border: 1px solid var(--border); border-radius: 0.5rem;
    }
    .scores-team-cell { font-size: 1rem; border-bottom: 1px solid var(--border-soft); margin-bottom: 0.25rem; }
    .scores-cell { border-left: none; padding: 0.25rem 0; }
    .scores-cell::before {
        content: attr(data-slot-label); display: block;
        font-size: 0.625rem; color: var(--text-muted); text-transform: uppercase;
    }
    .scores-empty { border-left: none; text-align: left; padding: 0.25rem 0; }
    .scores-total {
        border-left: none; border-top: 1px solid var(--border-soft);
        text-align: right; padding-top: 0.375rem; margin-top: 0.25rem;
    }
    .scores-total::before {
        content: attr(data-total-label); float: left; font-weight: 500;
        color: var(--text-muted); font-size: 0.8125rem;
    }
}

/* Footer */
.footer { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 0.75rem; }
.footer a { color: var(--primary); text-decoration: none; }
