:root {
    --app-primary: #0f3d8a;
    --app-primary-dark: #0a2a60;
    --tv-scale: 1;
    --tv-banner-overlap: 12px;
}

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

.app-top-banner {
    width: 100%;
    background: #ffffff;
}

.app-top-banner-img {
    display: block;
    width: 100%;
    height: clamp(68px, 14vw, 180px);
    object-fit: cover;
    object-position: center;
}

.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;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    background: radial-gradient(circle at 20% 20%, #123b86, #0a1d47 55%, #06112c);
    color: #f8fafc;
    overflow: hidden;
    font-family: "Segoe UI", Tahoma, sans-serif;
}

.tv-top-banner {
    flex-shrink: 0;
    position: relative;
    z-index: 12;
    margin-bottom: calc(-1 * var(--tv-banner-overlap));
    pointer-events: none;
}

.tv-top-banner .app-top-banner-img {
    height: calc(clamp(72px, 11vh, 136px) * var(--tv-scale));
}

.tv-topbar {
    min-height: calc(60px * var(--tv-scale));
    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);
    flex-shrink: 0;
}

.tv-brand {
    font-size: calc(1.6vw * var(--tv-scale));
    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: calc(0.95vw * var(--tv-scale));
}

.tv-scale-select {
    width: clamp(84px, 8vw, 115px);
}

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

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

.tv-icon-controls .btn i {
    font-size: calc(0.95rem * var(--tv-scale));
}

.tv-main {
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: calc((1vh * var(--tv-scale)) + var(--tv-banner-overlap)) calc(1vw * var(--tv-scale)) calc(1vh * var(--tv-scale));
    overflow: hidden;
    box-sizing: border-box;
}

.tv-main-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(150px, 12vw, 240px);
    gap: calc(0.8vw * var(--tv-scale));
}

.tv-content {
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.tv-right-sidebar {
    min-height: 0;
    height: 100%;
    border-radius: calc(0.9rem * var(--tv-scale));
    overflow: hidden;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.45);
    box-shadow: 0 0.4rem 1rem rgba(2, 8, 23, 0.2);
}

.tv-right-sidebar-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center;
}

.tv-footer {
    min-height: calc(44px * var(--tv-scale));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.45rem 1.1rem;
    color: #e2e8f0;
    background: rgba(6, 17, 44, 0.72);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    font-size: calc(0.85rem * var(--tv-scale));
    position: relative;
}

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

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

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

.tv-slide-header h2 {
    font-size: calc(1.6vw * var(--tv-scale));
    margin: 0;
    font-weight: 700;
}

.tv-table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.tv-table-wrap .table {
    font-size: calc(1.1vw * var(--tv-scale));
    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-event-icon-img {
    width: 1.8em;
    height: 1.8em;
    object-fit: cover;
    border-radius: 999px;
    border: 1px solid #c7d2fe;
    background: #fff;
}

.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;
}

.public-event-icon-img {
    width: 1.35rem;
    height: 1.35rem;
    object-fit: cover;
    border-radius: 999px;
    border: 1px solid #d7e1f8;
    background: #fff;
}

.public-event-icon-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
}

.public-page .public-nav-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.public-page #live-tally-table th,
.public-page #live-tally-table td,
.public-page #live-events-table th,
.public-page #live-events-table td {
    white-space: normal;
    vertical-align: middle;
}

.public-page #live-events-table td:nth-child(1) {
    min-width: 220px;
}

.public-footer {
    margin-top: 1rem;
    padding: 0.7rem 0;
    background: rgba(15, 61, 138, 0.95);
    color: #e6eefc;
    border-top: 1px solid rgba(255, 255, 255, 0.22);
    font-size: 0.9rem;
}


/* 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;
    }

    .public-page .public-nav-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .public-page #live-updated {
        width: 100%;
        display: block;
    }

    .public-footer {
        font-size: 0.83rem;
    }
}

@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;
    }

    .public-page #live-events-table th:nth-child(2),
    .public-page #live-events-table td:nth-child(2) {
        display: none;
    }

    .public-page #live-events-table td:nth-child(1) {
        min-width: 160px;
    }
}

@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;
    }

    .public-page .navbar .btn {
        padding: 0.25rem 0.45rem;
        font-size: 0.78rem;
    }

    .public-page #live-updated {
        font-size: 0.75rem;
    }

    .public-page #live-tally-table,
    .public-page #live-events-table {
        font-size: 0.8rem;
    }

    .public-footer {
        padding: 0.55rem 0;
        font-size: 0.78rem;
    }
}

@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; }
}
