/* =========================
   Linear Progression Calculator
   Share/export polish + mobile-first programme view
   ========================= */

#linearProgressionForm,
#linearProgressionForm .card-content,
#mainLinearProgressionPanel,
#lightLinearProgressionPanel,
.linear-program-table-details,
.linear-program-table-details .formula-accordion-content,
.linear-program-scroll,
.linear-progression-week-cards,
.linear-progression-week-card {
    min-width: 0;
    max-width: 100%;
}

/* Match the 5/3/1 action menu pattern without leaking styles globally. */
.linear-progression-actions {
    position: relative;
    align-items: center;
}

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

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

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

.linear-progression-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);
}

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

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

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

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

/* Top summary cards give the page a shareable, screenshot-friendly result area. */
.linear-progression-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0.25rem 0 1rem;
}

.linear-progression-summary-card {
    min-width: 0;
    padding: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: linear-gradient(180deg, var(--bg-card), var(--bg-panel));
}

.linear-progression-summary-card.is-anchor {
    background: linear-gradient(0deg, rgba(124, 58, 237, 0.1), rgba(124, 58, 237, 0.1)), var(--bg-card);
}

body.dark .linear-progression-summary-card.is-anchor {
    background: linear-gradient(0deg, rgba(139, 92, 246, 0.16), rgba(139, 92, 246, 0.16)), var(--bg-card);
}

.linear-progression-summary-label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text-muted) !important;
    font-size: 0.68rem;
    font-weight: 950;
    line-height: 1.15;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.linear-progression-summary-card strong {
    display: block;
    color: var(--accent-strong) !important;
    font-size: clamp(1.15rem, 3vw, 1.65rem);
    font-weight: 950;
    line-height: 1;
    letter-spacing: -0.03em;
}

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

.linear-progression-summary-card span:last-child {
    display: block;
    margin-top: 0.42rem;
    color: var(--text-muted) !important;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.2;
}

/* Phone-first programme cards. Desktop keeps the dense table as the primary view. */
.linear-progression-week-cards {
    display: none;
    gap: 0.65rem;
    margin-top: 0.8rem;
}

.linear-progression-week-card {
    padding: 0.72rem;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--bg-card);
    box-shadow: var(--shadow-soft);
}

.linear-progression-week-card.is-anchor {
    border-color: rgba(124, 58, 237, 0.32);
    background: linear-gradient(0deg, rgba(124, 58, 237, 0.08), rgba(124, 58, 237, 0.08)), var(--bg-card);
}

.linear-progression-week-card.is-light-session {
    background: linear-gradient(0deg, rgba(79, 70, 229, 0.07), rgba(79, 70, 229, 0.07)), var(--bg-card);
}

body.dark .linear-progression-week-card.is-anchor,
body.dark .linear-progression-week-card.is-light-session {
    background: linear-gradient(0deg, rgba(139, 92, 246, 0.13), rgba(139, 92, 246, 0.13)), var(--bg-card);
}

.linear-progression-week-card-top,
.linear-progression-week-meta,
.linear-progression-week-footer {
    min-width: 0;
}

.linear-progression-week-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.linear-progression-week-card-top strong {
    display: block;
    min-width: 0;
    margin-top: 0.1rem;
    overflow: hidden;
    color: var(--text-main) !important;
    font-size: 0.88rem;
    font-weight: 950;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.linear-progression-week-label {
    display: block;
    color: var(--text-muted) !important;
    font-size: 0.68rem;
    font-weight: 950;
    line-height: 1;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.linear-progression-week-weight {
    flex: 0 0 auto;
    color: var(--accent-strong) !important;
    font-size: 1.2rem;
    font-weight: 950;
    line-height: 1;
    white-space: nowrap;
}

body.dark .linear-progression-week-weight {
    color: var(--accent) !important;
}

.linear-progression-week-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    margin-top: 0.62rem;
}

.linear-progression-week-meta span {
    min-width: 0;
    padding: 0.42rem 0.45rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-panel);
    color: var(--text-main) !important;
    font-size: 0.72rem;
    font-weight: 850;
    line-height: 1.15;
    text-align: center;
}

.linear-progression-week-footer {
    display: grid;
    gap: 0.4rem;
    margin-top: 0.62rem;
}

.linear-progression-week-footer > span {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    padding: 0.28rem 0.48rem;
    border-radius: 999px;
    background: var(--accent-pale);
    color: var(--accent-strong) !important;
    font-size: 0.7rem;
    font-weight: 950;
    line-height: 1.1;
}

body.dark .linear-progression-week-footer > span {
    color: var(--accent) !important;
}

.linear-progression-week-footer p {
    margin: 0;
    color: var(--text-muted) !important;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.28;
}

/* Table stays useful for exports / desktop review, and scrolls as a real table on small screens. */
.linear-program-table-details {
    margin-top: 0.9rem;
}

.linear-program-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    background: var(--bg-card);
}

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

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

/* Bottom share/export CTA mirrors 5/3/1 so users see actions after reviewing results. */
.linear-progression-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);
}

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

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

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

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

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

@media screen and (min-width: 769px) {
    .linear-program-table-details {
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .linear-program-table-details > summary {
        display: none;
    }

    .linear-program-table-details .formula-accordion-content {
        padding: 0;
        border-top: 0;
    }
}

@media screen and (max-width: 768px) {
    .linear-progression-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.55rem;
    }

    .linear-progression-summary-card {
        padding: 0.75rem;
        border-radius: 16px;
    }

    .linear-progression-week-cards {
        display: grid;
    }

    .linear-program-table-details {
        margin-top: 0.8rem;
    }

    .linear-program-table-details summary {
        align-items: flex-start;
    }

    .linear-program-table-details summary .formula-subtitle {
        max-width: 8.6rem;
        font-size: 0.74rem;
        line-height: 1.12;
        text-align: right;
        white-space: normal;
    }

    .linear-program-scroll {
        max-height: 70vh;
    }

    .linear-program-table {
        min-width: 760px;
        table-layout: fixed;
        font-size: 0.72rem;
    }

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

    .linear-program-table {
        display: table !important;
    }

    .linear-program-table thead {
        display: table-header-group !important;
    }

    .linear-program-table tbody {
        display: table-row-group !important;
    }

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

    .linear-program-table th,
    .linear-program-table td {
        display: table-cell !important;
        padding: 0.36rem 0.38rem !important;
        border-color: var(--border-color) !important;
        background: var(--bg-table-row) !important;
        text-align: left !important;
        white-space: nowrap !important;
    }

    .linear-program-table td::before {
        content: none !important;
        display: none !important;
    }

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

    .linear-program-table th:nth-child(1),
    .linear-program-table td:nth-child(1) {
        width: 4.8rem;
    }

    .linear-program-table th:nth-child(2),
    .linear-program-table td:nth-child(2) {
        width: 7rem;
    }

    .linear-program-table th:nth-child(3),
    .linear-program-table td:nth-child(3) {
        width: 5.8rem;
        text-align: right !important;
    }

    .linear-program-table th:nth-child(4),
    .linear-program-table td:nth-child(4),
    .linear-program-table th:nth-child(5),
    .linear-program-table td:nth-child(5),
    .linear-program-table th:nth-child(6),
    .linear-program-table td:nth-child(6),
    .linear-program-table th:nth-child(7),
    .linear-program-table td:nth-child(7) {
        width: 5.4rem;
        text-align: center !important;
    }

    .linear-program-table th:nth-child(8),
    .linear-program-table td:nth-child(8) {
        width: 12rem;
        white-space: normal !important;
        line-height: 1.25;
    }

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

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

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

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

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

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

    .linear-progression-summary-grid {
        grid-template-columns: 1fr;
    }

    .linear-progression-week-meta {
        grid-template-columns: 1fr;
    }
}

@media screen and (max-width: 420px) {
    .linear-progression-week-card {
        padding: 0.62rem;
        border-radius: 16px;
    }

    .linear-progression-week-weight {
        font-size: 1.06rem;
    }

    .linear-progression-bottom-actions {
        grid-template-columns: 1fr;
    }
}
