/* Pro UX Upgrades: Backstage Strip, Podium, Mobile Bottom Bar, Live Age Check, Sticky Headers & Toasts */

/* 1. Backstage "Next 3 Up" Calling Strip */
.backstage-strip {
    margin-block-end: 16px;
    padding: 13px 15px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.backstage-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-block-end: 10px;
}

.backstage-head h3 {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.96rem;
    color: var(--ink);
}

.backstage-head svg {
    width: 17px;
    height: 17px;
    color: var(--brand);
}

.backstage-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.backstage-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--subtle);
    min-width: 0;
}

.backstage-card.is-ready {
    border-color: #9ed8c4;
    background: #effaf5;
}

html[data-theme="dark"] .backstage-card.is-ready {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.1);
}

.backstage-card > div {
    min-width: 0;
    flex: 1;
}

.backstage-card b {
    display: block;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.backstage-card small {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

/* 2. Quick Reorder Buttons & Single-Row Stage Action Bar */
.stage-pos-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.stage-pos-num {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    border-radius: 7px;
    background: var(--subtle);
    color: var(--ink);
    font-weight: 700;
    font-size: 0.84rem;
}

.reorder-btns {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
}

.reorder-btns .icon-btn {
    width: 22px;
    height: 17px;
    min-height: 17px;
    padding: 0;
    border-radius: 5px;
    background: var(--subtle);
}

.reorder-btns .icon-btn:hover {
    background: var(--active-surface);
    color: var(--active-ink);
    border-color: #9bb8e3;
}

.reorder-btns .icon-btn svg {
    width: 12px;
    height: 12px;
}

.stage-action-bar {
    flex-wrap: nowrap;
    gap: 6px;
}

.stage-action-bar .btn {
    min-height: 34px;
    padding: 4px 10px;
    font-size: 0.86rem;
    white-space: nowrap;
}

html[lang="dv"] .stage-action-bar .btn {
    font-size: 0.92rem;
    padding: 4px 10px;
}

.stage-action-bar .stage-more {
    width: 34px;
    min-height: 34px;
}

@media (max-width: 760px) {
    .stage-action-bar {
        flex-wrap: wrap;
    }
    .reorder-btns {
        flex-direction: row;
        gap: 4px;
    }
    .reorder-btns .icon-btn {
        width: 30px;
        height: 30px;
        min-height: 30px;
    }
}

/* 3. Live Age Eligibility Feedback on /register */
.age-feedback {
    margin-top: 4px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.age-feedback:empty {
    display: none;
}

.age-feedback.ok {
    background: #e7f7ef;
    color: #0e6b54;
    border: 1px solid #b6e3cd;
}

.age-feedback.err {
    background: #fce8ef;
    color: #a12b52;
    border: 1px solid #f4bfd1;
}

html[data-theme="dark"] .age-feedback.ok {
    background: rgba(16, 185, 129, 0.16);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.35);
}

html[data-theme="dark"] .age-feedback.err {
    background: rgba(244, 63, 94, 0.16);
    color: #fda4af;
    border-color: rgba(244, 63, 94, 0.35);
}

/* 4. Top-3 Gold / Silver / Bronze Podium on Results */
.podium-wrap {
    padding: 16px 17px 8px;
}

.podium-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

.podium-card {
    position: relative;
    display: grid;
    gap: 6px;
    padding: 16px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    text-align: center;
    box-shadow: var(--shadow);
}

.podium-card.rank-1 {
    border-color: #eab308;
    background: linear-gradient(180deg, #fffbeb 0%, var(--surface) 100%);
    padding-block: 22px 18px;
}

.podium-card.rank-2 {
    border-color: #94a3b8;
    background: linear-gradient(180deg, #f8fafc 0%, var(--surface) 100%);
}

.podium-card.rank-3 {
    border-color: #d97706;
    background: linear-gradient(180deg, #fff7ed 0%, var(--surface) 100%);
}

html[data-theme="dark"] .podium-card.rank-1 {
    background: linear-gradient(180deg, rgba(234, 179, 8, 0.16) 0%, var(--surface) 100%);
}

html[data-theme="dark"] .podium-card.rank-2 {
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.14) 0%, var(--surface) 100%);
}

html[data-theme="dark"] .podium-card.rank-3 {
    background: linear-gradient(180deg, rgba(217, 119, 6, 0.16) 0%, var(--surface) 100%);
}

.podium-medal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin: 0 auto;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.rank-1 .podium-medal { background: #fef3c7; color: #92400e; }
.rank-2 .podium-medal { background: #e2e8f0; color: #334155; }
.rank-3 .podium-medal { background: #ffedd5; color: #9a3412; }

.podium-card h3 {
    font-size: 1.08rem;
    overflow-wrap: anywhere;
}

.podium-score {
    font-size: 1.25rem;
    font-weight: 750;
    color: var(--brand);
}

/* 5. Table Row Count Pill & Desktop Sticky Headers */
.table-meta {
    margin-inline-start: auto;
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
}

@media (min-width: 761px) {
    .table-wrap {
        max-height: 68vh;
    }

    .table-wrap thead th {
        position: sticky;
        top: 0;
        z-index: 1;
        box-shadow: inset 0 -1px 0 var(--line);
    }
}

/* 6. Judge Summary Ready-to-Submit State */
.score-summary.ready-to-submit {
    border-color: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.16), var(--shadow);
}

.score-ready-note {
    margin-block-start: 6px;
    padding: 6px 9px;
    border-radius: 8px;
    background: #e7f7ef;
    color: #0e6b54;
    font-size: 0.82rem;
    font-weight: 600;
}

html[data-theme="dark"] .score-ready-note {
    background: rgba(16, 185, 129, 0.16);
    color: #6ee7b7;
}

/* 7. Semantic Toast Hierarchy */
#toast.toast-ok {
    background: #0d5c4d;
    border: 1px solid rgba(255, 255, 255, 0.14);
}

#toast.toast-warn {
    background: #92400e;
    border: 1px solid rgba(255, 255, 255, 0.16);
}

#toast.toast-err {
    background: #9f1239;
    border: 1px solid rgba(255, 255, 255, 0.16);
}

/* 8. Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 760px) {
    .backstage-cards,
    .podium-grid {
        grid-template-columns: 1fr;
    }

    .main,
    .public-main {
        padding-bottom: 84px;
    }

    .mobile-bottom-nav {
        position: fixed;
        inset-block-end: 0;
        inset-inline: 0;
        z-index: 6;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-block-start: 1px solid var(--line);
        box-shadow: 0 -4px 16px rgba(15, 36, 33, 0.08);
        padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    }

    html[data-theme="dark"] .mobile-bottom-nav {
        background: rgba(17, 34, 31, 0.96);
        box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.4);
    }

    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 50px;
        padding: 4px 2px;
        border-radius: 10px;
        color: var(--muted);
        font-size: 0.72rem;
        font-weight: 600;
        text-align: center;
    }

    .mobile-bottom-nav a svg {
        width: 19px;
        height: 19px;
    }

    .mobile-bottom-nav a.active,
    .mobile-bottom-nav a[aria-current="page"] {
        color: var(--brand);
        background: var(--active-surface);
    }

    #toast {
        inset-block-end: 72px;
    }
}

@media print {
    .mobile-bottom-nav {
        display: none !important;
    }
}

/* 9. Staff Quick-Login QR Modal */
.staff-qr-modal {
    display: grid;
    justify-items: center;
    gap: 12px;
    text-align: center;
}

.staff-qr-frame {
    padding: 14px;
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid var(--line);
    box-shadow: 0 6px 20px rgba(15, 36, 33, 0.08);
}

.staff-qr-frame .qr-svg {
    width: 220px;
    height: 220px;
    display: block;
    border: 0;
}

.staff-qr-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.staff-qr-expiry {
    font-size: 0.85rem;
    color: var(--muted);
}

/* 10. Accessible Skip-to-Content Link */
.skip-link {
    position: fixed;
    inset-block-start: -100px;
    inset-inline-start: 16px;
    z-index: 999;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    transition: inset-block-start 140ms ease;
}

.skip-link:focus {
    inset-block-start: 14px;
}

/* 11. Manager Performance Analytics Page */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-block-end: 16px;
    align-items: stretch;
}

.analytics-grid > .panel {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

.dist-chart {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    align-items: end;
    height: 170px;
    padding: 16px 14px 10px;
}

.dist-col {
    display: grid;
    grid-template-rows: auto 1fr auto;
    justify-items: center;
    align-items: end;
    height: 100%;
    gap: 6px;
}

.dist-bar-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.dist-bar {
    width: clamp(22px, 58%, 48px);
    min-height: 4px;
    border-radius: 7px 7px 2px 2px;
    background: linear-gradient(180deg, #168772 0%, #0d5c4d 100%);
    transition: height 280ms ease;
}

.dist-col.band-top .dist-bar {
    background: linear-gradient(180deg, #d49b38 0%, #b5832d 100%);
}

.dist-col.band-low .dist-bar {
    background: linear-gradient(180deg, #d16563 0%, #b2413f 100%);
}

.dist-val {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink);
}

.dist-label {
    font-size: 0.76rem;
    color: var(--muted);
}

.metric-row {
    display: grid;
    gap: 6px;
    padding: 11px 15px;
    border-block-start: 1px solid var(--line);
}

.metric-row:first-child {
    border-block-start: 0;
}

.metric-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.metric-row-top b {
    font-size: 0.94rem;
}

.metric-row-stats {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--muted);
}

@media (max-width: 760px) {
    .analytics-grid {
        grid-template-columns: 1fr;
    }
}

/* 12. Judge Self-Edit Audit Badges & History */
.tag.edited-mark {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b55;
}

.mark-edit-log {
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 10px;
    background: color-mix(in srgb, #f59e0b 9%, var(--surface));
    border: 1px solid color-mix(in srgb, #d97706 30%, var(--line));
}

.mark-edit-log h4 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 6px;
}

.mark-edit-entry {
    display: grid;
    gap: 3px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
    font-size: 0.84rem;
}

.mark-edit-entry:first-of-type {
    padding-top: 0;
    border-top: 0;
}

.mark-edit-delta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

/* 13. Live 3-Judge Status Strip & Buzz Reminder */
.judge-status-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 12px 0 16px;
}

.judge-status-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 13px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.judge-status-card.is-marked {
    border-color: color-mix(in srgb, #10b981 42%, var(--line));
    background: color-mix(in srgb, #10b981 6%, var(--surface));
}

.judge-status-card.is-buzzed {
    border-color: #f59e0b;
    background: color-mix(in srgb, #f59e0b 10%, var(--surface));
}

.judge-status-info {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.judge-status-info b {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.judge-status-info small {
    font-size: 0.76rem;
    color: var(--muted);
}

.buzz-btn {
    padding: 5px 10px;
    font-size: 0.78rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.buzz-alert-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 14px;
    border-radius: 12px;
    background: #fef3c7;
    color: #78350f;
    border: 1.5px solid #f59e0b;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.22);
    animation: buzzPulse 1.4s ease-in-out 3;
}

.buzz-alert-banner svg {
    flex: 0 0 auto;
    color: #d97706;
}

@keyframes buzzPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.012); }
}

@media (max-width: 760px) {
    .judge-status-strip {
        grid-template-columns: 1fr;
    }
}

/* 14. Percentage-Based Visual Score Quality (Bad -> Excellent) */
.score-card .score-range,
html[dir="rtl"] .score-card .score-range {
    --range-track: linear-gradient(
        to right,
        var(--score-color, var(--brand)) 0 var(--fill, 0%),
        color-mix(in srgb, var(--line) 90%, transparent) var(--fill, 0%) 100%
    );
    background: transparent;
}

html[data-theme="dark"] .score-card .score-range,
html[data-theme="dark"][dir="rtl"] .score-card .score-range {
    --range-track: linear-gradient(
        to right,
        var(--score-color, var(--brand)) 0 var(--fill, 0%),
        #2b3c59 var(--fill, 0%) 100%
    );
    background: transparent;
}

.score-card .score-range::-webkit-slider-thumb {
    border-color: var(--score-color, var(--brand));
}

.score-card .score-range::-moz-range-thumb {
    border-color: var(--score-color, var(--brand));
}

.score-tier-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.3;
    transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

.score-tier-badge.tier-poor {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #f87171;
}

.score-tier-badge.tier-fair {
    background: #ffedd5;
    color: #9a3412;
    border: 1px solid #fb923c;
}

.score-tier-badge.tier-good {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

.score-tier-badge.tier-very-good {
    background: #ccfbf1;
    color: #115e59;
    border: 1px solid #2dd4bf;
}

.score-tier-badge.tier-excellent {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.score-summary-tier {
    display: flex;
    justify-content: center;
    margin-bottom: 4px;
}
