:root {
    --app-primary: #0f3d8a;
    --app-primary-dark: #0a2a60;
}

body {
    font-family: "Segoe UI", Tahoma, sans-serif;
    overflow-x: hidden;
}

.brand-logo {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    background: #fff;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
    image-rendering: -webkit-optimize-contrast;
}

.brand-logo-alt {
    width: 30px;
    height: 30px;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.25));
}

.app-navbar {
    background: linear-gradient(135deg, var(--app-primary), #174ea6);
}

.app-card {
    border: 0;
    border-radius: 0.9rem;
    box-shadow: 0 0.35rem 1.25rem rgba(15, 61, 138, 0.08);
}

.app-card .card-body {
    padding: 1rem 1.1rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.table thead th {
    background: #eef4ff;
    color: #0d2b5f;
}

.medal-pill {
    border-radius: 999px;
    font-weight: 600;
    min-width: 2.25rem;
    display: inline-block;
    text-align: center;
}

.pill-gold { background: #fef3c7; color: #92400e; }
.pill-silver { background: #e5e7eb; color: #374151; }
.pill-bronze { background: #fed7aa; color: #9a3412; }

th.sortable::after {
    content: " \2195";
    font-size: 0.8rem;
    opacity: 0.5;
}

th.sortable[data-sort-dir="asc"]::after {
    content: " \2191";
    opacity: 0.9;
}

th.sortable[data-sort-dir="desc"]::after {
    content: " \2193";
    opacity: 0.9;
}

.search-input {
    max-width: 280px;
}

.school-logo {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 0.45rem;
    border: 1px solid #cdd6ea;
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 61, 138, 0.15);
    image-rendering: -webkit-optimize-contrast;
}

body.projector-mode {
    font-size: 1.15rem;
}

body.projector-mode .container {
    max-width: 96% !important;
}

body.projector-mode .navbar-brand {
    font-size: 1.4rem;
}

body.projector-mode .card {
    border-radius: 1rem;
}

body.projector-mode h2,
body.projector-mode .h5 {
    font-size: 1.5rem !important;
}

body.projector-mode .table {
    font-size: 1.08rem;
}

body.projector-mode .table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

body.projector-mode .search-input,
body.projector-mode #event-search,
body.projector-mode #school-search {
    max-width: 220px;
}

body.kiosk-mode .navbar .btn-outline-light,
body.kiosk-mode .navbar #manual-refresh {
    display: none;
}

body.kiosk-mode .navbar {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
}

body.kiosk-mode #live-updated {
    font-size: 0.85rem;
    opacity: 0.95;
}

body.kiosk-mode .card {
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.09);
}

/* TV board layout */
.tv-page {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, #123b86, #0a1d47 55%, #06112c);
    color: #f8fafc;
    overflow: hidden;
    font-family: "Segoe UI", Tahoma, sans-serif;
}

.tv-topbar {
    height: 9vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2vw;
    background: rgba(6, 17, 44, 0.6);
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.tv-brand {
    font-size: 1.6vw;
    font-weight: 700;
}

.tv-brand .brand-logo {
    width: 2.05rem;
    height: 2.05rem;
}

.tv-brand .brand-logo-alt {
    width: 1.75rem;
    height: 1.75rem;
}

.tv-meta {
    display: flex;
    align-items: center;
    gap: 0.7vw;
    font-size: 0.95vw;
}

.tv-icon-controls {
    display: flex;
    align-items: center;
    gap: 0.35vw;
}

.tv-icon-controls .btn {
    border-radius: 999px;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tv-icon-controls .btn i {
    font-size: 0.95rem;
}

.tv-main {
    height: 91vh;
    padding: 1vh 1vw;
}

.tv-swiper,
.tv-swiper .swiper-wrapper,
.tv-swiper .swiper-slide {
    width: 100%;
    height: 100%;
}

.tv-slide {
    background: rgba(255, 255, 255, 0.96);
    color: #0f172a;
    border-radius: 0.9rem;
    padding: 1.1vh 1vw;
    display: flex;
    flex-direction: column;
    gap: 0.8vh;
}

.tv-slide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tv-slide-header h2 {
    font-size: 1.6vw;
    margin: 0;
    font-weight: 700;
}

.tv-table-wrap {
    flex: 1;
    overflow: hidden;
}

.tv-table-wrap .table {
    font-size: 1.1vw;
    margin-bottom: 0;
}

.tv-table-wrap .table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #dbeafe;
}

.tv-events-slide .table-secondary td,
.tv-events-slide .table-light td {
    font-weight: 700;
}

.tv-sport-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8em;
    height: 1.8em;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 0.9em;
}

.tv-school-logo-icon {
    width: 1.55em;
    height: 1.55em;
    object-fit: cover;
    border-radius: 999px;
    border: 1px solid #c7d2fe;
    background: #fff;
    vertical-align: middle;
}

.tv-school-logo-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.55em;
    height: 1.55em;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    vertical-align: middle;
}

.tv-winner-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
}

.tv-school-logo-mini {
    width: 1.2em;
    height: 1.2em;
    object-fit: cover;
    border-radius: 999px;
    border: 1px solid #dbe3f2;
    background: #fff;
}

/* Global responsive tuning for app/public pages (excludes tv-specific classes). */
@media (max-width: 991.98px) {
    .navbar-brand {
        font-size: 0.98rem;
    }

    .navbar .badge.text-bg-light {
        display: none;
    }

    .container.py-4 {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .search-input {
        max-width: 100%;
    }

    .table {
        font-size: 0.94rem;
    }

    .d-flex.flex-wrap.align-items-center.gap-2 .form-control-sm,
    .d-flex.flex-wrap.align-items-center.gap-2 .form-select-sm {
        min-width: 140px;
    }
}

@media (max-width: 767.98px) {
    .app-card {
        border-radius: 0.8rem;
    }

    .app-card .card-body {
        padding: 0.9rem;
    }

    .h4 {
        font-size: 1.2rem;
    }

    .h5 {
        font-size: 1rem;
    }

    .stat-value {
        font-size: 1.6rem;
    }

    .brand-logo {
        width: 30px;
        height: 30px;
    }

    .brand-logo-alt {
        width: 26px;
        height: 26px;
    }

    .school-logo {
        width: 36px;
        height: 36px;
    }

    .btn-group[role="group"] {
        width: 100%;
    }

    .btn-group[role="group"] .btn {
        flex: 1 1 auto;
    }
}

@media (max-width: 575.98px) {
    .navbar-brand span {
        display: inline-block;
        max-width: 150px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .table {
        font-size: 0.88rem;
    }

    .medal-pill {
        min-width: 2rem;
    }
}

@media (max-width: 1200px) {
    .tv-brand { font-size: 1.1rem; }
    .tv-meta { font-size: 0.85rem; }
    .tv-slide-header h2 { font-size: 1.1rem; }
    .tv-table-wrap .table { font-size: 0.9rem; }
}
