/* =========================
   DUP Calculator
   Consistent result actions, dense table focus and mobile sticky columns
   ========================= */

#dupForm,
#dupForm .card-content,
.dup-results-card,
.dup-results-card .card-content,
.dup-program-scroll,
.dup-table-focus,
.dup-table-controls {
    min-width: 0;
    max-width: 100%;
}

/* Calculator inputs */

#dupForm .dup-primary-inputs {
    margin-top: 0.9rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--bg-panel);
}

.dup-primary-row {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(112px, 0.65fr);
    gap: 0.75rem;
    align-items: end;
}

.dup-primary-row .one-rm-field,
.dup-primary-row .input,
.dup-primary-row .one-rm-unit-segment {
    min-width: 0;
    max-width: 100%;
}

.dup-primary-row .input,
.dup-primary-row .one-rm-unit-segment {
    width: 100%;
}

.dup-calc-explain {
    max-width: 780px;
}

.dup-submit {
    width: 100%;
}

/* Result header and actions */

.dup-results-header {
    align-items: flex-start;
}

.dup-actions {
    position: relative;
    align-items: center;
}

.dup-more-actions {
    position: relative;
    flex: 0 0 auto;
}

.dup-more-actions > summary {
    list-style: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.dup-more-actions > summary::-webkit-details-marker {
    display: none;
}

.dup-more-menu {
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    z-index: 40;
    min-width: 12rem;
    padding: 0.35rem;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-card);
    box-shadow: var(--shadow-soft);
}

.dup-more-menu button {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    min-width: 0;
    padding: 0.58rem 0.65rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-main) !important;
    font: inherit;
    font-size: 0.84rem;
    font-weight: 850;
    line-height: 1.15;
    text-align: left;
    cursor: pointer;
}

.dup-more-menu button:hover,
.dup-more-menu button:focus-visible {
    background: var(--bg-panel);
    outline: none;
}

.dup-more-menu i {
    width: 1rem;
    color: var(--accent-strong) !important;
    text-align: center;
}

body.dark .dup-more-menu i {
    color: var(--accent) !important;
}

.dup-result-hero {
    margin-top: 0.4rem;
}

/* Programme summary */

.dup-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.dup-summary-card {
    min-width: 0;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-panel);
}

.dup-summary-card span,
.dup-summary-card strong {
    display: block;
    min-width: 0;
}

.dup-summary-card span {
    color: var(--text-muted) !important;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.dup-summary-card strong {
    margin-top: 0.25rem;
    overflow-wrap: anywhere;
    color: var(--accent-strong) !important;
    font-size: 0.94rem;
}

body.dark .dup-summary-card strong {
    color: var(--accent) !important;
}

/* Table focus controls */

.dup-table-focus {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.1fr);
    gap: 0.9rem;
    align-items: end;
    margin: 1rem 0 0.85rem;
    padding: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--bg-panel);
}

.dup-table-focus-copy .settings-summary-left {
    margin-bottom: 0.2rem;
}

.dup-table-focus-copy .help {
    margin: 0;
}

.dup-table-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
    gap: 0.65rem;
    align-items: end;
}

.dup-table-control {
    min-width: 0;
}

.dup-table-control .label {
    margin-bottom: 0.3rem;
    font-size: 0.76rem;
}

.dup-table-control .select,
.dup-table-control .select select {
    width: 100%;
    min-width: 0;
}

.dup-clear-highlight {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    height: 2.7rem;
    font-size: 0.82rem;
    font-weight: 900;
}

/* Dense table: preserve the strong existing table while adding focus tools. */

.dup-program-scroll {
    position: relative;
    overflow: auto;
    max-height: 76vh;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--bg-card);
}

.dup-results-card .dup-program-table {
    --dup-week-col: 5.4rem;
    --dup-day-col: 9.2rem;
    min-width: 960px;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.74rem;
}

.dup-results-card .dup-program-table th,
.dup-results-card .dup-program-table td {
    padding: 0.48rem 0.5rem !important;
    white-space: nowrap;
    vertical-align: middle;
    border-color: var(--border-color) !important;
    transition: background-color 0.16s ease, opacity 0.16s ease;
}

.dup-results-card .dup-program-table thead th {
    position: sticky;
    top: 0;
    z-index: 12;
    background: var(--bg-table-header) !important;
}

.dup-results-card .dup-program-table th:nth-child(1),
.dup-results-card .dup-program-table td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 9;
    width: var(--dup-week-col);
    min-width: var(--dup-week-col);
    max-width: var(--dup-week-col);
    background: linear-gradient(0deg, var(--accent-pale), var(--accent-pale)), var(--bg-card) !important;
    font-weight: 900;
    box-shadow: inset -1px 0 0 var(--border-color);
}

.dup-results-card .dup-program-table th:nth-child(2),
.dup-results-card .dup-program-table td:nth-child(2) {
    position: sticky;
    left: var(--dup-week-col);
    z-index: 8;
    width: var(--dup-day-col);
    min-width: var(--dup-day-col);
    max-width: var(--dup-day-col);
    background: var(--bg-card) !important;
    box-shadow: inset -1px 0 0 var(--border-color), 3px 0 8px rgba(17, 24, 39, 0.04);
}

.dup-results-card .dup-program-table thead th:nth-child(1),
.dup-results-card .dup-program-table thead th:nth-child(2) {
    z-index: 16;
    background: var(--bg-table-header) !important;
}

.dup-results-card .dup-program-table th:nth-child(3),
.dup-results-card .dup-program-table td:nth-child(3) {
    width: 5rem;
    text-align: center;
}

.dup-results-card .dup-program-table th:nth-child(4),
.dup-results-card .dup-program-table td:nth-child(4) {
    width: 6.2rem;
    text-align: right;
}

.dup-results-card .dup-program-table th:nth-child(5),
.dup-results-card .dup-program-table td:nth-child(5) {
    width: 7rem;
    text-align: center;
}

.dup-results-card .dup-program-table th:nth-child(6),
.dup-results-card .dup-program-table td:nth-child(6) {
    width: 6.2rem;
    text-align: center;
}

.dup-results-card .dup-program-table th:nth-child(7),
.dup-results-card .dup-program-table td:nth-child(7) {
    width: 7rem;
    text-align: right;
}

.dup-results-card .dup-program-table th:nth-child(8),
.dup-results-card .dup-program-table td:nth-child(8) {
    width: 22rem;
    white-space: normal;
    line-height: 1.32;
}

.dup-results-card .dup-program-table td[data-label="Weight"] strong {
    color: var(--accent-strong) !important;
    white-space: nowrap;
}

body.dark .dup-results-card .dup-program-table td[data-label="Weight"] strong {
    color: var(--accent) !important;
}

.dup-program-table tbody tr {
    cursor: pointer;
}

.dup-program-table tbody tr:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
}

.dup-program-table tbody tr.is-highlight-dimmed {
    opacity: 0.3;
}

.dup-program-table tbody tr.is-highlight-match {
    opacity: 1;
}

.dup-program-table tbody tr.is-highlight-match > td,
.dup-program-table tbody tr.is-highlight-match > td:nth-child(odd),
.dup-program-table tbody tr.is-highlight-match > td:nth-child(even) {
    background: linear-gradient(0deg, var(--accent-pale), var(--accent-pale)), var(--bg-card) !important;
}

.dup-program-table tbody tr.is-highlight-match > td:first-child {
    background: linear-gradient(0deg, var(--accent-soft), var(--accent-soft)), var(--bg-card) !important;
}

.dup-program-table tbody tr.is-highlight-match > td:nth-child(2) {
    background: linear-gradient(0deg, var(--accent-pale), var(--accent-pale)), var(--bg-card) !important;
}

.dup-program-table tbody tr[aria-selected="true"] {
    box-shadow: inset 0 0 0 2px var(--accent);
}

/* Bottom save/share panel */

.dup-bottom-actions-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: center;
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--bg-panel);
}

.dup-bottom-actions-card .title {
    margin-bottom: 0.2rem !important;
}

.dup-bottom-actions-card .help {
    margin-top: 0;
}

.dup-bottom-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55rem;
}

.dup-bottom-actions .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.55rem;
    font-size: 0.86rem;
    font-weight: 900;
    white-space: nowrap;
}

.dup-bottom-actions .button i {
    margin-right: 0.35rem;
}

@media screen and (max-width: 900px) {
    .dup-table-focus {
        grid-template-columns: 1fr;
    }
}

@media screen and (max-width: 768px) {
    .dup-lift-tabs ul {
        display: flex;
        flex-direction: row;
    }

    .dup-lift-tabs li {
        width: auto;
        flex: 1 1 0;
    }

    .dup-lift-tabs button {
        padding-left: 0.45rem;
        padding-right: 0.45rem;
        font-size: 0.84rem;
        line-height: 1.15;
        white-space: normal;
    }

    .dup-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dup-bottom-actions-card {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }

    .dup-bottom-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: stretch;
    }

    .dup-bottom-actions .button {
        width: 100%;
    }

    .dup-program-scroll {
        max-height: 72vh;
    }

    .dup-results-card .dup-program-table,
    .dup-results-card .dup-program-table thead,
    .dup-results-card .dup-program-table tbody,
    .dup-results-card .dup-program-table tr,
    .dup-results-card .dup-program-table th,
    .dup-results-card .dup-program-table td {
        width: auto !important;
    }

    .dup-results-card .dup-program-table {
        display: table !important;
        min-width: 900px;
        font-size: 0.68rem;
    }

    .dup-results-card .dup-program-table thead {
        display: table-header-group !important;
    }

    .dup-results-card .dup-program-table tbody {
        display: table-row-group !important;
    }

    .dup-results-card .dup-program-table tr {
        display: table-row !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none;
    }

    .dup-results-card .dup-program-table th,
    .dup-results-card .dup-program-table td {
        display: table-cell !important;
        padding: 0.36rem 0.38rem !important;
        border-color: var(--border-color) !important;
    }

    .dup-results-card .dup-program-table td::before {
        content: none !important;
        display: none !important;
    }

    .dup-results-card .dup-program-table th:nth-child(1),
    .dup-results-card .dup-program-table td:nth-child(1) {
        width: var(--dup-week-col) !important;
        min-width: var(--dup-week-col) !important;
        max-width: var(--dup-week-col) !important;
    }

    .dup-results-card .dup-program-table th:nth-child(2),
    .dup-results-card .dup-program-table td:nth-child(2) {
        width: var(--dup-day-col) !important;
        min-width: var(--dup-day-col) !important;
        max-width: var(--dup-day-col) !important;
    }
}

@media screen and (max-width: 620px) {
    .dup-primary-row {
        grid-template-columns: minmax(0, 1fr);
    }

    .dup-actions {
        gap: 0.35rem;
    }

    .dup-actions .share-result-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .dup-more-menu {
        right: -0.15rem;
        min-width: min(12rem, calc(100vw - 2rem));
    }

    .dup-table-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dup-clear-highlight {
        grid-column: 1 / -1;
        width: 100%;
    }
}

@media screen and (max-width: 440px) {
    .dup-summary-grid,
    .dup-bottom-actions,
    .dup-table-controls {
        grid-template-columns: 1fr;
    }

    .dup-clear-highlight {
        grid-column: auto;
    }

    .dup-results-card .dup-program-table {
        --dup-week-col: 4.7rem;
        --dup-day-col: 8rem;
        min-width: 850px;
        font-size: 0.64rem;
    }
}
