/* Event Day mobile/tablet reusable layout utilities.
   Layout only: theme colours continue to come from competition-theme-light.css and competition-theme-dark.css. */

body.competition-shell .cm-mobile-page {
    --cm-mobile-sticky-offset: 0px;
}

body.competition-shell .cm-mobile-card-list {
    display: grid;
    gap: .85rem;
}

body.competition-shell .cm-mobile-card {
    min-width: 0;
}

body.competition-shell .cm-mobile-sticky-actions {
    border-top: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
}

body.competition-shell .cm-page--judge-mark .judge-action-bar,
body.competition-shell .cm-page--judge-mark .cm-mobile-sticky-actions,
body.competition-shell .cm-page--judge-dashboard .judge-finish-footer.cm-mobile-sticky-actions {
    position: static !important;
    top: auto !important;
    bottom: auto !important;
    z-index: auto !important;
    backdrop-filter: none !important;
}

body.competition-shell .cm-mobile-collapsible-context {
    margin-bottom: 1rem;
}

body.competition-shell .cm-mobile-context-summary {
    display: none;
}

body.competition-shell .cm-mobile-context-details .stage-context-bar {
    margin-bottom: 0 !important;
}

body.competition-shell .judge-card-meta-grid {
    display: grid;
    gap: .6rem;
}

body.competition-shell .judge-card-meta-value {
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text))) !important;
    font-size: 1rem !important;
}

body.competition-shell .judge-mark-back-row {
    margin-bottom: .75rem;
}

body.competition-shell .judge-back-link {
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

body.competition-shell .judge-criteria-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

body.competition-shell .judge-criteria-generic-title {
    display: block;
}

body.competition-shell .cm-page--judge-mark .judge-action-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.competition-shell .cm-mobile-access-accordion {
    display: grid;
    gap: .9rem;
}

body.competition-shell .cm-mobile-access-item {
    color: var(--cm-body-text, var(--cm-text)) !important;
    background: var(--cm-stage-live-action-group-bg, var(--cm-soft-bg, var(--cm-surface))) !important;
    border: 1px solid var(--cm-stage-live-action-group-border, var(--cm-surface-border, var(--cm-border))) !important;
    border-radius: var(--cm-radius-card-sm, 1rem) !important;
    overflow: hidden;
}

body.competition-shell .cm-mobile-access-toggle {
    color: var(--cm-heading-text, var(--cm-text)) !important;
    background: transparent !important;
    box-shadow: none !important;
    font-weight: 900;
    gap: .2rem;
    min-height: 4.25rem;
}

body.competition-shell .cm-mobile-access-toggle:not(.collapsed) {
    color: var(--cm-heading-text, var(--cm-text)) !important;
    background: var(--cm-hover-bg, transparent) !important;
    border-bottom: 1px solid var(--cm-stage-live-action-group-border, var(--cm-surface-border, var(--cm-border)));
}

body.competition-shell .cm-mobile-access-toggle::after {
    filter: var(--cm-accordion-arrow-filter, none);
}

body.competition-shell .cm-mobile-access-form {
    display: grid;
    gap: .2rem;
}

body.competition-shell .cm-event-access-input--name {
    letter-spacing: normal;
    text-transform: none;
}

@media (max-width: 1023.98px) {
    body.competition-shell .cm-mobile-page {
        --cm-mobile-sticky-offset: 3.6rem;
    }

    body.competition-shell .cm-page--judge-access .cm-event-access-header {
        align-items: flex-start;
    }

    body.competition-shell .cm-page--judge-access .cm-event-access-subtitle {
        font-size: .92rem;
    }

    body.competition-shell .cm-page--judge-access .cm-event-access-card .card-body {
        padding: .85rem;
    }

    body.competition-shell .cm-page--judge-access .cm-mobile-access-toggle {
        font-size: 1rem;
        padding: .95rem;
        text-align: left;
    }

    body.competition-shell .cm-page--judge-access .accordion-body {
        padding: .95rem;
    }

    body.competition-shell .cm-page--judge-access .cm-event-access-actions {
        justify-content: stretch;
        margin-top: 1rem;
    }

    body.competition-shell .cm-page--judge-access .cm-event-access-actions .btn {
        width: 100%;
        min-height: 3.1rem;
    }

    body.competition-shell .cm-page--judge-dashboard .stage-context-main,
    body.competition-shell .cm-page--judge-mark .stage-context-main {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .5rem;
    }

    body.competition-shell .cm-page--judge-dashboard .stage-context-pill,
    body.competition-shell .cm-page--judge-mark .stage-context-pill {
        width: 100%;
        justify-content: space-between;
        min-width: 0;
    }

    body.competition-shell .judge-dashboard-card .card-header {
        padding: .9rem;
    }

    body.competition-shell .judge-dashboard-card .card-header .btn {
        width: 100%;
    }

    body.competition-shell .judge-mobile-list {
        padding: .85rem;
    }

    body.competition-shell .judge-card-main-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    body.competition-shell .judge-chest-card {
        padding: .95rem;
    }

    body.competition-shell .judge-card-status,
    body.competition-shell .judge-enter-mark-btn {
        width: 100%;
    }

    body.competition-shell .judge-status-badge,
    body.competition-shell .judge-enter-mark-btn {
        justify-content: center;
    }

    body.competition-shell .judge-card-meta-grid {
        gap: .7rem;
    }

    body.competition-shell .judge-card-total-row {
        border: 1px solid var(--cm-stage-live-pill-border, var(--cm-surface-border, var(--cm-border)));
        border-radius: .8rem;
        background: var(--cm-stage-live-pill-bg, var(--cm-control-bg, var(--cm-surface)));
        padding: .7rem .8rem;
    }

    body.competition-shell .judge-finish-footer {
        position: static !important;
        bottom: auto !important;
        z-index: auto !important;
        background: var(--cm-stage-live-card-footer-bg, var(--cm-surface-bg, var(--cm-surface))) !important;
        backdrop-filter: none !important;
    }

    body.competition-shell .judge-mark-back-row {
        padding: .25rem 0 .6rem;
        margin-bottom: .5rem;
    }

    body.competition-shell .judge-back-link {
        width: 100%;
    }

    body.competition-shell .cm-mobile-collapsible-context {
        position: static !important;
        top: auto !important;
        z-index: auto !important;
        background: var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface))) !important;
        border: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
        border-radius: var(--cm-radius-card-sm, 1rem);
        box-shadow: var(--cm-shadow-card, 0 12px 30px rgba(15, 23, 42, .12));
        overflow: hidden;
    }

    body.competition-shell .cm-mobile-context-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .65rem;
        width: 100%;
        border: 0;
        background: var(--cm-stage-live-action-group-bg, var(--cm-control-bg, var(--cm-surface))) !important;
        color: var(--cm-heading-text, var(--cm-text)) !important;
        padding: .75rem .85rem;
        text-align: left;
    }

    body.competition-shell .cm-mobile-context-summary-text {
        display: grid;
        gap: .12rem;
        min-width: 0;
    }

    body.competition-shell .cm-mobile-context-summary-text strong,
    body.competition-shell .cm-mobile-context-summary-text span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.competition-shell .cm-mobile-context-summary-text span,
    body.competition-shell .cm-mobile-context-summary-total {
        color: var(--cm-muted-text, var(--cm-text-muted)) !important;
        font-size: .78rem;
        font-weight: 800;
    }

    body.competition-shell .cm-mobile-context-summary-total {
        display: grid;
        gap: .05rem;
        flex: 0 0 auto;
        text-align: right;
        white-space: nowrap;
    }

    body.competition-shell .cm-mobile-context-summary-total strong {
        color: var(--cm-heading-text, var(--cm-text)) !important;
        font-size: .95rem;
    }

    body.competition-shell .cm-mobile-context-chevron {
        flex: 0 0 auto;
        transition: transform .18s ease;
    }

    body.competition-shell .cm-mobile-collapsible-context.is-collapsed .cm-mobile-context-chevron {
        transform: rotate(180deg);
    }

    body.competition-shell .cm-mobile-context-details {
        padding: .65rem;
    }

    body.competition-shell .cm-mobile-collapsible-context.is-collapsed .cm-mobile-context-details {
        display: none;
    }

    body.competition-shell .judge-current-total-pill {
        grid-column: 1 / -1;
        justify-content: space-between;
        font-size: 1rem;
    }

    body.competition-shell .judge-section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    body.competition-shell .judge-total-pill {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        font-size: 1rem;
    }

    body.competition-shell .judge-criteria-card {
        grid-template-columns: 1fr;
        gap: .75rem;
        padding: .9rem;
    }

    body.competition-shell .judge-criteria-generic-title {
        display: block;
    }

    body.competition-shell .judge-min-max {
        margin-top: .45rem;
    }

    body.competition-shell .judge-mark-entry {
        grid-template-columns: 1fr auto;
    }

    body.competition-shell .judge-mark-input {
        width: 100%;
        min-height: 3.35rem;
        font-size: 1.5rem;
    }

    body.competition-shell .judge-action-bar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: .75rem;
        padding: .85rem 0 0;
        margin-top: .75rem;
        position: static !important;
        bottom: auto !important;
        z-index: auto !important;
        background: transparent !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
    }

    body.competition-shell .judge-action-btn {
        width: 100%;
        min-height: 3rem;
        padding-left: .75rem;
        padding-right: .75rem;
    }

    body.competition-shell .judge-comment-card {
        margin-bottom: 1rem !important;
    }

}

@media (max-width: 575.98px) {
    body.competition-shell .cm-page--judge-dashboard .stage-context-main,
    body.competition-shell .cm-page--judge-mark .stage-context-main {
        grid-template-columns: 1fr;
    }

    body.competition-shell .judge-action-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Judge Portal mobile/tablet correction: context and action buttons must stay in normal page flow. */
body.competition-shell .cm-page--judge-mark .judge-mark-back-row,
body.competition-shell .cm-page--judge-mark .cm-mobile-collapsible-context,
body.competition-shell .cm-page--judge-mark .cm-mobile-context-summary,
body.competition-shell .cm-page--judge-mark .judge-action-bar,
body.competition-shell .cm-page--judge-mark .judge-action-btn,
body.competition-shell .cm-page--judge-dashboard .cm-mobile-collapsible-context,
body.competition-shell .cm-page--judge-dashboard .cm-mobile-context-summary,
body.competition-shell .cm-page--judge-dashboard .judge-finish-footer {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
}

/* Judge Portal mobile/tablet action surface: buttons stay in normal flow but sit on a clear card/footer background. */
@media (max-width: 1023.98px) {
    body.competition-shell .cm-page--judge-mark .judge-action-bar {
        position: static !important;
        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: .75rem;
        margin: 1rem 0 0;
        padding: .85rem;
        background: var(--cm-stage-live-card-footer-bg, var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface)))) !important;
        border: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border))) !important;
        border-radius: var(--cm-radius-card-sm, 1rem) !important;
        box-shadow: var(--cm-shadow-card, 0 12px 30px rgba(15, 23, 42, .10));
        backdrop-filter: none !important;
    }

    body.competition-shell .cm-page--judge-mark .judge-action-btn {
        min-width: 0;
        min-height: 3rem;
        width: 100%;
        justify-content: center;
        white-space: nowrap;
        font-size: clamp(.9rem, 3.4vw, 1rem);
    }

    body.competition-shell .cm-page--judge-dashboard .judge-finish-footer {
        margin-top: 1rem;
        background: var(--cm-stage-live-card-footer-bg, var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface)))) !important;
        border-top: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border))) !important;
        backdrop-filter: none !important;
    }
}

/* Reusable inline edit badge/action. Use when a compact context badge needs a small edit action beside its value. */
body.competition-shell .cm-inline-edit-badge {
    display: inline-flex !important;
    align-items: center;
    gap: .35rem;
    min-width: 0;
}

body.competition-shell .cm-inline-edit-badge .cm-inline-edit-label,
body.competition-shell .cm-inline-edit-badge .cm-inline-edit-value {
    min-width: 0;
}

body.competition-shell .cm-inline-edit-badge .cm-inline-edit-value {
    max-width: 15ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.competition-shell .cm-inline-edit-action {
    appearance: none;
    border: 1px solid var(--cm-stage-live-pill-warning-border, var(--cm-stage-live-code-highlight-border, var(--cm-border)));
    background: var(--cm-stage-live-pill-warning-bg, var(--cm-stage-live-code-highlight-bg, transparent));
    color: var(--cm-stage-live-warning-text, var(--cm-link-accent, var(--cm-primary))) !important;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font: inherit;
    font-size: .72rem;
    font-weight: 900;
    line-height: 1;
    min-height: 1.45rem;
    padding: .18rem .48rem;
    text-transform: none;
    white-space: nowrap;
    text-decoration: none;
}

body.competition-shell .cm-inline-edit-action:hover,
body.competition-shell .cm-inline-edit-action:focus-visible {
    background: var(--cm-stage-live-code-highlight-bg, var(--cm-hover-bg, var(--cm-control-bg)));
    color: var(--cm-stage-live-code-highlight-value, var(--cm-link-accent, var(--cm-primary))) !important;
    outline: none;
    box-shadow: 0 0 0 .16rem rgba(245, 158, 11, .18);
}

body.competition-shell .cm-inline-edit-badge--compact {
    gap: .28rem;
    max-width: 100%;
}

body.competition-shell .cm-inline-edit-badge--compact .cm-inline-edit-label::after {
    content: ":";
}

body.competition-shell .cm-inline-edit-badge--plain .cm-inline-edit-action {
    min-height: 1.3rem;
    padding: .12rem .38rem;
    font-size: .68rem;
}

@media (max-width: 1023.98px) {
    body.competition-shell .cm-mobile-context-summary-text .cm-inline-edit-badge {
        color: var(--cm-muted-text, var(--cm-text-muted)) !important;
        font-size: .78rem;
        font-weight: 800;
        max-width: 100%;
        overflow: hidden;
        white-space: nowrap;
    }

    body.competition-shell .cm-mobile-context-summary-text .cm-inline-edit-label {
        flex: 0 0 auto;
    }

    body.competition-shell .cm-mobile-context-summary-text .cm-inline-edit-value {
        color: var(--cm-heading-text, var(--cm-text)) !important;
        flex: 0 1 auto;
        max-width: 15ch;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
}

/* Judge Dashboard chest-number accordion: compact rows for quick scanning on mobile/tablet. */
body.competition-shell .judge-chest-accordion-list {
    gap: .55rem;
}

/* Judge Portal full marksheet: landscape phones and every tablet/laptop use one inline grid. */
body.competition-shell .cm-page--judge-dashboard .judge-mobile-list {
    display: none !important;
}

body.competition-shell .cm-page--judge-dashboard .judge-marksheet-grid-view {
    display: block !important;
    margin-top: 1rem;
}

body.competition-shell .judge-grid-summary-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .65rem;
}

body.competition-shell .judge-grid-summary-actions {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
}

body.competition-shell .judge-view-criteria-btn {
    display: inline-flex;
    min-height: 2.65rem;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    padding: .5rem .85rem;
    white-space: nowrap;
}

body.competition-shell .judge-focus-enter,
body.competition-shell .judge-focus-exit {
    display: inline-flex;
    width: 2.65rem;
    min-width: 2.65rem;
    height: 2.65rem;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
    background: var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface)));
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text))) !important;
}

body.competition-shell .judge-focus-toolbar {
    display: none;
}

body.competition-shell.judge-focus-mode {
    overflow: hidden !important;
}

body.competition-shell.judge-focus-mode .judge-criteria-modal,
body.competition-shell.judge-focus-mode .judge-comment-modal {
    z-index: 1080 !important;
}

body.competition-shell.judge-focus-mode .modal-backdrop {
    z-index: 1070 !important;
}

body.competition-shell .judge-marksheet-grid-view.is-focus-mode {
    position: fixed;
    inset: 0;
    z-index: 1040;
    display: flex !important;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0 !important;
    flex-direction: column;
    overflow: hidden;
    background: var(--cm-stage-live-card-bg, var(--cm-body-bg, var(--cm-surface)));
}

body.competition-shell .judge-marksheet-grid-view.is-focus-mode .judge-focus-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    flex: 0 0 auto;
    align-items: center;
    gap: .75rem;
    min-height: 3.5rem;
    padding: max(.55rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) .55rem max(.75rem, env(safe-area-inset-left));
    border-bottom: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
    background: var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface)));
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text)));
    box-shadow: 0 .25rem .75rem rgba(15, 23, 42, .10);
}

body.competition-shell .judge-view-criteria-btn--focus {
    min-height: 2.45rem;
    padding-top: .35rem;
    padding-bottom: .35rem;
}

body.competition-shell .judge-criteria-modal-dialog {
    width: min(46rem, calc(100% - 2rem));
    max-width: 46rem;
}

body.competition-shell .judge-criteria-modal-content {
    max-height: min(48rem, calc(100dvh - 2rem));
    border-color: var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
    background: var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface)));
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text)));
}

body.competition-shell .judge-criteria-modal-context {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem .7rem;
    margin-top: .2rem;
    color: var(--cm-stage-live-muted, var(--cm-muted-text, var(--cm-text-muted)));
    font-size: .82rem;
}

body.competition-shell .judge-criteria-modal-list {
    display: grid;
    gap: .75rem;
}

body.competition-shell .judge-criteria-modal-card {
    display: grid;
    grid-template-columns: 3rem minmax(0, 1fr);
    gap: .8rem;
    padding: .9rem;
    border: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
    border-radius: .9rem;
    background: var(--cm-stage-live-action-group-bg, var(--cm-control-bg, var(--cm-surface)));
}

body.competition-shell .judge-criteria-modal-number {
    display: inline-flex;
    width: 3rem;
    height: 3rem;
    align-items: center;
    justify-content: center;
    border-radius: .8rem;
    background: rgba(245, 158, 11, .18);
    color: var(--cm-stage-live-warning-text, #b45309);
    font-weight: 950;
}

body.competition-shell .judge-criteria-modal-title {
    font-size: 1rem;
    font-weight: 900;
}

body.competition-shell .judge-criteria-modal-description {
    margin-top: .3rem;
    color: var(--cm-stage-live-muted, var(--cm-muted-text, var(--cm-text-muted)));
    line-height: 1.45;
}

body.competition-shell .judge-criteria-modal-range {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    margin-top: .6rem;
    font-size: .82rem;
}

@media (max-width: 575.98px) {
    body.competition-shell .judge-criteria-modal-dialog {
        width: 100%;
        max-width: none;
        height: 100%;
        min-height: 100dvh;
        margin: 0;
    }

    body.competition-shell .judge-criteria-modal-content {
        width: 100%;
        min-height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    body.competition-shell .judge-criteria-modal-card {
        grid-template-columns: 2.65rem minmax(0, 1fr);
        gap: .7rem;
        padding: .8rem;
    }

    body.competition-shell .judge-criteria-modal-number {
        width: 2.65rem;
        height: 2.65rem;
    }

    body.competition-shell .judge-focus-title {
        display: none;
    }

    body.competition-shell .judge-marksheet-grid-view.is-focus-mode .judge-focus-toolbar {
        grid-template-columns: minmax(0, 1fr) auto auto;
    }

    body.competition-shell .judge-view-criteria-btn--focus span {
        display: none;
    }

    body.competition-shell .judge-view-criteria-btn--focus {
        width: 2.45rem;
        min-width: 2.45rem;
        padding-left: 0;
        padding-right: 0;
    }
}

body.competition-shell .judge-focus-title {
    min-width: 0;
    font-size: 1rem;
    font-weight: 900;
}

body.competition-shell .judge-focus-title-short,
body.competition-shell .judge-comment-landscape-actions {
    display: none;
}

body.competition-shell .judge-focus-progress {
    color: var(--cm-stage-live-muted, var(--cm-muted-text, var(--cm-text-muted)));
    font-size: .82rem;
    font-weight: 800;
    white-space: nowrap;
}

body.competition-shell .judge-focus-progress strong {
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text)));
}

body.competition-shell .judge-marksheet-grid-view.is-focus-mode .judge-marksheet-scroll {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    max-height: none;
    overflow: auto !important;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: max(1rem, env(safe-area-inset-bottom));
    border-top: 0;
    border-bottom: 0;
}

body.competition-shell .judge-marksheet-grid-view.is-focus-mode .judge-marksheet-scroll::after {
    display: block;
    height: max(.75rem, env(safe-area-inset-bottom));
    content: "";
}

body.competition-shell .judge-marksheet-grid-view.is-focus-mode .judge-grid-footer {
    display: none;
}

body.competition-shell .cm-page--judge-dashboard.judge-layout-phone-portrait .judge-marksheet-grid-view {
    display: none !important;
}

body.competition-shell .cm-page--judge-dashboard.judge-layout-phone-portrait .judge-focus-enter {
    display: none;
}

body.competition-shell .cm-page--judge-dashboard.judge-layout-phone-portrait .judge-marksheet-grid-view.is-focus-mode {
    display: flex !important;
}

body.competition-shell .cm-page--judge-dashboard.judge-layout-phone-portrait .judge-mobile-list {
    display: grid !important;
}

body.competition-shell .cm-page--judge-dashboard.judge-layout-grid .judge-marksheet-grid-view {
    display: block !important;
}

body.competition-shell .cm-page--judge-dashboard.judge-layout-grid .judge-mobile-list {
    display: none !important;
}

body.competition-shell .judge-marksheet-scroll {
    max-width: 100%;
    max-height: clamp(18rem, 62dvh, 42rem);
    overflow: auto;
    overscroll-behavior-inline: contain;
    border-top: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
    border-bottom: 1px solid var(--cm-stage-live-card-border, var(--cm-surface-border, var(--cm-border)));
}

body.competition-shell .judge-marksheet-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--cm-stage-live-text, var(--cm-body-text, var(--cm-text)));
}

body.competition-shell .judge-marksheet-table th,
body.competition-shell .judge-marksheet-table td {
    vertical-align: middle;
    padding: .55rem .45rem;
    border-right: 1px solid var(--cm-stage-live-table-border-soft, var(--cm-surface-border, var(--cm-border)));
    border-bottom: 1px solid var(--cm-stage-live-table-border-soft, var(--cm-surface-border, var(--cm-border)));
    background: var(--cm-stage-live-card-bg, var(--cm-surface-bg, var(--cm-surface)));
}

body.competition-shell .judge-marksheet-table thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text)));
    background: var(--cm-stage-live-action-group-bg, var(--cm-control-bg, var(--cm-surface)));
    font-size: .78rem;
    font-weight: 900;
    text-align: center;
    white-space: nowrap;
    box-shadow: inset 0 -.14rem 0 var(--cm-stage-live-table-border, var(--cm-surface-border, var(--cm-border)));
}

body.competition-shell .judge-marksheet-table thead th small {
    display: block;
    color: var(--cm-stage-live-muted, var(--cm-muted-text, var(--cm-text-muted)));
    font-size: .66rem;
    font-weight: 800;
}

body.competition-shell .judge-marksheet-table .judge-grid-chest {
    position: sticky;
    left: 0;
    z-index: 3;
    width: 5.5rem;
    min-width: 5.5rem;
    box-shadow: .35rem 0 .55rem rgba(15, 23, 42, .08);
}

body.competition-shell .judge-marksheet-table thead .judge-grid-chest {
    z-index: 7;
    box-shadow: inset 0 -.14rem 0 var(--cm-stage-live-table-border, var(--cm-surface-border, var(--cm-border))),
        .35rem 0 .55rem rgba(15, 23, 42, .08);
}

body.competition-shell .judge-grid-chest-label {
    display: inline-flex;
    align-items: center;
    gap: .42rem;
    white-space: nowrap;
}

body.competition-shell .judge-grid-row-status-icon {
    flex: 0 0 auto;
    font-size: .82rem;
}

body.competition-shell .judge-marksheet-table tbody tr.judge-grid-row-complete > td {
    background: rgba(34, 197, 94, .08) !important;
}

body.competition-shell .judge-marksheet-table tbody tr.judge-grid-row-draft > td {
    background: rgba(14, 165, 233, .07) !important;
}

body.competition-shell .judge-marksheet-table tbody tr.judge-grid-row-waiting > td {
    background: rgba(148, 163, 184, .08) !important;
}

body.competition-shell .judge-grid-row-complete .judge-grid-row-status-icon {
    color: var(--cm-stage-live-success-text, #15803d);
}

body.competition-shell .judge-grid-row-draft .judge-grid-row-status-icon {
    color: var(--cm-stage-live-accent, #0284c7);
}

body.competition-shell .judge-grid-row-waiting .judge-grid-row-status-icon {
    color: var(--cm-stage-live-muted, var(--cm-muted-text, #64748b));
}

body.competition-shell .judge-grid-criterion {
    min-width: 6rem;
    text-align: center;
}

body.competition-shell .judge-grid-mark-control {
    position: relative;
    width: 5.2rem;
    margin: 0 auto;
}

body.competition-shell .judge-grid-mark-input {
    width: 100%;
    min-height: 2.45rem;
    margin: 0;
    padding: .35rem 1.25rem .35rem .25rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 900;
}

body.competition-shell .judge-grid-mark-input.is-invalid {
    padding-right: 1.25rem;
    background-image: none !important;
}

body.competition-shell .judge-grid-field-save-state {
    position: absolute;
    top: 50%;
    right: .3rem;
    display: inline-flex;
    width: .95rem;
    height: .95rem;
    align-items: center;
    justify-content: center;
    color: transparent;
    font-size: .82rem;
    line-height: 1;
    pointer-events: none;
    transform: translateY(-50%);
}

body.competition-shell .judge-grid-field-save-state.is-saving {
    color: var(--cm-stage-live-accent, #1d4ed8);
}

body.competition-shell .judge-grid-field-save-state.is-saving .bi {
    animation: judge-grid-field-spin .8s linear infinite;
}

body.competition-shell .judge-grid-field-save-state.is-saved {
    color: var(--cm-stage-live-success-text, #15803d);
}

body.competition-shell .judge-grid-field-save-state.is-error {
    color: var(--cm-stage-live-danger-text, #b91c1c);
}

@keyframes judge-grid-field-spin {
    to {
        transform: rotate(360deg);
    }
}

body.competition-shell .judge-grid-total {
    min-width: 5rem;
    text-align: center;
}

body.competition-shell .judge-grid-comment {
    min-width: 4.25rem;
    text-align: center;
}

body.competition-shell .judge-grid-comment-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.35rem;
    min-width: 2.35rem;
    height: 2.35rem;
    padding: 0;
    border: 1px solid var(--cm-stage-live-pill-border, var(--cm-surface-border, var(--cm-border)));
    background: var(--cm-stage-live-pill-bg, var(--cm-control-bg, var(--cm-surface)));
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text))) !important;
    white-space: nowrap;
}

body.competition-shell .judge-grid-comment-btn.has-comment {
    border-color: rgba(245, 158, 11, .72);
    background: rgba(245, 158, 11, .18);
    color: var(--cm-stage-live-warning-text, #b45309) !important;
}

body.competition-shell .judge-grid-empty-row td {
    padding: 2rem 1rem;
    color: var(--cm-stage-live-muted, var(--cm-muted-text, var(--cm-text-muted)));
    font-weight: 800;
    text-align: center;
}

body.competition-shell .judge-marksheet-table tbody tr.judge-grid-performing > td {
    background: rgba(245, 158, 11, .20) !important;
    border-top-color: rgba(245, 158, 11, .72) !important;
    border-bottom-color: rgba(245, 158, 11, .72) !important;
}

body.competition-shell .judge-marksheet-table tbody tr.judge-grid-performing > td:first-child {
    box-shadow: inset .3rem 0 0 #f59e0b;
}

body.competition-shell .judge-marksheet-table tbody tr.judge-grid-performing .judge-grid-chest {
    background: rgba(245, 158, 11, .26) !important;
}

body.competition-shell .judge-grid-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1.25rem;
    padding: .7rem 1rem;
    color: var(--cm-stage-live-muted, var(--cm-muted-text, var(--cm-text-muted)));
    font-size: .82rem;
    font-weight: 800;
}

body.competition-shell .judge-grid-footer strong {
    color: var(--cm-stage-live-heading, var(--cm-heading-text, var(--cm-text)));
}

/* Landscape phone focus mode: preserve the full marks grid while the native keyboard is open. */
@media (max-width: 1023.98px) and (max-height: 575.98px) and (orientation: landscape) {
    body.competition-shell .judge-marksheet-grid-view.is-focus-mode {
        inset: auto;
        top: var(--judge-visual-top, 0);
        left: var(--judge-visual-left, 0);
        width: var(--judge-visual-width, 100vw);
        height: var(--judge-visual-height, 100dvh);
    }

    body.competition-shell .judge-marksheet-grid-view.is-focus-mode .judge-focus-toolbar {
        grid-template-columns: auto minmax(0, 1fr) auto auto;
        gap: .4rem;
        min-height: 2.7rem;
        padding: .25rem max(.45rem, env(safe-area-inset-right)) .25rem max(.45rem, env(safe-area-inset-left));
    }

    body.competition-shell .judge-focus-title {
        display: block;
        font-size: .9rem;
    }

    body.competition-shell .judge-focus-title-long,
    body.competition-shell .judge-focus-progress-label,
    body.competition-shell .judge-view-criteria-btn--focus span {
        display: none;
    }

    body.competition-shell .judge-focus-title-short {
        display: inline;
    }

    body.competition-shell .judge-focus-progress {
        justify-self: end;
        font-size: .78rem;
    }

    body.competition-shell .judge-view-criteria-btn--focus,
    body.competition-shell .judge-focus-exit {
        width: 2.25rem;
        min-width: 2.25rem;
        height: 2.25rem;
        min-height: 2.25rem;
        padding: 0;
    }

    body.competition-shell .judge-marksheet-grid-view.is-score-keyboard-open .judge-focus-toolbar {
        display: none !important;
    }

    body.competition-shell .judge-marksheet-grid-view.is-score-keyboard-open .judge-marksheet-scroll {
        flex: 1 1 auto;
        height: var(--judge-visual-height, 100dvh);
        min-height: 0;
        scroll-padding-top: 2.35rem;
    }

    body.competition-shell .judge-marksheet-grid-view.is-score-keyboard-open .judge-marksheet-table th,
    body.competition-shell .judge-marksheet-grid-view.is-score-keyboard-open .judge-marksheet-table td {
        padding-top: .3rem;
        padding-bottom: .3rem;
    }

    body.competition-shell .judge-marksheet-grid-view.is-score-keyboard-open .judge-marksheet-table thead th {
        font-size: .72rem;
    }

    body.competition-shell .judge-marksheet-grid-view.is-score-keyboard-open .judge-marksheet-table thead th small {
        font-size: .6rem;
    }

    body.competition-shell .judge-grid-keyboard-active > td {
        box-shadow: inset 0 .12rem 0 rgba(37, 99, 235, .7), inset 0 -.12rem 0 rgba(37, 99, 235, .7);
    }

    body.competition-shell .judge-grid-keyboard-active .judge-grid-mark-input:focus {
        border-color: #2563eb;
        box-shadow: 0 0 0 .18rem rgba(37, 99, 235, .24);
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .judge-comment-modal-dialog {
        position: absolute;
        top: var(--judge-visual-top, 0);
        left: var(--judge-visual-left, 0);
        width: var(--judge-visual-width, 100vw);
        max-width: none;
        height: var(--judge-visual-height, 100dvh);
        min-height: 0;
        margin: 0;
        transform: none !important;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .judge-comment-modal-content {
        width: 100%;
        height: 100%;
        min-height: 0;
        border: 0;
        border-radius: 0;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .modal-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: .5rem;
        min-height: 2.75rem;
        padding: .3rem max(.55rem, env(safe-area-inset-right)) .3rem max(.55rem, env(safe-area-inset-left));
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .modal-title {
        min-width: 0;
        overflow: hidden;
        font-size: .9rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .judge-comment-landscape-actions {
        display: inline-flex;
        align-items: center;
        gap: .4rem;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .judge-comment-landscape-actions .btn {
        min-height: 2.15rem;
        padding: .3rem .7rem;
        font-size: .8rem;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .judge-comment-default-close,
    body.competition-shell .judge-comment-modal.is-landscape-phone .judge-comment-default-footer {
        display: none;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        padding: .35rem max(.55rem, env(safe-area-inset-right)) .4rem max(.55rem, env(safe-area-inset-left));
        overflow: hidden;
    }

    body.competition-shell .judge-comment-modal.is-landscape-phone #judgeCommentText {
        width: 100%;
        height: 100%;
        min-height: 2.75rem;
        padding: .45rem .6rem;
        resize: none;
    }
}

body.competition-shell .cm-page--judge-mark .judge-action-bar {
    grid-template-columns: minmax(11rem, 18rem) minmax(0, 1fr);
    align-items: center;
}

body.competition-shell .judge-autosave-state {
    min-height: 1.25rem;
    font-size: .85rem;
    font-weight: 800;
}

@media (max-width: 575.98px) and (orientation: portrait) {
    body.competition-shell .cm-page--judge-dashboard .judge-marksheet-grid-view {
        display: none !important;
    }

    body.competition-shell .cm-page--judge-dashboard .judge-mobile-list {
        display: grid !important;
    }

    body.competition-shell .cm-page--judge-mark .judge-action-bar {
        grid-template-columns: 1fr;
    }
}

body.competition-shell .judge-chest-accordion-card {
    padding: 0 !important;
    overflow: hidden;
}

body.competition-shell .judge-chest-compact-row {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    display: grid;
    grid-template-columns: minmax(4.75rem, auto) minmax(0, 1fr) minmax(3.6rem, auto) auto;
    align-items: center;
    gap: .55rem;
    width: 100%;
    min-height: 3.1rem;
    padding: .7rem .85rem;
    text-align: left;
}

body.competition-shell .judge-chest-compact-row:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 .16rem rgba(245, 158, 11, .28);
}

body.competition-shell .judge-chest-compact-number {
    color: var(--cm-heading-text, var(--cm-text));
    font-size: 1.05rem;
    font-weight: 950;
    letter-spacing: .01em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.competition-shell .judge-chest-compact-status {
    justify-self: start;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.competition-shell .judge-chest-compact-total {
    color: var(--cm-heading-text, var(--cm-text));
    font-size: 1rem;
    font-weight: 950;
    text-align: right;
    white-space: nowrap;
}

body.competition-shell .judge-chest-compact-chevron {
    color: var(--cm-muted-text, var(--cm-text-muted));
    flex: 0 0 auto;
    transition: transform .18s ease;
}

body.competition-shell .judge-chest-accordion-card.is-expanded .judge-chest-compact-chevron {
    transform: rotate(180deg);
}

body.competition-shell .judge-chest-expanded-panel {
    border-top: 1px solid var(--cm-stage-live-table-border-soft, var(--cm-surface-border, var(--cm-border)));
    display: none;
    padding: .8rem .85rem .9rem;
}

body.competition-shell .judge-chest-accordion-card.is-expanded .judge-chest-expanded-panel {
    display: block;
}

body.competition-shell .judge-chest-expanded-actions {
    margin-top: .8rem;
}

body.competition-shell .judge-chest-expanded-actions .judge-enter-mark-btn {
    width: 100%;
    justify-content: center;
    min-height: 2.75rem;
}

body.competition-shell .judge-chest-accordion-card.judge-current-performing .judge-chest-compact-row {
    background: var(--cm-stage-live-action-group-bg, var(--cm-control-bg, var(--cm-surface)));
}

@media (max-width: 1023.98px) {
    body.competition-shell .judge-chest-accordion-list {
        gap: .5rem;
    }

    body.competition-shell .judge-chest-compact-row {
        grid-template-columns: minmax(3.8rem, .7fr) minmax(0, 1fr) minmax(3.25rem, auto) auto;
        min-height: 2.85rem;
        padding: .62rem .72rem;
    }

    body.competition-shell .judge-chest-compact-number {
        font-size: 1rem;
    }

    body.competition-shell .judge-chest-compact-status {
        font-size: .72rem;
        padding-left: .5rem;
        padding-right: .5rem;
    }

    body.competition-shell .judge-chest-compact-total {
        font-size: .95rem;
    }

    body.competition-shell .judge-chest-expanded-panel .judge-card-meta-grid {
        gap: .55rem;
    }

    body.competition-shell .judge-chest-expanded-panel .judge-card-total-row {
        padding: .62rem .72rem;
    }
}

@media (max-width: 420px) {
    body.competition-shell .judge-chest-compact-row {
        grid-template-columns: minmax(3.25rem, .65fr) minmax(0, 1fr) minmax(2.8rem, auto) auto;
        gap: .4rem;
        padding-left: .62rem;
        padding-right: .62rem;
    }

    body.competition-shell .judge-chest-compact-status {
        font-size: .68rem;
    }

    body.competition-shell .judge-chest-compact-total {
        font-size: .88rem;
    }
}

/* Time Entry mobile/tablet scoped layout. These rules are isolated to timing pages. */
body.competition-shell .cm-page--timing-dashboard .cm-mobile-collapsible-context,
body.competition-shell .cm-page--timing-entry .cm-mobile-collapsible-context,
body.competition-shell .cm-page--timing-dashboard [data-finish-timing-footer],
body.competition-shell .cm-page--timing-entry .timing-entry-action-panel {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
}

body.competition-shell .timing-code-chest-list {
    display: grid;
    gap: .75rem;
}

body.competition-shell .timing-code-chest-card {
    margin-bottom: 0 !important;
    padding: .85rem !important;
}

body.competition-shell .timing-code-card-row {
    display: grid;
    grid-template-columns: minmax(3.75rem, auto) minmax(0, 1fr);
    align-items: center;
    gap: .75rem;
    width: 100%;
}

body.competition-shell .timing-code-chest-number {
    color: var(--cm-stage-live-heading, var(--cm-heading-text)) !important;
    font-weight: 900;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.competition-shell .timing-code-right-rail {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    justify-self: end;
    gap: .45rem;
    flex-wrap: wrap;
    min-width: 0;
    max-width: 100%;
    text-align: right;
}

body.competition-shell .timing-code-status-row {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: .35rem;
    flex: 0 1 auto;
    min-width: 0;
}

body.competition-shell .timing-code-status-row .timing-status-badge {
    max-width: 9.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.competition-shell .timing-code-action {
    flex: 0 0 auto;
    justify-content: center;
    min-width: 7.25rem;
}

body.competition-shell .timing-rule-card-list {
    display: grid;
    gap: 1rem;
}

body.competition-shell .timing-rule-card {
    border-top: 1px solid var(--cm-stage-live-table-border-soft, var(--cm-surface-border));
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
}

body.competition-shell .timing-rule-card:first-child {
    border-top: 0;
    padding-top: 0;
}

body.competition-shell .timing-rule-name {
    color: var(--cm-stage-live-heading, var(--cm-heading-text)) !important;
    font-weight: 900;
    font-size: 1.05rem;
    margin-bottom: .55rem;
}

body.competition-shell .timing-rule-meta {
    display: grid;
    gap: .25rem;
    color: var(--cm-stage-live-muted, var(--cm-muted-text)) !important;
}

body.competition-shell .timing-rule-meta strong {
    color: var(--cm-stage-live-heading, var(--cm-text)) !important;
    margin-left: .2rem;
}

body.competition-shell .timing-rule-entry {
    display: grid;
    gap: .45rem;
    justify-items: end;
}

body.competition-shell .timing-rule-entry-label {
    color: var(--cm-stage-live-heading, var(--cm-heading-text)) !important;
    font-size: .82rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .04em;
}

body.competition-shell .timing-rule-input-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
    flex-wrap: nowrap;
}

@media (max-width: 1023.98px) {
    body.competition-shell .cm-page--timing-dashboard .stage-context-main,
    body.competition-shell .cm-page--timing-entry .stage-context-main {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .5rem;
    }

    body.competition-shell .cm-page--timing-dashboard .stage-context-pill,
    body.competition-shell .cm-page--timing-entry .stage-context-pill {
        width: 100%;
        justify-content: space-between;
        min-width: 0;
    }

    body.competition-shell .cm-page--timing-dashboard .timing-dashboard-card .card-header {
        align-items: flex-start !important;
        padding: .9rem;
    }

    body.competition-shell .cm-page--timing-dashboard .timing-dashboard-card .card-header .btn {
        width: auto;
    }

    body.competition-shell .timing-code-chest-list {
        padding: .85rem;
    }

    body.competition-shell .timing-code-card-row {
        grid-template-columns: minmax(3.35rem, auto) minmax(0, 1fr);
        gap: .6rem;
    }

    body.competition-shell .timing-code-right-rail {
        gap: .4rem;
    }

    body.competition-shell .timing-code-status-row .timing-status-badge {
        max-width: 7.5rem;
        padding-left: .55rem;
        padding-right: .55rem;
        font-size: .76rem;
    }

    body.competition-shell .timing-code-action {
        min-width: 7.25rem;
        padding-left: .65rem;
        padding-right: .65rem;
    }

    body.competition-shell .timing-rule-card {
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: .85rem;
    }

    body.competition-shell .timing-rule-entry {
        justify-items: start;
    }

    body.competition-shell .timing-rule-input-row {
        justify-content: flex-start;
        width: 100%;
    }

    body.competition-shell .cm-page--timing-entry .timing-entry-action-panel .d-flex {
        justify-content: stretch !important;
    }

    body.competition-shell .cm-page--timing-entry .timing-action-btn {
        flex: 1 1 100%;
        min-width: 0;
    }
}

@media (max-width: 575.98px) {
    body.competition-shell .cm-page--timing-dashboard .stage-context-main,
    body.competition-shell .cm-page--timing-entry .stage-context-main {
        grid-template-columns: 1fr;
    }

    body.competition-shell .timing-code-chest-card {
        padding: .8rem !important;
    }

    body.competition-shell .timing-code-card-row {
        grid-template-columns: minmax(3.15rem, auto) minmax(0, 1fr);
        gap: .45rem;
    }

    body.competition-shell .timing-code-right-rail {
        align-content: flex-start;
        row-gap: .45rem;
    }

    body.competition-shell .timing-code-status-row {
        max-width: 100%;
    }

    body.competition-shell .timing-code-status-row .timing-status-badge {
        max-width: 6.9rem;
        font-size: .72rem;
    }

    body.competition-shell .timing-number-input {
        max-width: 5.6rem;
        min-height: 2.75rem;
    }
}


/* Timing dashboard: keep the change-code action inside the Program Code badge. */
body.competition-shell .cm-page--timing-dashboard .stage-context-pill-code.cm-inline-edit-badge {
    flex-wrap: nowrap;
}

body.competition-shell .cm-page--timing-dashboard .stage-context-pill-code .cm-inline-edit-action {
    margin-left: .15rem;
}
