/* ── Olympic Tracker — PicoCSS overrides + mobile-first ─── */

/* ── Safe-area padding for notched phones ───────────────── */
body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ── Week cards ─────────────────────────────────────────── */
.week-card {
    margin-bottom: 0.75rem;
}

.week-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.metrics-badge {
    font-size: 0.8rem;
    opacity: 0.75;
}

.metrics-bar {
    background: var(--pico-card-background-color, #f8f9fa);
    padding: 0.5rem 0.75rem;
    border-radius: var(--pico-border-radius);
    margin-bottom: 1rem;
}

/* ── Day cards ──────────────────────────────────────────── */
.day-card {
    margin-bottom: 1.5rem;
}

.day-card.archived {
    opacity: 0.6;
}

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
}

.archived-badge {
    background: var(--pico-ins-color, #2a9d8f);
}

/* ── Inline edit forms ──────────────────────────────────── */
.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
}

.inline-form input {
    margin: 0;
    padding: 0.25rem 0.35rem;
    min-height: 2.4rem;           /* touch-friendly */
}

.input-tiny {
    width: 3.2rem !important;
    text-align: center;
}

.input-small {
    width: 4.5rem !important;
    text-align: right;
}

/* ── Set checkboxes — larger tap targets ────────────────── */
.sets-cell {
    display: flex;
    gap: 0.15rem;
    flex-wrap: wrap;
    align-items: center;
}

.sets-cell input[type="checkbox"] {
    margin: 0;
    width: 1.5rem;
    height: 1.5rem;
    min-height: unset;
}

/* ── Small buttons ──────────────────────────────────────── */
.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    margin: 0;
    min-height: 2rem;
}

.btn-small.danger {
    --pico-color: var(--pico-del-color, #e63946);
    border-color: var(--pico-del-color, #e63946);
}

/* ── Archived rows ──────────────────────────────────────── */
.archived-row {
    opacity: 0.7;
}

/* ── Accessory form ─────────────────────────────────────── */
.accessory-form {
    margin-top: 0.5rem;
}

.accessory-add-form .grid {
    margin-bottom: 0.5rem;
}

/* ── Table tweaks ───────────────────────────────────────── */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.5rem;
}

table {
    font-size: 0.88rem;
    white-space: nowrap;
}

th, td {
    padding: 0.4rem 0.5rem;
    vertical-align: middle;
}

/* ── Ratio analysis ─────────────────────────────────────── */
.ratio-analysis {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--pico-muted-border-color, #dee2e6);
}

.ratio-row.ratio-weak {
    border-left: 3px solid var(--pico-del-color, #e63946);
}

.ratio-row.ratio-balanced {
    border-left: 3px solid var(--pico-ins-color, #2a9d8f);
}

.ratio-row.ratio-strong {
    border-left: 3px solid #e9c46a;
}

.ratio-row.ratio-unknown {
    border-left: 3px solid var(--pico-muted-color, #999);
}

.verdict {
    font-weight: 600;
    white-space: nowrap;
}

.verdict-weak {
    color: var(--pico-del-color, #e63946);
}

.verdict-balanced {
    color: var(--pico-ins-color, #2a9d8f);
}

.verdict-strong {
    color: #e9c46a;
}

.ratio-note {
    opacity: 0.7;
}

/* ════════════════════════════════════════════════════════════
   MOBILE-FIRST  (≤ 640px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* ── Container ─────────────────────────────────────────── */
    .container {
        padding-left: 0.6rem;
        padding-right: 0.6rem;
    }

    /* ── Nav ───────────────────────────────────────────────── */
    nav ul li a {
        padding: 0.4rem 0.3rem;
        font-size: 0.85rem;
    }

    /* ── Week header ───────────────────────────────────────── */
    .week-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
    }

    .metrics-badge {
        font-size: 0.7rem;
        line-height: 1.5;
    }

    /* ── Day header ────────────────────────────────────────── */
    .day-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .day-header .badge,
    .day-header button,
    .day-header form {
        align-self: stretch;
        text-align: center;
    }

    /* ── Metrics bar ───────────────────────────────────────── */
    .metrics-bar small {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem 1rem;
        line-height: 1.8;
    }

    /* ── Exercise table → card layout ─────────────────────── */
    .exercise-table thead {
        display: none;
    }

    .table-responsive {
        overflow-x: visible;
    }

    .exercise-table,
    .exercise-table tbody,
    .exercise-table tr {
        display: block;
        width: 100%;
    }

    .exercise-table tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "name    name"
            "setsreps weight"
            "logs    logs"
            "actions actions";
        border: 1px solid var(--pico-muted-border-color, #ddd);
        border-radius: var(--pico-border-radius, 4px);
        margin-bottom: 0.5rem;
        padding: 0.5rem 0.6rem;
        gap: 0.25rem 0.5rem;
        background: var(--pico-card-background-color);
    }

    .exercise-table td {
        border: none;
        padding: 0.1rem 0;
        vertical-align: middle;
        white-space: normal;
    }

    .exercise-table td[data-col="name"] {
        grid-area: name;
        font-weight: 600;
        font-size: 0.95rem;
        padding-bottom: 0.3rem;
        border-bottom: 1px solid var(--pico-muted-border-color, #eee);
        margin-bottom: 0.1rem;
    }

    .exercise-table td[data-col="setsreps"] {
        grid-area: setsreps;
        display: flex;
        align-items: center;
    }

    .exercise-table td[data-col="pct"] {
        display: none !important;
    }

    .exercise-table td[data-col="weight"] {
        grid-area: weight;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    .exercise-table td[data-col="logs"] {
        grid-area: logs;
    }

    .exercise-table td[data-col="actions"] {
        grid-area: actions;
        text-align: right;
    }

    /* ── Input sizing on mobile ────────────────────────────── */
    table {
        font-size: 0.85rem;
        white-space: normal;
    }

    .input-tiny {
        width: 2.8rem !important;
        font-size: 0.82rem;
    }

    .input-small {
        width: 4rem !important;
        font-size: 0.82rem;
    }

    /* ── Accessory add form ─────────────────────────────────── */
    .accessory-add-form .grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .accessory-add-form .grid > label:first-child {
        grid-column: 1 / -1;
    }

    /* ── Ratio analysis → stacked cards ────────────────────── */
    .ratio-table thead {
        display: none;
    }

    .ratio-table,
    .ratio-table tbody {
        display: block;
        width: 100%;
    }

    .ratio-table tr {
        display: block;
        margin-bottom: 0.75rem;
        border-radius: var(--pico-border-radius, 4px);
        overflow: hidden;
    }

    .ratio-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.35rem 0.6rem;
        border-bottom: 1px solid var(--pico-muted-border-color, #eee);
        white-space: normal;
        gap: 0.5rem;
    }

    .ratio-table td:last-child {
        border-bottom: none;
    }

    .ratio-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.8rem;
        opacity: 0.65;
        flex-shrink: 0;
        min-width: 3.5rem;
    }

    .ratio-table td[data-label="Ratio"] {
        background: var(--pico-secondary-background, #f4f4f4);
        font-weight: 600;
        font-size: 0.9rem;
    }

    .ratio-table td[data-label="Ratio"]::before {
        display: none;
    }

    .verdict {
        white-space: nowrap;
    }

    .ratio-note {
        display: block;
        font-size: 0.78rem;
    }

    /* ── Maxes table ─────────────────────────────────────────── */
    .maxes-table thead {
        display: none;
    }

    .maxes-table,
    .maxes-table tbody {
        display: block;
    }

    .maxes-table tr {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--pico-muted-border-color, #eee);
    }

    .maxes-table td {
        border: none;
        padding: 0;
    }

    .maxes-lift {
        flex: 1;
    }

    .maxes-unit {
        display: none;
    }

    /* ── hgroup headings ─────────────────────────────────────── */
    hgroup h2 {
        font-size: 1.4rem;
    }

    /* ── Details/summary (week accordion) ───────────────────── */
    details > summary {
        padding: 0.6rem 0.4rem;
    }
}

/* ════════════════════════════════════════════════════════════
   MEDIUM SCREENS  (641px – 900px)
   ════════════════════════════════════════════════════════════ */
@media (min-width: 641px) and (max-width: 900px) {
    .hide-mobile {
        display: none;
    }

    .accessory-add-form .grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Exercise swap UI ───────────────────────────────────── */
.swap-details {
    display: inline-block;
    position: relative;
    margin-left: 0.3rem;
}

.swap-details summary {
    display: inline-block;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0.5;
    padding: 0 0.2rem;
    list-style: none;
    transition: opacity 0.15s;
}

.swap-details summary:hover {
    opacity: 1;
}

.swap-details[open] summary {
    opacity: 1;
}

.swap-menu {
    position: absolute;
    top: 1.5rem;
    left: 0;
    z-index: 100;
    background: var(--pico-card-background-color, #fff);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 0.5rem;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.swap-menu small {
    font-size: 0.75em;
    opacity: 0.6;
    margin-bottom: 0.2rem;
}

.btn-tiny {
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

/* ── Ontology exercise search ─────────────────────────────── */
.exercise-search-wrap {
    position: relative;
}

.exercise-search-results {
    list-style: none;
    padding: 0;
    margin: 0;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--pico-background-color, #fff);
    border: 1px solid var(--pico-muted-border-color, #ccc);
    border-radius: 4px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.exercise-search-results li {
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--pico-muted-border-color, #eee);
}

.exercise-search-results li:last-child {
    border-bottom: none;
}

.exercise-search-results li:hover {
    background: var(--pico-primary-focus, rgba(var(--pico-primary-rgb), 0.08));
}

/* ── Day session labels ─────────────────────────────────────────────── */
.day-title-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.session-label {
    font-size: 0.8rem;
    color: var(--pico-muted-color, #888);
    font-weight: normal;
}

.day-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.char-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.char-heavy     { background: #fee2e2; color: #991b1b; }
.char-technical { background: #dbeafe; color: #1e40af; }
.char-medium    { background: #fef9c3; color: #854d0e; }
.char-light     { background: #dcfce7; color: #166534; }
.char-accumulation  { background: #ede9fe; color: #6d28d9; }
.char-realization   { background: #ffedd5; color: #9a3412; }
.char-peak      { background: #fce7f3; color: #9d174d; }

.fatigue-tag {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: var(--pico-muted-background, #f3f4f6);
    color: var(--pico-muted-color, #666);
    font-weight: 500;
}

/* ── ARI metrics ─────────────────────────────────────────────────────── */
.ari-block { white-space: nowrap; }
.ari-target { color: var(--pico-muted-color, #888); font-size: 0.85em; }

.ari-above { color: #f59e0b; }   /* amber — higher than target */
.ari-on    { color: #10b981; }   /* green — on target */
.ari-below { color: #ef4444; }   /* red — below target */

/* ── Suggested weight hint ───────────────────────────────────────────── */
.suggested-weight {
    margin-top: 0.2rem;
    padding: 0.15rem 0.4rem;
    background: var(--pico-muted-background, #f3f4f6);
    border-left: 2px solid #a5b4fc;
    border-radius: 0 4px 4px 0;
    font-size: 0.78rem;
}
.sw-note {
    color: var(--pico-muted-color, #888);
    margin-left: 0.3rem;
}

/* ── Archive popup ───────────────────────────────────────────────────── */
dialog[open] {
    max-width: 480px;
    width: 92%;
}
.popup-metrics-table { font-size: 0.9rem; margin-bottom: 0; }
.popup-metrics-table td { padding: 0.4rem 0.5rem; }

.status-above     { color: #f59e0b; font-weight: 600; }
.status-on-target { color: #10b981; font-weight: 600; }
.status-below     { color: #ef4444; font-weight: 600; }
.status-no-target { color: var(--pico-muted-color, #888); }

.fatigue-low      { color: #10b981; font-weight: 600; }
.fatigue-moderate { color: #f59e0b; font-weight: 600; }
.fatigue-high     { color: #ef4444; font-weight: 600; }

/* ── BB rep range & hit-top-reps toggle ─────────────────────────────── */
.rep-range {
    font-weight: 600;
    font-size: 0.9em;
    letter-spacing: 0.02em;
}
.hit-top-active {
    background: #10b981;
    color: #fff;
    border-color: #10b981;
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
}
