/* =========================
   5/3/1 Calculator
   Full-mode mobile input fix
   ========================= */

/* Prevent nested grids/columns from forcing the calculator card wider than the viewport. */
#fiveThreeOneForm,
#fiveThreeOneForm .card-content,
.five-three-one-full-inputs,
.five-three-one-full-inputs .formula-accordion-content,
.five-three-one-full-results-card,
.five-three-one-full-results-card .card-content,
.five-three-one-lift-card,
.five-three-one-lift-card .table-container {
    min-width: 0;
    max-width: 100%;
}

/* Keep the existing simple row compact, but make it wrap safely on narrow screens. */
.five-three-one-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
    gap: 0.7rem;
    align-items: end;
    min-width: 0;
}

.five-three-one-row .one-rm-field,
.five-three-one-row .field,
.five-three-one-row .control,
.five-three-one-row .input,
.five-three-one-row .button,
.five-three-one-row .one-rm-unit-segment {
    min-width: 0;
    max-width: 100%;
}

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

/* Bulma columns use negative margins; inside the full lift accordion that can create mobile overflow. */
.five-three-one-full-inputs .columns,
.five-three-one-full-summary-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)) !important;
    gap: 0.75rem !important;
    margin: 0 !important;
    min-width: 0;
}

.five-three-one-full-inputs .column,
.five-three-one-full-summary-grid > .column {
    display: block !important;
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 0 !important;
    overflow: hidden;
}

.five-three-one-full-inputs .one-rm-field,
.five-three-one-full-inputs .input,
.five-three-one-full-summary-grid .box {
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.five-three-one-full-inputs .input {
    display: block;
    width: 100% !important;
}

.five-three-one-full-inputs summary,
.five-three-one-full-table-details summary,
.five-three-one-week-panel summary {
    min-width: 0;
}

.five-three-one-full-inputs summary .formula-subtitle,
.five-three-one-full-table-details summary .formula-subtitle,
.five-three-one-week-panel summary .formula-subtitle {
    min-width: 0;
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Results: keep phone cards readable and stop nested tables from stretching the card. */
.five-three-one-full-mobile {
    display: block;
    margin-top: 1rem;
}

.five-three-one-lift-card {
    overflow: hidden;
}

.five-three-one-week-lift-table {
    table-layout: fixed;
    font-size: 0.82rem;
}

.five-three-one-week-lift-table th,
.five-three-one-week-lift-table td {
    white-space: normal !important;
    word-break: normal;
}

.five-three-one-week-lift-table td[data-label="Weight"] strong {
    white-space: nowrap;
}

.five-three-one-full-table-details {
    margin-top: 1rem;
}

@media screen and (min-width: 900px) {
    .five-three-one-row {
        grid-template-columns: minmax(180px, 1fr) minmax(112px, 0.7fr) minmax(132px, 0.8fr);
    }

    .five-three-one-full-inputs .columns,
    .five-three-one-full-summary-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }
}

@media screen and (max-width: 620px) {
    .five-three-one-mode-tabs button {
        font-size: 0.82rem;
        line-height: 1.15;
        padding-left: 0.45rem;
        padding-right: 0.45rem;
        white-space: normal;
    }

    .five-three-one-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .five-three-one-full-inputs .columns,
    .five-three-one-full-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .five-three-one-full-inputs summary {
        align-items: flex-start;
    }

    .five-three-one-full-inputs summary .formula-subtitle,
    .five-three-one-week-panel summary .formula-subtitle {
        max-width: 8.8rem;
        font-size: 0.74rem;
        line-height: 1.12;
        white-space: normal;
        text-align: right;
    }
}

@media screen and (max-width: 520px) {
    .five-three-one-row,
    .five-three-one-full-inputs .columns,
    .five-three-one-full-summary-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .five-three-one-calc-explain {
        font-size: 0.8rem;
        line-height: 1.35;
    }

    .five-three-one-week-lift-table {
        font-size: 0.76rem;
    }
}


/* =========================
   5/3/1 full-mode mobile results fix
   ========================= */

/* The global responsive table CSS can clip values inside nested mobile cards.
   Use compact set cards for the week/lift output instead of a table. */
.five-three-one-set-list {
    display: grid;
    gap: 0.48rem;
    min-width: 0;
    max-width: 100%;
}

.five-three-one-set-row {
    display: grid;
    gap: 0.3rem;
    min-width: 0;
    max-width: 100%;
    padding: 0.58rem 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-panel);
}

.five-three-one-set-row.is-supplemental {
    background: linear-gradient(0deg, rgba(124, 58, 237, 0.08), rgba(124, 58, 237, 0.08)), var(--bg-panel);
}

body.dark .five-three-one-set-row.is-supplemental {
    background: linear-gradient(0deg, rgba(139, 92, 246, 0.14), rgba(139, 92, 246, 0.14)), var(--bg-panel);
}

.five-three-one-set-main,
.five-three-one-set-numbers {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.65rem;
    min-width: 0;
}

.five-three-one-set-type,
.five-three-one-set-percent,
.five-three-one-set-reps {
    min-width: 0;
    font-size: 0.76rem;
    font-weight: 900;
    line-height: 1.15;
    color: var(--text-muted) !important;
}

.five-three-one-set-type {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main) !important;
}

.five-three-one-set-reps {
    flex: 0 0 auto;
    text-align: right;
}

.five-three-one-set-weight {
    flex: 0 0 auto;
    font-size: 0.98rem;
    line-height: 1;
    color: var(--accent-strong) !important;
    white-space: nowrap;
}

body.dark .five-three-one-set-weight {
    color: var(--accent) !important;
}

@media screen and (min-width: 760px) {
    .five-three-one-set-row {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .five-three-one-set-main,
    .five-three-one-set-numbers {
        justify-content: flex-start;
    }

    .five-three-one-set-numbers {
        justify-content: flex-end;
    }
}

@media screen and (max-width: 420px) {
    .five-three-one-lift-card {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .five-three-one-set-row {
        padding: 0.52rem 0.55rem;
        border-radius: 12px;
    }

    .five-three-one-set-main,
    .five-three-one-set-numbers {
        gap: 0.45rem;
    }

    .five-three-one-set-type,
    .five-three-one-set-percent,
    .five-three-one-set-reps {
        font-size: 0.72rem;
    }

    .five-three-one-set-weight {
        font-size: 0.88rem;
    }
}

/* =========================
   5/3/1 full table mobile overflow fix
   ========================= */

/* Keep the optional full table as a real scrollable table on phones.
   The site-wide responsive table rules turn tables into stacked cards, which
   clips the right-hand values in this dense 9-column view. */
.five-three-one-full-table-details,
.five-three-one-full-table-details .formula-accordion-content,
.five-three-one-full-table-scroll {
    min-width: 0;
    max-width: 100%;
}

.five-three-one-full-table-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    background: var(--bg-card);
}

.five-three-one-full-program-table {
    min-width: 820px;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.76rem;
}

.five-three-one-full-program-table th,
.five-three-one-full-program-table td {
    padding: 0.42rem 0.48rem !important;
    white-space: nowrap;
    vertical-align: middle;
}

/* Reordered for quick programme scanning: Lift, Week, Set, Weight, Sets × Reps, Type, Phase, % TM, Notes. */
.five-three-one-full-program-table th:nth-child(1),
.five-three-one-full-program-table td:nth-child(1) {
    width: 5.8rem;
}

.five-three-one-full-program-table th:nth-child(2),
.five-three-one-full-program-table td:nth-child(2) {
    width: 5.5rem;
}

.five-three-one-full-program-table th:nth-child(3),
.five-three-one-full-program-table td:nth-child(3) {
    width: 3.4rem;
    text-align: center;
}

.five-three-one-full-program-table th:nth-child(4),
.five-three-one-full-program-table td:nth-child(4) {
    width: 5.8rem;
    text-align: right;
}

.five-three-one-full-program-table th:nth-child(5),
.five-three-one-full-program-table td:nth-child(5) {
    width: 5.8rem;
    text-align: center;
}

.five-three-one-full-program-table th:nth-child(6),
.five-three-one-full-program-table td:nth-child(6) {
    width: 7.2rem;
}

.five-three-one-full-program-table th:nth-child(7),
.five-three-one-full-program-table td:nth-child(7) {
    width: 6.7rem;
}

.five-three-one-full-program-table th:nth-child(8),
.five-three-one-full-program-table td:nth-child(8) {
    width: 4.4rem;
    text-align: center;
}

.five-three-one-full-program-table th:nth-child(9),
.five-three-one-full-program-table td:nth-child(9) {
    width: 12rem;
    white-space: normal;
    line-height: 1.25;
}

.five-three-one-full-program-table td[data-label="Weight"] strong {
    color: var(--accent-strong) !important;
    white-space: nowrap;
}

body.dark .five-three-one-full-program-table td[data-label="Weight"] strong {
    color: var(--accent) !important;
}

@media screen and (max-width: 768px) {
    .five-three-one-full-table-scroll {
        max-height: 70vh;
    }

    .five-three-one-full-program-table {
        min-width: 780px;
        font-size: 0.7rem;
    }

    .five-three-one-full-program-table,
    .five-three-one-full-program-table thead,
    .five-three-one-full-program-table tbody,
    .five-three-one-full-program-table tr,
    .five-three-one-full-program-table th,
    .five-three-one-full-program-table td {
        width: auto !important;
    }

    .five-three-one-full-program-table {
        display: table !important;
    }

    .five-three-one-full-program-table thead {
        display: table-header-group !important;
    }

    .five-three-one-full-program-table tbody {
        display: table-row-group !important;
    }

    .five-three-one-full-program-table tr {
        display: table-row !important;
        margin-bottom: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
    }

    .five-three-one-full-program-table th,
    .five-three-one-full-program-table td {
        display: table-cell !important;
        padding: 0.34rem 0.36rem !important;
        border-color: var(--border-color) !important;
    }

    .five-three-one-full-program-table td::before {
        content: none !important;
        display: none !important;
    }

    .five-three-one-full-program-table thead th {
        position: sticky;
        top: 0;
        z-index: 6;
        background: var(--bg-table-header) !important;
    }

    .five-three-one-full-program-table th:first-child,
    .five-three-one-full-program-table td:first-child {
        position: sticky;
        left: 0;
        z-index: 5;
        background: var(--bg-card) !important;
        box-shadow: 1px 0 0 rgba(17, 24, 39, 0.08);
    }

    .five-three-one-full-program-table thead th:first-child {
        z-index: 8;
        background: var(--bg-table-header) !important;
    }
}

@media screen and (max-width: 420px) {
    .five-three-one-full-program-table {
        min-width: 760px;
        font-size: 0.66rem;
    }

    .five-three-one-full-program-table th,
    .five-three-one-full-program-table td {
        padding: 0.3rem 0.3rem !important;
    }
}

/* =========================
   5/3/1 extended result actions
   ========================= */

.five-three-one-actions {
    position: relative;
    align-items: center;
}

.five-three-one-more-actions {
    position: relative;
    flex: 0 0 auto;
}

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

.five-three-one-more-actions > summary::-webkit-details-marker {
    display: none;
}

.five-three-one-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);
}

.five-three-one-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;
}

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

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

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

@media screen and (max-width: 520px) {
    .five-three-one-actions {
        gap: 0.35rem;
    }

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

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

/* =========================
   5/3/1 primary input panel
   ========================= */

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

#fiveThreeOneForm .five-three-one-primary-settings-row {
    margin: 0;
}

@media screen and (max-width: 520px) {
    form#fiveThreeOneForm .five-three-one-row.five-three-one-primary-settings-row {
        display: grid !important;
        grid-template-columns: 112px 95px !important;
        justify-content: center !important;
        justify-items: stretch !important;
        align-items: end !important;
        gap: 0.7rem !important;
        width: 100% !important;
    }

    form#fiveThreeOneForm .five-three-one-primary-settings-row .one-rm-weight-cell {
        grid-column: 1 / -1;
    }

    form#fiveThreeOneForm .five-three-one-primary-settings-row > .one-rm-field {
        width: auto !important;
        justify-self: stretch !important;
    }

    form#fiveThreeOneForm .five-three-one-primary-settings-row .one-rm-unit-segment,
    form#fiveThreeOneForm .five-three-one-primary-settings-row .field.has-addons {
        width: 100% !important;
    }

    form#fiveThreeOneForm .five-three-one-primary-settings-row .label {
        text-align: left !important;
    }
}

/* =========================
   5/3/1 full table controls
   ========================= */

.five-three-one-table-controls {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) auto minmax(150px, 0.8fr) minmax(150px, 0.8fr) auto;
    gap: 0.65rem;
    align-items: end;
    margin-bottom: 0.85rem;
    padding: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--bg-panel);
}

.five-three-one-table-control {
    min-width: 0;
}

.five-three-one-table-control .label {
    margin-bottom: 0.3rem;
    font-size: 0.78rem;
}

.five-three-one-table-controls .select,
.five-three-one-table-controls .select select {
    width: 100%;
}

.five-three-one-direction-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 108px;
    height: 2.45rem;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-card);
}

.five-three-one-direction-btn {
    border: 0;
    background: transparent;
    color: var(--text-main) !important;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 900;
    cursor: pointer;
}

.five-three-one-direction-btn:hover,
.five-three-one-direction-btn:focus-visible {
    background: var(--accent-pale);
    outline: none;
}

.five-three-one-direction-btn.is-active {
    background: var(--brand-gradient);
    color: #ffffff !important;
}

.five-three-one-clear-highlight {
    height: 2.45rem;
    font-size: 0.82rem;
    font-weight: 900;
}

.five-three-one-full-program-table tbody tr.is-highlight-dimmed {
    opacity: 0.38;
}

.five-three-one-full-program-table tbody tr.is-highlight-match > td,
.five-three-one-full-program-table tbody tr.is-highlight-match > td:nth-child(odd),
.five-three-one-full-program-table tbody tr.is-highlight-match > td:nth-child(even) {
    background: var(--accent-pale) !important;
}

.five-three-one-full-program-table tbody tr.is-highlight-match > td:first-child {
    background: var(--accent-soft) !important;
}

@media screen and (max-width: 820px) {
    .five-three-one-table-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .five-three-one-clear-highlight {
        width: 100%;
    }
}

@media screen and (max-width: 480px) {
    .five-three-one-table-controls {
        grid-template-columns: 1fr;
        gap: 0.55rem;
    }

    .five-three-one-direction-toggle,
    .five-three-one-clear-highlight {
        width: 100%;
    }
}


/* =========================
   5/3/1 full table controls layout correction
   Prevents select/toggle overlap and keeps controls inside the panel.
   ========================= */

.five-three-one-full-table-details .formula-accordion-content {
    min-width: 0;
    overflow: hidden;
}

.five-three-one-table-controls,
.five-three-one-table-controls * {
    box-sizing: border-box;
}

.five-three-one-table-controls {
    display: grid !important;
    grid-template-columns:
        minmax(0, 1.25fr)
        minmax(0, 0.75fr)
        minmax(0, 1fr)
        minmax(0, 1.1fr) !important;
    gap: 0.75rem !important;
    align-items: end !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.five-three-one-table-control {
    display: grid;
    grid-template-rows: auto auto;
    gap: 0.32rem;
    min-width: 0;
    max-width: 100%;
}

.five-three-one-table-control .label,
.five-three-one-table-control > .label {
    display: block;
    margin: 0 !important;
    min-width: 0;
    min-height: 0.95rem;
    font-size: 0.76rem;
    line-height: 1.15;
    white-space: nowrap;
}

.five-three-one-table-controls .select {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 2.85rem !important;
}

.five-three-one-table-controls .select select {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 2.85rem !important;
    line-height: 1.15 !important;
    padding-left: 0.75rem !important;
    padding-right: 2.35rem !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

.five-three-one-direction-toggle {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 2.85rem !important;
}

.five-three-one-direction-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    height: 100%;
    padding: 0 0.5rem;
    line-height: 1;
    white-space: nowrap;
}

.five-three-one-clear-highlight {
    grid-column: 4 / 5;
    justify-self: stretch;
    align-self: end;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 2.85rem !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    line-height: 1 !important;
}

@media screen and (min-width: 1180px) {
    .five-three-one-table-controls {
        grid-template-columns:
            minmax(180px, 1.2fr)
            minmax(116px, 0.62fr)
            minmax(160px, 0.95fr)
            minmax(170px, 1fr)
            minmax(72px, 0.35fr) !important;
    }

    .five-three-one-clear-highlight {
        grid-column: auto;
    }
}

@media screen and (max-width: 900px) {
    .five-three-one-table-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .five-three-one-clear-highlight {
        grid-column: 2 / 3;
    }
}

@media screen and (max-width: 540px) {
    .five-three-one-table-controls {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 0.7rem !important;
        padding: 0.75rem !important;
        border-radius: 16px;
    }

    .five-three-one-clear-highlight {
        grid-column: 1 / -1;
    }

    .five-three-one-table-controls .select,
    .five-three-one-table-controls .select select,
    .five-three-one-direction-toggle,
    .five-three-one-clear-highlight {
        height: 2.75rem !important;
    }
}

/* =========================
   5/3/1 bottom share/export actions
   ========================= */

.five-three-one-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);
}

.five-three-one-bottom-actions-card .title {
    margin-bottom: 0.2rem !important;
}

.five-three-one-bottom-actions-card .help {
    margin-top: 0;
}

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

.five-three-one-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;
}

.five-three-one-bottom-actions .button i {
    margin-right: 0.35rem;
}

@media screen and (max-width: 760px) {
    .five-three-one-bottom-actions-card {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }

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

    .five-three-one-bottom-actions .button {
        width: 100%;
    }
}

@media screen and (max-width: 420px) {
    .five-three-one-bottom-actions {
        grid-template-columns: 1fr;
    }
}


/* =========================
   5/3/1 main-work option polish
   ========================= */

.five-three-one-main-work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media screen and (max-width: 768px) {
    .five-three-one-main-work-grid {
        grid-template-columns: 1fr;
    }
}


/* =========================
   5/3/1 week order options
   ========================= */

.five-three-one-week-order-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media screen and (max-width: 768px) {
    .five-three-one-week-order-grid {
        grid-template-columns: 1fr;
    }
}
