* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #0f1117; --surface: #1a1d27; --surface2: #242836;
    --accent: #ff6b35; --accent2: #4ecdc4;
    /* --text: titles & emphasized UI text; --text-soft: body copy */
    --text: #d0d2e0;
    --text-soft: #aeb2bf;
    --muted: #8b8fa3; --border: #2d3142; --danger: #ff4757;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text-soft); line-height: 1.6; overflow-x: hidden; }

/* Header */
header { background: linear-gradient(135deg, var(--surface), var(--surface2)); border-bottom: 1px solid var(--border); padding: 1rem 1.5rem; }
.header-inner { max-width: 100%; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; padding: 0 1rem; }
.header-left h1 { font-size: 1.6rem; color: var(--text); }
.header-left .subtitle { color: var(--muted); font-size: 0.75rem; }
.settings-btn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 1.2rem; cursor: pointer; transition: border-color 0.15s; line-height: 1; }
.settings-btn:hover { border-color: var(--accent); }

/* Reconnect Banner */
.reconnect-banner {
    background: var(--surface2); border-bottom: 1px solid var(--border);
    padding: 0.6rem 1.5rem; display: flex; align-items: center; gap: 0.75rem;
    font-size: 0.85rem; color: var(--muted);
}
.reconnect-banner span:first-child { flex: 1; }
.btn-reconnect {
    padding: 0.3rem 1rem; background: var(--accent); color: #fff;
    border: none; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.btn-reconnect:hover { filter: brightness(1.1); }
.banner-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.2rem; padding: 0.5rem; line-height: 1; }
.banner-close:hover { color: var(--text); }

/* Settings Panel */
.settings-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100;
}
.settings-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 90vw;
    background: var(--bg); border-left: 1px solid var(--border);
    z-index: 101; display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.25s ease;
}
.settings-panel.open { transform: translateX(0); }
.settings-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.settings-header h2 { font-size: 1.1rem; margin: 0; }
.settings-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.2rem; }
.settings-close:hover { color: var(--text); }
.settings-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.settings-section { margin-bottom: 1.5rem; }
.settings-section h3 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.settings-desc { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.75rem; }
.settings-status {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 0.75rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 0.75rem; font-size: 0.85rem;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.connected { background: var(--accent2); }
.status-dot.disconnected { background: var(--danger); }
.settings-info {
    display: flex; justify-content: space-between; padding: 0.4rem 0;
    font-size: 0.85rem; color: var(--muted);
}
.settings-info strong { color: var(--text); }
.settings-section .btn-primary { width: 100%; margin-bottom: 0.5rem; font-size: 0.9rem; padding: 0.5rem; }
.btn-secondary {
    width: 100%; padding: 0.5rem; background: var(--surface); color: var(--text-soft);
    border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 0.9rem;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }
.btn-danger {
    width: 100%; padding: 0.5rem; background: transparent; color: var(--danger);
    border: 1px solid var(--danger); border-radius: 8px; cursor: pointer; font-size: 0.85rem; margin-top: 0.75rem;
}
.btn-danger:hover { background: rgba(255,71,87,0.1); }

main { max-width: 100%; margin: 0 auto; padding: 1.5rem 2.5rem; }
.achievement-notice {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.8rem;
    cursor: default;
}
.achievement-notice[hidden] { display: none !important; }
.achievement-notice-text {
    flex: 1;
    min-width: 0;
    line-height: 1.3;
    color: var(--text-soft);
}
.achievement-notice-hero { margin-bottom: 0.1rem; }
.achievement-notice-hero .pb-label { margin-bottom: 0.15rem; }
.achievement-notice-hero .pb-value { line-height: 1.15; }
.achievement-notice-hero .pb-detail { margin-top: 0.15rem; }
.achievement-notice-items {
    margin-top: 0.55rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--border);
}
.achievement-notice-actions {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    flex-shrink: 0;
    align-items: stretch;
}
/* Match section nav pills (Goals, Training plan, …): muted label, same hover as .section-toggle */
.achievement-notice-actions .btn-secondary {
    width: auto;
    min-width: 5.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: var(--muted);
}
@media (hover: hover) and (pointer: fine) {
    .achievement-notice-actions .btn-secondary:hover {
        border-color: var(--accent);
        color: var(--text);
    }
}
@media (hover: none), (pointer: coarse) {
    .achievement-notice-actions .btn-secondary:hover,
    .achievement-notice-actions .btn-secondary:active,
    .achievement-notice-actions .btn-secondary:focus,
    .achievement-notice-actions .btn-secondary:focus-visible {
        border-color: var(--border) !important;
        color: var(--muted) !important;
        background: var(--surface) !important;
        box-shadow: none !important;
        outline: none !important;
    }
}
.achievement-notice-item {
    color: var(--text-soft);
    font-size: 0.75rem;
    line-height: 1.38;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.achievement-notice-more {
    margin-top: 0.45rem;
    font-size: 0.72rem;
    color: var(--muted);
    line-height: 1.35;
}
@media (max-width: 700px) {
    .achievement-notice { flex-direction: column; align-items: stretch; }
    .achievement-notice-actions { flex-direction: row; flex-wrap: wrap; }
}
@media (max-width: 480px) {
    .achievement-notice-item { font-size: 0.72rem; line-height: 1.4; }
}
section { margin-bottom: 1.5rem; }
h2 { font-size: 1.2rem; margin-bottom: 0.75rem; color: var(--text); }
h3, h4 { color: var(--text); }

/* Setup */
.setup-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2.5rem; text-align: center; max-width: 500px; margin: 2rem auto; }
.setup-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.setup-card h2 { margin-bottom: 0.5rem; }
.setup-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }
.setup-card .btn-primary { padding: 0.6rem 2rem; width: auto; }

/* Progress */
.import-progress { padding: 0.5rem 0; }
.progress-bar { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.2s; width: 0%; }
#progressText { text-align: center; color: var(--muted); font-size: 0.82rem; margin-top: 0.4rem; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.72rem 0.78rem;
    min-height: 86px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.stat-value {
    font-size: 1.22rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.12;
}
.stat-label { color: var(--muted); font-size: 0.69rem; margin-top: 0.14rem; line-height: 1.15; }
.stat-card-matrix { text-align: left; padding: 0.72rem 0.78rem 0.64rem; }
.stat-title { font-size: 0.9rem; font-weight: 700; color: var(--text); margin-bottom: 0.46rem; }
.stat-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.stat-table th,
.stat-table td { padding: 0.3rem 0.1rem; }
.stat-table th {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.stat-table th:first-child,
.stat-table td:first-child {
    text-align: left;
    width: 34%;
    color: var(--muted);
}
.stat-table th:not(:first-child),
.stat-table td:not(:first-child) {
    text-align: right;
    width: 22%;
}
.stat-table td {
    font-size: 0.9rem;
    color: var(--text-soft);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.stat-table tbody tr:last-child td { border-bottom: 0; }

.year-compare-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; margin-bottom: 0.75rem; }

/* Filters */
.filter-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.filter-group { flex: 0 1 130px; min-width: 130px; }
.filter-group label { display: block; font-size: 0.75rem; color: var(--text); margin-bottom: 0.2rem; }
select { width: 100%; padding: 0.45rem 0.6rem; background: var(--surface); color: var(--text-soft); border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; cursor: pointer; }
select:focus { outline: none; border-color: var(--accent); }
section.filters select { color: var(--text); }
.filter-actions { min-width: 150px; flex: 0 0 150px; }
.clear-filters-btn {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}
.clear-filters-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-sort { flex: 0 0 auto; min-width: 0; }
.filter-search { flex: 1 1 140px; min-width: 140px; }
.sort-chips { display: flex; gap: 0.4rem; flex-wrap: nowrap; overflow-x: auto; align-items: center; }
.sort-chip {
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    white-space: nowrap;
    flex: 0 0 auto;
    box-sizing: border-box;
}
.sort-chip:hover { border-color: var(--accent); color: var(--text); }
.sort-chip.active {
    background: rgba(255,107,53,0.16);
    color: var(--accent);
    border-color: var(--accent);
}

/* Charts */
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
.chart-header h2 { margin-bottom: 0; }
.chart-tabs { display: flex; gap: 0.4rem; }
.chart-tab { border: 1px solid var(--border); background: var(--surface2); color: var(--muted); border-radius: 999px; padding: 0.26rem 0.7rem; font-size: 0.8rem; cursor: pointer; }
.chart-tab.active { color: var(--text); border-color: var(--accent); background: rgba(255,107,53,0.14); }
.chart-tab:hover { border-color: var(--accent); color: var(--text); }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.chart-container { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; height: 280px; }

/* Activity List */
.activity-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 1rem; margin-bottom: 0.4rem; cursor: pointer; transition: border-color 0.15s; display: grid; grid-template-columns: 36px 1fr auto; gap: 0.75rem; align-items: center; }
.activity-item:hover { border-color: var(--accent); }
.activity-sport-icon { font-size: 1.3rem; text-align: center; }
.activity-info h3 { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.activity-title-link { color: inherit; text-decoration: none; }
.activity-title-link:hover { text-decoration: underline; }
.activity-info .activity-date { color: var(--muted); font-size: 0.78rem; }
/* Activity list + detail header: one compact chip size (emoji + text) */
.activity-race-badge,
.activity-indoor-badge,
.activity-structured-badge,
.activity-shoe-badge,
.activity-route-badge,
.detail-race-badge,
.detail-workout-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.22em;
    padding: 0.08rem 0.42rem;
    border-radius: 999px;
    font-size: 0.65rem;
    line-height: 1.25;
    vertical-align: middle;
    box-sizing: border-box;
}
.activity-race-badge {
    margin-left: 0.35rem;
    color: #ffd08a;
    background: rgba(255,107,53,0.18);
    border: 1px solid rgba(255,107,53,0.35);
}
.activity-indoor-badge {
    margin-left: 0.35rem;
    color: #9ad9ff;
    background: rgba(86,198,232,0.16);
    border: 1px solid rgba(86,198,232,0.34);
}
.activity-structured-badge {
    margin-left: 0.35rem;
    color: #9be7e1;
    background: rgba(78,205,196,0.16);
    border: 1px solid rgba(78,205,196,0.38);
}
.activity-shoe-badge {
    margin-left: 0.35rem;
    color: #cbb6ff;
    background: rgba(168, 128, 255, 0.16);
    border: 1px solid rgba(168, 128, 255, 0.34);
}
.activity-route-badge {
    margin-left: 0.35rem;
    color: #fde68a;
    background: rgba(250,204,21,0.12);
    border: 1px solid rgba(250,204,21,0.42);
}
.activity-list h2 { color: var(--text); }
.activity-metrics { display: flex; gap: 1.25rem; font-size: 0.82rem; text-align: right; color: var(--text); }
.metric-value { font-weight: 600; color: var(--text); }
.activity-metrics .metric-value { white-space: nowrap; }
.activity-metrics .metric-label { white-space: nowrap; }
.metric-label { color: var(--muted); font-size: 0.7rem; }
#activityCount { color: var(--text); font-weight: 400; font-size: 0.85rem; }
.load-more { text-align: center; padding: 1rem; }
.load-more button { padding: 0.5rem 2rem; background: var(--surface); color: var(--text-soft); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.load-more button:hover { border-color: var(--accent); }

/* Detail */
.back-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 0.9rem; margin-bottom: 0.75rem; padding: 0.2rem 0; }
.back-btn:hover { text-decoration: underline; }
.detail-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 0.5rem;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.detail-header h2 { margin-bottom: 0.15rem; }
.detail-header-meta {
    margin-top: 0.5rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--border);
}
.detail-header-meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem 1rem;
}
.detail-datetime-visual {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}
.detail-datetime-visual--empty {
    color: var(--muted);
    font-size: 0.85rem;
}
.detail-dt-cal {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 2.85rem;
    flex-shrink: 0;
    border-radius: 9px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface2);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.detail-dt-cal-month {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-align: center;
    padding: 0.22rem 0.2rem 0.18rem;
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    color: var(--accent);
}
.detail-dt-cal-day {
    font-size: 1.38rem;
    font-weight: 800;
    line-height: 1;
    text-align: center;
    padding: 0.28rem 0 0.32rem;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.detail-dt-aside {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}
.detail-dt-weekday {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}
.detail-dt-sub {
    font-size: 0.78rem;
    color: var(--muted);
    letter-spacing: 0.01em;
}
.detail-dt-dot {
    margin: 0 0.28rem;
    opacity: 0.65;
}
.detail-header-source {
    flex: 1 1 10rem;
    min-width: min(100%, 11rem);
    margin-left: auto;
    font-size: 0.74rem;
    line-height: 1.35;
    color: var(--muted);
    opacity: 0.95;
}
@media (max-width: 520px) {
    .detail-header-source {
        margin-left: 0;
        flex-basis: 100%;
    }
}
.detail-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}
/* Let the title shrink on narrow viewports; otherwise the row can exceed 100% width and
   body { overflow-x: hidden } clips the right side of the header — often the last route badge. */
.detail-title-row h2 {
    margin: 0;
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.25;
}
.detail-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.btn-icon { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.5rem; cursor: pointer; font-size: 1rem; line-height: 1; }
.btn-icon:hover { border-color: var(--accent); }
.btn-icon.active-race { border-color: #ff9a3d; color: #ffb562; background: rgba(255,154,61,0.14); }
.btn-icon-danger:hover { border-color: var(--danger); }
.detail-name-edit { display: flex; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.detail-name-edit input {
    flex: 1;
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
}
.detail-name-edit input:focus { outline: none; border-color: var(--accent); }
.detail-sport-edit { display: flex; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.detail-sport-edit select { flex: 1; }
.detail-edit-actions { display: flex; gap: 0.5rem; align-items: center; margin: 0.45rem 0 0.2rem; }
.btn-small-save { padding: 0.35rem 0.75rem; background: var(--accent); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 0.82rem; font-weight: 600; }
.btn-small-save:hover { filter: brightness(1.1); }
.btn-small-cancel { padding: 0.35rem 0.75rem; background: var(--surface2); color: var(--muted); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 0.82rem; }
.btn-small-cancel:hover { color: var(--text); border-color: var(--muted); }
.detail-workout-badge {
    background: rgba(78,205,196,0.16);
    border: 1px solid rgba(78,205,196,0.38);
    color: #9be7e1;
}
.detail-badge-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.45rem;
    min-width: 0;
    max-width: 100%;
}
.detail-badge-row > span {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.detail-badge-row .detail-race-badge,
.detail-badge-row .detail-workout-badge,
.detail-badge-row .activity-indoor-badge,
.detail-badge-row .activity-shoe-badge,
.detail-badge-row .activity-route-badge {
    margin-top: 0;
    margin-left: 0;
}
.detail-race-badge {
    background: rgba(255,107,53,0.18);
    border: 1px solid rgba(255,107,53,0.4);
    color: #ffd08a;
}
.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
.detail-stat { position: relative; background: var(--surface2); border-radius: 8px; padding: 0.6rem; text-align: center; }
.detail-stat .val { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.detail-stat .lbl { font-size: 0.7rem; color: var(--text); }
.detail-stat-help-btn {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    top: 0.32rem;
    right: 0.32rem;
    z-index: 2;
    width: 1.1rem;
    min-width: 1.1rem;
    max-width: 1.1rem;
    height: 1.1rem;
    min-height: 1.1rem;
    max-height: 1.1rem;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.06);
    color: var(--muted);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    font-size: 0.68rem;
    font-weight: 700;
    font-family: inherit;
    text-align: center;
    text-indent: 0;
    white-space: nowrap;
    overflow: hidden;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.detail-stat-help-btn:hover {
    color: var(--text);
    border-color: rgba(255,255,255,0.22);
    background: rgba(255,255,255,0.1);
}
.detail-stat-help-copy {
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.5;
}
.detail-stat-help-copy p {
    margin: 0 0 0.7rem;
}
.detail-stat-help-copy p:last-child {
    margin-bottom: 0;
}
.detail-chart-container { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; margin-bottom: 0.75rem; }
.detail-chart-container h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }
.detail-chart-container canvas { max-height: 200px; }
.detail-compact-layout { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.75rem; }
.detail-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.6rem; align-items: start; }
.detail-row-single { grid-template-columns: minmax(0, 1fr); }
.detail-col { min-width: 0; display: flex; flex-direction: column; }
.detail-col .detail-chart-container,
.detail-col .detail-map { margin-bottom: 0; }
.detail-laps-card .laps-table-wrap { max-height: 420px; overflow: auto; }
.detail-metric-toggles { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.metric-toggle {
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--muted);
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    cursor: pointer;
}
.metric-toggle.is-active {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(255,107,53,0.14);
}
.metric-toggle:hover { border-color: var(--accent); color: var(--text); }
.metrics-selection-hint {
    display: none;
    margin-bottom: 0.35rem;
    padding: 0.22rem 0.5rem;
    border-radius: 999px;
    border: 1px solid rgba(250,204,21,0.45);
    background: rgba(250,204,21,0.12);
    color: #fde68a;
    font-size: 0.72rem;
}
.metrics-selection-hint.active { display: inline-block; }
.metrics-effort-active {
    border-color: rgba(250,204,21,0.45);
    box-shadow: 0 0 0 1px rgba(250,204,21,0.15) inset;
}
.pace-analysis-toolbar { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.pace-mode-tabs, .pace-metric-tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pace-tab {
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--muted);
    border-radius: 6px;
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
    cursor: pointer;
}
.pace-tab.is-active { color: var(--text); border-color: var(--accent); background: rgba(86,198,232,0.12); }
.pace-analysis-wrap { height: 205px; }
.chart-live-value {
    margin-top: 0.35rem;
    font-size: 0.74rem;
    color: var(--muted);
}
/* AI insight: width matches right edge of the "Avg HR" stat tile (set inline in app.js); fallback before measure */
#detailContent #aiInsightBox.ai-insight-box {
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.chart-live-value-metrics { margin-top: 0.35rem; }
.metrics-live-top { display: flex; justify-content: space-between; gap: 0.5rem; min-height: 1.1rem; }
.metrics-live-km { margin-top: 0.08rem; min-height: 1rem; }
.metrics-live-top span, .metrics-live-km { font-size: 0.74rem; color: var(--muted); }
.zone-chart-wrap { height: 170px; margin-bottom: 0.45rem; }
.zone-list { display: flex; flex-direction: column; gap: 0.38rem; }
.zone-row { border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.5rem; background: var(--surface2); }
.zone-meta { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.78rem; margin-bottom: 0.2rem; }
.zone-key { font-weight: 700; color: var(--text); }
.zone-label { color: var(--muted); text-align: right; }
.zone-stats { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.74rem; color: var(--text-soft); margin-bottom: 0.2rem; }
.zone-bar { height: 8px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; }
.zone-bar span { display: block; height: 100%; border-radius: inherit; min-width: 2px; }
.zone-list-hr .zone-bar span { background: linear-gradient(90deg, #ff8a8a, #ff4d6d); }
.zone-list-pace .zone-bar span { background: linear-gradient(90deg, #73d9d1, #2eb7a8); }
.laps-table-wrap { overflow-x: auto; }
.laps-table { width: 100%; min-width: 0; border-collapse: collapse; font-size: 0.83rem; table-layout: fixed; }
.laps-table th, .laps-table td { padding: 0.46rem 0.6rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.laps-table th { color: var(--muted); font-weight: 500; font-size: 0.76rem; }
.laps-table th:first-child, .laps-table td:first-child { text-align: left; }
.zones-table th:nth-child(1), .zones-table td:nth-child(1) { width: 14%; text-align: left; }
.zones-table th:nth-child(2), .zones-table td:nth-child(2) { width: 46%; text-align: left; }
.zones-table th:nth-child(3), .zones-table td:nth-child(3) { width: 24%; text-align: right; }
.zones-table th:nth-child(4), .zones-table td:nth-child(4) { width: 16%; text-align: right; }
.performance-table th:nth-child(1), .performance-table td:nth-child(1) { text-align: left; }
.performance-table th:nth-child(n+2), .performance-table td:nth-child(n+2) { text-align: right; }
.laps-detail-table th:nth-child(1), .laps-detail-table td:nth-child(1) { width: 8%; }
.laps-detail-table th:nth-child(2), .laps-detail-table td:nth-child(2) { width: 26%; }
.laps-detail-table th:nth-child(3), .laps-detail-table td:nth-child(3) { width: 22%; }
.laps-detail-table th:nth-child(4), .laps-detail-table td:nth-child(4) { width: 22%; }
.laps-detail-table th:nth-child(5), .laps-detail-table td:nth-child(5) { width: 22%; }
.best-efforts-table th:nth-child(1), .best-efforts-table td:nth-child(1) { width: 44%; text-align: left; }
.best-efforts-table th:nth-child(2), .best-efforts-table td:nth-child(2) { width: 20%; text-align: right; }
.best-efforts-table th:nth-child(3), .best-efforts-table td:nth-child(3) { width: 20%; text-align: right; }
.best-efforts-table th:nth-child(4), .best-efforts-table td:nth-child(4) { width: 16%; text-align: right; }
.best-effort-row { cursor: pointer; }
.best-effort-row:hover td { color: var(--accent); background: rgba(255,107,53,0.05); }
.best-effort-row.selected td {
    color: var(--accent);
    background: rgba(255,107,53,0.14);
}
.target-analysis-table th:nth-child(1), .target-analysis-table td:nth-child(1) { width: 22%; text-align: left; }
.target-analysis-table th:nth-child(2), .target-analysis-table td:nth-child(2) { width: 23%; text-align: left; }
.target-analysis-table th:nth-child(3), .target-analysis-table td:nth-child(3) { width: 16%; text-align: right; }
.target-analysis-table th:nth-child(4), .target-analysis-table td:nth-child(4) { width: 24%; text-align: left; }
.target-analysis-table th:nth-child(5), .target-analysis-table td:nth-child(5) { width: 15%; text-align: right; }
.target-bar {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    display: flex;
    background: var(--surface2);
    border: 1px solid rgba(255,255,255,0.08);
}
.target-under { background: #4ecdc4; }
.target-in { background: #4ade80; }
.target-over { background: #ff6b35; }
.target-share {
    margin-top: 0.26rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: var(--muted);
}
.target-legend { margin-top: 0.55rem; display: flex; gap: 0.35rem; flex-wrap: wrap; }
.target-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    font-size: 0.69rem;
    border: 1px solid var(--border);
    color: var(--text);
}
.target-chip-under { background: rgba(78,205,196,0.18); border-color: rgba(78,205,196,0.4); }
.target-chip-in { background: rgba(74,222,128,0.18); border-color: rgba(74,222,128,0.4); }
.target-chip-over { background: rgba(255,107,53,0.18); border-color: rgba(255,107,53,0.4); }
.workout-steps-compliance-desc { margin-bottom: 0.35rem; }
.workout-overall-compliance {
    margin: 0 0 0.65rem;
    padding: 0.5rem 0.55rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface2);
}
.workout-overall-compliance .target-bar { max-width: 100%; }
.workout-overall-compliance-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.35rem;
    flex-wrap: wrap;
    gap: 0.25rem 0.65rem;
}
.workout-overall-label { font-weight: 600; font-size: 0.82rem; color: var(--text); }
.workout-overall-summary { font-size: 0.8rem; color: var(--muted); }
.workout-steps-table th:nth-child(1), .workout-steps-table td:nth-child(1) { width: 2.2rem; text-align: right; }
.workout-steps-table th:nth-child(2), .workout-steps-table td:nth-child(2) { min-width: 5rem; }
.workout-steps-table th:nth-child(6), .workout-steps-table td:nth-child(6),
.workout-steps-table th:nth-child(7), .workout-steps-table td:nth-child(7),
.workout-steps-table th:nth-child(9), .workout-steps-table td:nth-child(9) { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.workout-steps-table th:nth-child(8), .workout-steps-table td:nth-child(8) { min-width: 7.2rem; vertical-align: middle; }
.workout-step-compliance .target-share { font-size: 0.62rem; }
.target-legend--below-table { margin-top: 0.4rem; }
.target-legend--inline { margin-top: 0.35rem; }
.mobile-step-compliance { margin-top: 0.35rem; }
.lap-timeline {
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin: 0.25rem 0 0.45rem;
    min-height: 24px;
}
.lap-block {
    border-radius: 6px;
    min-width: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.67rem;
    font-weight: 700;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
}
.lap-block span { pointer-events: none; }
.lap-fast { background: linear-gradient(180deg, #22c55e, #16a34a); }
.lap-mid { background: linear-gradient(180deg, #4ecdc4, #26a69a); }
.lap-slow { background: linear-gradient(180deg, #ff6b35, #e4572a); }
.lap-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.9rem;
    margin-bottom: 0.65rem;
    color: var(--muted);
    font-size: 0.74rem;
}
.lap-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.lap-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
}
.step-timeline {
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin: 0.25rem 0 0.55rem;
    min-height: 28px;
}
.step-block {
    border-radius: 6px;
    min-width: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
    opacity: 0.95;
}
.step-block span { pointer-events: none; }
.step-block.active { background: linear-gradient(180deg, #ff6b35, #e4572a); }
.step-block.rest { background: linear-gradient(180deg, #4ecdc4, #32b7ae); }
.step-block.warmup { background: linear-gradient(180deg, #facc15, #eab308); color: #1a1d27; }
.step-block.cooldown { background: linear-gradient(180deg, #a78bfa, #8b5cf6); }
.step-block.repeat { background: linear-gradient(180deg, #8b8fa3, #6b7280); }
.step-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.9rem;
    margin-bottom: 0.65rem;
    color: var(--muted);
    font-size: 0.74rem;
}
.step-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.step-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
}
.step-dot.active { background: #ff6b35; }
.step-dot.rest { background: #4ecdc4; }
.step-dot.warmup { background: #facc15; }
.step-dot.cooldown { background: #a78bfa; }
.step-dot.repeat { background: #8b8fa3; }

/* Map */
.detail-map { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 0.75rem; }
.detail-map h3 { font-size: 0.95rem; padding: 0.75rem 0.75rem 0.5rem; }
#detailMap { height: 350px; width: 100%; background: var(--surface2); }

/* Loading */
.loading-inline { text-align: center; padding: 1rem; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 0.5rem; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .year-compare-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-grid { grid-template-columns: 1fr; }
    .detail-row { grid-template-columns: 1fr; }
    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-group,
    .filter-search,
    .filter-sort,
    .filter-actions {
        width: 100%;
        flex: 0 0 auto;
        min-width: 0;
    }
    .filter-actions { min-width: 0; }
    .filter-actions label { display: none; }
}
@media (max-width: 480px) {
    .activity-item { grid-template-columns: 30px 1fr; }
    .activity-metrics { grid-column: 1 / -1; justify-content: space-between; }
    #detailMap { height: 250px; }
    .settings-panel { width: 100%; max-width: 100vw; }
    .best-efforts-table { table-layout: fixed; }
    .best-efforts-table th,
    .best-efforts-table td { padding: 0.44rem 0.45rem; font-size: 0.8rem; }
    .best-efforts-table th:nth-child(1),
    .best-efforts-table td:nth-child(1) {
        width: 50%;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
        line-height: 1.25;
        vertical-align: top;
    }
    .best-efforts-table th:nth-child(2),
    .best-efforts-table td:nth-child(2) { width: 18%; }
    .best-efforts-table th:nth-child(3),
    .best-efforts-table td:nth-child(3) { width: 17%; }
    .best-efforts-table th:nth-child(4),
    .best-efforts-table td:nth-child(4) { width: 15%; }
    .best-efforts-table th:nth-child(n+2),
    .best-efforts-table td:nth-child(n+2) {
        white-space: nowrap;
        vertical-align: top;
    }
}


/* Leaflet controls dark theme */
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--surface2) !important; }


/* Personal Bests */
.pb-section h2 { margin-bottom: 0.75rem; }
.pb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.6rem; }
.pb-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 0.85rem 1rem; cursor: pointer; transition: border-color 0.15s;
}
.pb-card:hover { border-color: var(--accent); }
.pb-card.pb-empty { opacity: 0.4; cursor: default; }
.pb-card.pb-empty:hover { border-color: var(--border); }
/* Default PB-related label; KM on cards matches page heading tier (no teal) */
.pb-label { font-size: 0.78rem; margin-bottom: 0.2rem; color: var(--muted); }
.pb-card .pb-label { color: var(--text); font-weight: 600; }
.pb-value { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.pb-detail { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.pb-category { margin-bottom: 1rem; }
.pb-category h3 { font-size: 0.9rem; margin-bottom: 0.5rem; font-weight: 500; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.6rem; }
.badge-card {
    background: linear-gradient(160deg, rgba(255,107,53,0.14), rgba(78,205,196,0.08));
    border: 1px solid rgba(255,107,53,0.35);
    border-radius: 10px;
    padding: 0.7rem 0.8rem;
    min-height: 88px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.badge-card-empty {
    background: var(--surface);
    border-color: var(--border);
}
.badge-icon { font-size: 1rem; margin-bottom: 0.2rem; }
.badge-title { font-size: 0.86rem; font-weight: 700; color: var(--text); }
.badge-detail { font-size: 0.72rem; color: var(--muted); margin-top: 0.18rem; line-height: 1.2; }

.pb-analysis-intro { font-size: 0.78rem; color: var(--muted); margin: -0.25rem 0 0.6rem; line-height: 1.35; }
.pb-analysis-details {
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 0.45rem; overflow: hidden;
}
.pb-analysis-details summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    padding: 0.55rem 0.75rem; font-size: 0.85rem; user-select: none;
}
.pb-analysis-details summary::-webkit-details-marker { display: none; }
.pb-analysis-details summary::after { content: '▸'; color: var(--muted); font-size: 0.7rem; transition: transform 0.15s; }
.pb-analysis-details[open] summary::after { transform: rotate(90deg); }
.pb-analysis-details summary:hover { background: var(--surface2); }
.pb-analysis-sum-label { font-weight: 600; color: var(--text-soft); }
.pb-analysis-sum-meta {
    margin-left: auto;
    padding-right: 0.55rem;
    text-align: right;
    font-size: 0.72rem;
    color: var(--muted);
}
.route-manage-actions {
    display: inline-flex;
    gap: 0.35rem;
    margin-left: 0.4rem;
    margin-right: 0.7rem;
}
.route-manage-actions .btn-xs {
    padding: 0.15rem 0.42rem;
    font-size: 0.68rem;
}
.pb-analysis-cols {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 0.75rem;
    padding: 0 0.65rem 0.65rem; border-top: 1px solid var(--border);
}
@media (max-width: 720px) { .pb-analysis-cols { grid-template-columns: 1fr; } }
.pb-analysis-col h5 { font-size: 0.72rem; color: var(--muted); font-weight: 500; margin: 0.5rem 0 0.35rem; }
.pb-analysis-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.pb-analysis-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 0.2rem 0.35rem 0.35rem 0; border-bottom: 1px solid var(--border); }
.pb-analysis-table td { padding: 0.28rem 0.35rem 0.28rem 0; border-bottom: 1px solid rgba(255,255,255,0.06); vertical-align: top; }
.pb-analysis-table tr.pb-analysis-row { cursor: pointer; }
.pb-analysis-table tr.pb-analysis-row:hover td { color: var(--accent); }
.pb-analysis-name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-analysis-empty { color: var(--muted); font-style: italic; padding: 0.5rem 0 !important; }

.achievement-log {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.35rem 0.55rem;
}
/* PB “Last 50”: show ~10 rows; scroll for the rest (50 lines still rendered). */
.achievement-log.achievement-log-recent-scroll {
    max-height: calc((0.78rem * 1.35 + 0.45rem * 2 + 1px) * 10);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}
.achievement-line {
    font-size: 0.78rem;
    line-height: 1.38;
    color: var(--text-soft);
    padding: 0.45rem 0.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    word-break: break-word;
    overflow-wrap: anywhere;
}
@media (max-width: 480px) {
    .achievement-line { font-size: 0.74rem; line-height: 1.42; padding: 0.4rem 0.2rem; }
}
.achievement-line:last-child { border-bottom: 0; }
.achievement-clickable { cursor: pointer; }
.achievement-clickable:hover { color: var(--accent); }
.achievement-empty { color: var(--muted); font-style: italic; }


/* KM markers on map */
.km-marker {
    background: rgba(255,255,255,0.9); color: #333; font-size: 11px; font-weight: 700;
    width: 22px !important; height: 22px !important; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.km-marker span { line-height: 1; }


/* Exclude badge */
.exclude-badge {
    display: inline-block; background: rgba(255,71,87,0.15); color: var(--danger);
    font-size: 0.78rem; padding: 0.25rem 0.6rem; border-radius: 4px; margin-top: 0.4rem;
}


/* Fitness & Freshness */
.fitness-cards { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.fitness-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 1.25rem; text-align: center; flex: 1 1 170px; }
.fitness-value { font-size: 2rem; font-weight: 700; }
.fitness-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.1rem; }
.fitness-color { color: var(--accent); }
.fatigue-color { color: #a78bfa; }
.form-color { color: var(--accent2); }
.readiness-color { color: #facc15; }
.ff-chart-container { height: 320px; }
.ff-range-select { padding: 0.3rem 0.6rem; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 0.8rem; cursor: pointer; }
.ff-range-select:focus { outline: none; border-color: var(--accent); }

/* Search input */
.filter-search input { width: 100%; padding: 0.45rem 0.6rem; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; }
.filter-search input:focus { outline: none; border-color: var(--accent); }
.filter-search input::placeholder { color: var(--text); }

/* Statistics sub-sections */
.trend-section, .streak-section, .weekly-stats-section, .race-section { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.trend-section h3, .streak-section h3, .weekly-stats-section h3, .race-section h3 { font-size: 0.85rem; margin-bottom: 0.5rem; font-weight: 500; }
.stats-subsection-title { display: block; font-family: inherit !important; line-height: 1.2; font-size: 0.85rem !important; color: var(--text) !important; margin: 0 0 0.5rem !important; font-weight: 500 !important; background: transparent !important; }
.weekly-stats-section { position: relative; margin-top: 1.15rem; padding-top: 0.95rem; border-top: 1px solid var(--border) !important; box-shadow: inset 0 1px 0 rgba(255,255,255,0.05); }
.weekly-stats-section::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; background: var(--border); opacity: 0.9; pointer-events: none; }

/* Unified stat cards for trends, streaks, race */
.trend-grid, .streak-grid, .race-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.trend-card, .streak-card, .race-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 0.72rem 0.78rem;
    min-height: 86px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
}
.trend-label, .streak-label, .race-dist {
    font-size: 0.69rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.15rem;
    line-height: 1.15;
}
.trend-value, .streak-val, .race-time {
    font-size: 1.22rem;
    font-weight: 700;
    line-height: 1.12;
}
.trend-change { font-size: 0.69rem; margin-top: 0.14rem; line-height: 1.15; }
.trend-up { color: #4ade80; }
.trend-down { color: var(--accent); }
.trend-neutral { color: var(--muted); }

.streak-val { color: var(--accent); }
.streak-detail { font-size: 0.69rem; color: var(--muted); margin-top: 0.14rem; line-height: 1.15; }

.race-card { text-align: center; }
.race-time { color: var(--accent2); margin: 0.12rem 0 0.08rem; }
.race-pace { font-size: 0.69rem; color: var(--muted); line-height: 1.15; }

@media (max-width: 768px) {
    .trend-grid, .streak-grid, .race-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Calendar heatmap */

/* Notes */
.detail-notes { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; margin-top: 0.75rem; margin-bottom: 0.75rem; }
.detail-notes h3 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.detail-notes textarea { width: 100%; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem; font-size: 0.85rem; font-family: inherit; resize: vertical; min-height: 60px; }
.detail-notes textarea:focus { outline: none; border-color: var(--accent); }
.detail-notes-readonly { margin-bottom: 0.65rem; }
.detail-notes-readonly .detail-notes-body {
    font-size: 0.86rem;
    line-height: 1.45;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}
.activity-edit-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.activity-edit-modal-actions .btn-secondary {
    width: 100%;
    margin-top: 0;
}
.activity-edit-inline-check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.88rem; cursor: pointer; user-select: none; }
.activity-edit-inline-check input { width: auto; margin: 0; cursor: pointer; }
textarea.activity-edit-notes {
    width: 100%;
    box-sizing: border-box;
    min-height: 5.5rem;
    resize: vertical;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    font-family: inherit;
    line-height: 1.45;
}
textarea.activity-edit-notes:focus {
    outline: none;
    border-color: var(--accent);
}
textarea.activity-edit-notes::placeholder {
    color: var(--muted);
}


/* Goals */
.goals-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.goals-header h2 { margin: 0; }
.goals-edit { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 0.75rem; }
.goal-edit-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.goal-edit-row label { font-size: 0.85rem; color: var(--muted); min-width: 120px; }
.goal-edit-row input { flex: 1; padding: 0.4rem 0.6rem; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; max-width: 120px; }
.goal-edit-row input:focus { outline: none; border-color: var(--accent); }
.goal-edit-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.goals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.goal-column { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.goal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.goal-card-main { height: 134px; display: flex; flex-direction: column; }
/* Goals card titles: same heading tier as h2/h3 (scoped via #goalsBody) */
#goalsBody .goal-period {
    font-size: 0.75rem;
    margin: 0 0 0.4rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.25;
}
.goal-progress-text { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.6rem; }
.goal-progress-text .goal-current { color: var(--accent); }
.goal-progress-text .goal-target { color: var(--muted); font-weight: 400; font-size: 1rem; }
.goal-bar { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; position: relative; margin-bottom: 0.5rem; }
.goal-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.goal-bar-fill.on-track { background: var(--accent2); }
.goal-bar-fill.behind { background: var(--accent); }
.goal-bar-fill.complete { background: #4ade80; }
.goal-bar-pace { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--text); border-radius: 2px; z-index: 1; }
.goal-pace-info { font-size: 0.8rem; color: var(--muted); }
.goal-pace-info .ahead { color: var(--accent2); }
.goal-pace-info .behind { color: var(--accent); }
.goal-days { display: flex; gap: 3px; margin-bottom: 0.5rem; }
.goal-day { width: 100%; height: 4px; border-radius: 2px; background: var(--surface2); }
.goal-day.active { background: var(--accent2); }
.goal-empty { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 1.5rem; }
.goal-history-box { background: var(--surface); border: 1px solid var(--border); }
.goal-history-bars { display: flex; flex-direction: column; gap: 0.35rem; }
.goal-history-row { display: grid; grid-template-columns: 60px 1fr auto; gap: 0.5rem; align-items: center; }
.goal-history-row-label { font-size: 0.74rem; color: var(--muted); }
.goal-history-row-bar { position: relative; height: 8px; border-radius: 999px; background: var(--surface2); overflow: hidden; border: 1px solid var(--border); }
.goal-history-row-fill { height: 100%; border-radius: 999px; }
.goal-history-row-fill.reached { background: var(--accent2); }
.goal-history-row-fill.missed { background: var(--accent); }
.goal-history-row-val { font-size: 0.74rem; color: var(--muted); white-space: nowrap; }
@media (max-width: 480px) { .goals-grid { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .goal-history-row { grid-template-columns: 54px 1fr; } .goal-history-row-val { grid-column: 1 / -1; justify-self: end; } }
@media (max-width: 700px) { .route-fine-tune { grid-template-columns: 1fr; } }


/* Collapsible sections */
.collapsible-header {
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; user-select: none; padding: 0.6rem 0;
}
.collapsible-header h2 { margin: 0; }
.collapse-icon {
    font-size: 0.8rem; color: var(--muted); transition: transform 0.2s;
}
.collapsible-header.collapsed .collapse-icon { transform: rotate(-90deg); }
.collapsible-body { overflow: hidden; transition: max-height 0.3s ease; }
.collapsible-body.collapsed { max-height: 0 !important; overflow: hidden; }

/* Hide sections completely when their content is collapsed */
section:has(> .collapsible-body.collapsed) { display: none; }


/* Section toggle buttons */
.section-toggles { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section-toggle {
    padding: 0.5rem 1rem; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
    font-size: 0.85rem; transition: all 0.15s; -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) and (pointer: fine) {
    .section-toggle:hover { border-color: var(--accent); color: var(--text); }
}
/* Omit border-color: :focus stays after click and would beat :hover (same specificity, later rule). */
.section-toggle:focus,
.section-toggle:focus-visible {
    outline: none;
    box-shadow: none;
}
.section-toggle.active { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (hover: none), (pointer: coarse) {
    .section-toggle:not(.active):hover,
    .section-toggle:not(.active):active,
    .section-toggle:not(.active):focus,
    .section-toggle:not(.active):focus-visible {
        border-color: var(--border) !important;
        color: var(--text) !important;
        background: var(--surface) !important;
        box-shadow: none !important;
        outline: none !important;
    }
}
.section-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.btn-small-inline { width: auto; margin: 0; padding: 0.35rem 0.65rem; font-size: 0.78rem; }

.route-card, .shoe-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.9rem;
    margin-bottom: 0.65rem;
}
.route-top, .shoe-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.route-name, .shoe-name { font-weight: 700; font-size: 0.92rem; color: var(--text); }
.route-meta, .shoe-meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.2rem; }
.route-actions, .shoe-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
/* Shoes: Add Shoe + card actions — same emphasis as activity titles */
#shoesSection .btn-secondary,
#shoesSection .btn-xs {
    color: var(--text);
}
#shoesSection .btn-secondary:hover,
#shoesSection .btn-xs:hover {
    color: var(--text);
}
.btn-xs {
    padding: 0.22rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-soft);
    font-size: 0.75rem;
    cursor: pointer;
}
.btn-xs:hover { border-color: var(--accent); }
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 12000;
}
.modal-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 420px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.45);
    z-index: 12010;
}
#appConfirmModal {
    width: min(94vw, 460px);
}
/* Room for long activity titles in the name field */
#activityEditModal {
    width: min(96vw, 580px);
}
/* Author `display:flex` on the panel must not defeat the HTML `hidden` attribute (UA loses specificity). */
#trainingPlanSettingsOverlay[hidden],
#trainingPlanSettingsModal[hidden] {
    display: none !important;
    pointer-events: none !important;
}
#trainingPlanSettingsModal {
    width: min(98vw, 640px);
    max-height: min(96vh, 860px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#trainingPlanSettingsModal .training-plan-settings-modal-body {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding-top: 0.65rem;
    padding-bottom: 1rem;
}
#trainingPlanSettingsModal .training-plan-settings-modal-body .training-plan-hint,
#trainingPlanSettingsModal .training-plan-settings-modal-body .training-plan-subhint {
    margin-top: 0.25rem;
    margin-bottom: 0.35rem;
}
#trainingPlanSettingsModal .training-plan-fieldset {
    margin-bottom: 0.35rem;
}
#trainingPlanSettingsModal .training-plan-controls {
    gap: 0.45rem;
    margin-bottom: 0;
}
#trainingPlanSettingsModal .training-plan-controls .goal-edit-row {
    margin-bottom: 0;
}
#routeBuilderModal {
    width: min(96vw, 980px);
    max-height: 92vh;
    overflow: auto;
}
#routeBuilderModal #routeEditorMap {
    height: 220px;
}
.route-builder-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: linear-gradient(180deg, rgba(20,24,39,0.1), rgba(20,24,39,0.98) 30%);
    padding-top: 0.6rem;
    margin-top: 0.45rem;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 0.9rem 0.65rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 0.98rem; }
.modal-body { padding: 0.85rem 0.9rem 0.95rem; }
.app-confirm-message {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--text);
    white-space: pre-wrap;
}
.app-confirm-actions {
    margin-top: 0.85rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.55rem;
    flex-wrap: wrap;
}
.app-confirm-actions button { width: auto; margin: 0; }
.app-confirm-typed-wrap {
    margin-top: 0.75rem;
    margin-bottom: 0.15rem;
}
.app-confirm-typed-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.45rem 0.55rem;
    font-size: 0.9rem;
    font-family: ui-monospace, monospace;
    letter-spacing: 0.04em;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.app-confirm-typed-input:focus {
    outline: none;
    border-color: var(--accent);
}
.app-confirm-note-wrap {
    margin-top: 0.75rem;
    margin-bottom: 0.15rem;
}
.app-confirm-note-label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}
.app-confirm-note-input {
    width: 100%;
    min-height: 4.5rem;
    resize: vertical;
    box-sizing: border-box;
    padding: 0.45rem 0.55rem;
    font-size: 0.86rem;
    line-height: 1.4;
    font-family: inherit;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.app-confirm-note-input:focus {
    outline: none;
    border-color: var(--accent);
}
.modal-body .goal-edit-row input,
.modal-body .goal-edit-row select {
    flex: 1;
    max-width: none;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.55rem;
    font-size: 0.88rem;
}
.shoe-rule {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.45rem;
    align-items: center;
    flex-wrap: wrap;
}
.shoe-rule select, .shoe-rule input, .route-create-box input, .route-create-box select {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.45rem;
    font-size: 0.8rem;
}
.route-create-box {
    margin-bottom: 0.75rem;
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    background: rgba(255,255,255,0.01);
}
.route-create-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.route-create-grid label {
    display: block;
    font-size: 0.76rem;
    color: var(--muted);
    margin-bottom: 0.28rem;
}
.route-create-grid input[type="range"] { width: 100%; }
.route-create-grid input[disabled] {
    opacity: 0.95;
}
.route-fine-tune {
    margin-top: 0.6rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
}
.route-fine-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem;
}
.route-fine-card label { display: block; margin-bottom: 0.35rem; }
.route-fine-actions { display: flex; gap: 0.45rem; margin-top: 0.35rem; }
#routeStartRange, #routeEndRange { accent-color: #ff6b35; }
.route-map-hint {
    margin-top: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.76rem;
    color: var(--muted);
}
#routeEditorMap {
    height: 250px;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface2);
}
.route-progress-table { width: 100%; border-collapse: collapse; margin-top: 0.45rem; font-size: 0.79rem; }
.route-progress-table th, .route-progress-table td { border-bottom: 1px solid var(--border); padding: 0.35rem 0.3rem; text-align: left; }
.route-activity-link {
    background: none;
    border: none;
    color: inherit;
    padding: 0;
    font: inherit;
    cursor: pointer;
    text-align: left;
}
.route-activity-link:hover { color: inherit; text-decoration: underline; }
.route-progress-fast { color: #4ade80; font-weight: 600; }
.route-progress-slow { color: var(--accent); font-weight: 600; }


.training-plan-section { margin-top: 0; }
.training-plan-hint { margin-top: -0.15rem; margin-bottom: 0.45rem; font-size: 0.76rem; line-height: 1.35; }
.training-plan-subhint { margin-top: -0.2rem; margin-bottom: 0.35rem; font-size: 0.72rem; opacity: 0.92; }
.training-plan-fieldset {
    margin: 0 0 0.55rem;
    padding: 0.45rem 0.55rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}
.training-plan-legend {
    padding: 0 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
}
.training-plan-day-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.tp-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.45rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface2);
    font-size: 0.76rem;
    cursor: pointer;
    user-select: none;
}
.tp-chip input { margin: 0; cursor: pointer; }
.tp-chip:has(input:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, var(--surface2));
}
/* Single column: each label+control stays one row (2-col grid paired unrelated fields, e.g. Runs + Weeks). */
.training-plan-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.65rem;
    margin-bottom: 0.5rem;
}
@media (max-width: 420px) {
    .training-plan-controls .goal-edit-row {
        flex-direction: column;
        align-items: stretch;
    }
    .training-plan-controls .goal-edit-row > label {
        flex: none;
    }
}
.training-plan-controls .goal-edit-row {
    margin-bottom: 0;
    align-items: center;
    gap: 0.5rem 0.75rem;
    min-width: 0;
}
.training-plan-controls .goal-edit-row > label {
    flex: 0 0 min(42%, 11.5rem);
    min-width: 0;
    line-height: 1.25;
}
.training-plan-controls .goal-edit-row select,
.training-plan-controls .goal-edit-row input[type="date"] {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    max-width: none;
    padding: 0.4rem 0.55rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
}
.training-plan-controls .goal-edit-row input[type="date"] {
    /* Native date control needs room for text + calendar affordance */
    min-width: 10.5rem;
}
.training-plan-adapt-hint {
    margin: 0.35rem 0 0.45rem;
    font-size: 0.76rem;
    line-height: 1.4;
}
/* Match Generate / Update plan: same filled “primary” look (not outline). */
.training-plan-actions .btn-primary {
    width: auto;
    margin: 0;
    padding: 0.5rem 1rem;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #f2f2f5, #e6e6ea);
    color: #14151c;
}
.training-plan-actions .btn-primary:hover {
    filter: brightness(1.05);
    border-color: #3d4258;
}
.training-plan-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0 0.35rem;
}
.training-plan-actions .btn-training-plan-view {
    width: auto;
    margin: 0;
    padding: 0.42rem 0.72rem;
    font-size: 0.78rem;
}
.training-plan-actions .btn-secondary.btn-training-plan-view {
    color: var(--text);
}
.training-plan-actions .btn-secondary.btn-training-plan-view:hover {
    color: var(--text);
}
.training-plan-meta {
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
    min-height: 1rem;
}
.training-plan-output {
    /* Raw markdown backing store for copy/export only (kept out of visual UI). */
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.training-plan-rendered {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.35rem;
}
.training-plan-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.7rem;
}
.training-plan-card > summary {
    cursor: pointer;
    list-style: none;
    font-size: 0.82rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text);
}
.training-plan-card > summary::-webkit-details-marker { display: none; }
.training-plan-card > summary::after {
    content: '▸';
    opacity: 0.8;
    font-size: 0.82rem;
}
.training-plan-card[open] > summary::after { content: '▾'; }
.training-plan-card pre {
    margin: 0.35rem 0 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.77rem;
    line-height: 1.4;
    font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
    color: var(--text-soft);
}
.training-plan-summary-block {
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: 7px;
    background: color-mix(in srgb, var(--surface2) 80%, #1e2436);
    padding: 0.4rem 0.48rem;
    margin-top: 0.4rem;
}
.training-plan-summary-block h4 {
    margin: 0 0 0.2rem;
    font-size: 0.79rem;
    color: var(--text);
}
.training-plan-summary-block pre {
    margin: 0;
    color: var(--text-soft);
}
.training-plan-summary-block.summary-phases { border-left-color: #8b5cf6; }
.training-plan-summary-block.summary-race-time { border-left-color: #f97316; }
.training-plan-summary-block.summary-adjustments { border-left-color: #ec4899; }
.training-plan-summary-block.summary-notes { border-left-color: #06b6d4; }
.training-plan-week {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.training-plan-week > summary {
    cursor: pointer;
    list-style: none;
    padding: 0.58rem 0.7rem 0.55rem;
    font-size: 0.8rem;
    font-weight: 700;
    border-bottom: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    color: var(--text);
}
.training-plan-week-title {
    flex: 1 1 auto;
    min-width: 0;
    white-space: normal;
}
.training-plan-week[open] > summary {
    border-bottom-color: var(--border);
}
.training-plan-week > summary::-webkit-details-marker { display: none; }
.training-plan-week > summary::after {
    content: '▸';
    opacity: 0.85;
    font-size: 0.82rem;
}
.training-plan-week[open] > summary::after { content: '▾'; }
.training-plan-week-meta {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--muted);
    margin-left: auto;
    margin-right: 0.35rem;
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
}
.training-plan-week-actions {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    margin-right: 0.15rem;
}
@media (max-width: 760px) {
    .training-plan-week > summary {
        flex-wrap: wrap;
        align-items: flex-start;
    }
    .training-plan-week-meta {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
        text-align: left;
        order: 2;
    }
    .training-plan-week-actions {
        order: 3;
        margin-left: auto;
    }
    .training-plan-week-title {
        order: 1;
        width: 100%;
    }
}
.training-plan-week-body {
    padding: 0.58rem 0.7rem 0.65rem;
}
.training-plan-session {
    background: color-mix(in srgb, var(--surface2) 75%, #1d2233);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: 7px;
    padding: 0.46rem 0.52rem;
    margin-bottom: 0.4rem;
}
.training-plan-session.type-intervals { border-left-color: #f59e0b; }
.training-plan-session.type-fartlek { border-left-color: #a3e635; }
.training-plan-session.type-threshold { border-left-color: #fb7185; }
.training-plan-session.type-tempo { border-left-color: #f97316; }
.training-plan-session.type-long { border-left-color: #8b5cf6; }
.training-plan-session.type-easy { border-left-color: #22c55e; }
.training-plan-session.type-recovery { border-left-color: #06b6d4; }
.training-plan-session.type-cross { border-left-color: #eab308; }
.training-plan-session.type-race {
    border-left-color: #dc2626;
    background: color-mix(in srgb, var(--surface2) 72%, rgba(220, 38, 38, 0.14));
}
.training-plan-session:last-child { margin-bottom: 0; }
.training-plan-session-skipped {
    opacity: 0.55;
}
.training-plan-session-skipped .training-plan-line-title {
    text-decoration: line-through;
}
.training-plan-manual-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.12rem 0.4rem;
    margin-bottom: 0.35rem;
    border-radius: 4px;
    background: color-mix(in srgb, #ec4899 22%, var(--surface2));
    color: #f9a8d4;
    border: 1px solid color-mix(in srgb, #ec4899 45%, var(--border));
}
.training-plan-manual-note {
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
    color: var(--muted);
    font-style: italic;
}
.btn-tp-week-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    appearance: none;
    -webkit-appearance: none;
    background: color-mix(in srgb, var(--surface2) 80%, transparent);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-soft);
    opacity: 0.92;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn-tp-week-edit:hover {
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    opacity: 1;
}
.btn-tp-week-edit svg {
    display: block;
    width: 14px;
    height: 14px;
}
.training-plan-week-edit-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.tp-week-edit-item {
    display: grid;
    grid-template-columns: 5.5rem 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.2rem 0.55rem;
    align-items: start;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
}
.tp-week-edit-item-rest {
    opacity: 0.72;
    background: color-mix(in srgb, var(--surface2) 88%, transparent);
}
.tp-week-edit-item-draggable {
    cursor: grab;
    border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
    background: color-mix(in srgb, var(--surface2) 88%, var(--accent) 6%);
}
.tp-week-edit-item-draggable.tp-week-edit-dragging {
    opacity: 0.5;
    cursor: grabbing;
}
.tp-week-edit-item-skipped .tp-week-edit-payload {
    opacity: 0.55;
    text-decoration: line-through;
}
.tp-week-edit-item.tp-week-edit-drop-target {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}
.tp-week-edit-day-fixed {
    grid-row: 1 / span 2;
    user-select: none;
    pointer-events: none;
}
.tp-week-edit-weekday {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
}
.tp-week-edit-ymd {
    font-size: 0.66rem;
    color: var(--muted);
    margin-top: 0.05rem;
}
.tp-week-edit-slot {
    min-width: 0;
    grid-column: 2;
    grid-row: 1;
}
.tp-week-edit-actions-col {
    grid-column: 3;
    grid-row: 1;
    align-self: start;
}
.tp-week-edit-payload {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    padding: 0.15rem 0.1rem;
    min-height: 1.6rem;
}
.tp-week-edit-item-draggable .tp-week-edit-skip,
.tp-week-edit-item-draggable .tp-week-edit-note-input {
    cursor: pointer;
}
.tp-week-edit-grip {
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: -0.12em;
    user-select: none;
    flex-shrink: 0;
    padding-top: 0.05rem;
}
.tp-week-edit-headline {
    font-size: 0.74rem;
    line-height: 1.35;
    color: var(--text-soft);
    word-break: break-word;
}
.tp-week-edit-rest {
    font-size: 0.72rem;
    color: var(--muted);
    font-style: italic;
    padding: 0.35rem 0.1rem;
    min-height: 1.6rem;
    display: flex;
    align-items: center;
}
.tp-week-edit-skip {
    font-size: 0.72rem;
    color: var(--text-soft);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}
.tp-week-edit-note-input {
    grid-column: 2 / -1;
    grid-row: 2;
    width: 100%;
    min-height: 2.5rem;
    font-size: 0.88rem;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    box-sizing: border-box;
}
.training-plan-week-edit-hint {
    margin-bottom: 0.25rem;
}
.training-plan-sync-hint {
    margin-bottom: 0.35rem;
}
.training-plan-session pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.76rem;
    line-height: 1.38;
    font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
    color: var(--text-soft);
}
.training-plan-session-content {
    font-size: 0.77rem;
    line-height: 1.42;
    font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
    color: var(--text-soft);
}
.training-plan-line { margin: 0 0 0.14rem; white-space: pre-wrap; word-break: break-word; }
.training-plan-line:last-child { margin-bottom: 0; }
.training-plan-line-title {
    font-weight: 700;
    margin-bottom: 0.2rem;
    color: var(--text);
}
.training-plan-line-block {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.18rem 0.38rem;
    margin-bottom: 0.18rem;
    background: color-mix(in srgb, var(--surface2) 78%, #1f2435);
}
.training-plan-line-block.nested {
    margin-left: 1.05rem;
    border-left-width: 3px;
}
.training-plan-line-detail {
    margin-left: 0.2rem;
    color: var(--text-soft);
}
.training-plan-line-detail-repeat {
    margin-left: 1.15rem;
}
.training-plan-line-bullet {
    margin-left: 1.15rem;
    color: var(--text-soft);
}
/* Default key label: same tier as body copy; phase-specific colors override below. */
.training-plan-key { font-weight: 700; color: var(--text-soft); }
.training-plan-line-block.k-warmup .training-plan-key { color: #22c55e; }
.training-plan-line-block.k-main .training-plan-key { color: #f97316; }
.training-plan-line-block.k-repeat .training-plan-key { color: #fb923c; }
.training-plan-line-block.k-recovery .training-plan-key { color: #06b6d4; }
.training-plan-line-block.k-cooldown .training-plan-key { color: #60a5fa; }

/* Hide toggles when detail view is visible */
.activity-detail:not([hidden]) ~ .section-toggles,
body.detail-open .section-toggles { display: none !important; }

/* Toast notification */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--surface2); color: var(--text);
    border: 1px solid var(--border);
    padding: 0.6rem 1.2rem; border-radius: 8px;
    font-size: 0.85rem; opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s; z-index: 300;
    display: flex; align-items: center; gap: 0.75rem;
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast-action {
    background: none; border: 1px solid var(--accent); color: var(--accent);
    padding: 0.2rem 0.6rem; border-radius: 5px;
    font-size: 0.8rem; cursor: pointer; white-space: nowrap;
}
.toast-action:hover { background: var(--accent); color: #fff; }

/* Responsive hardening: mobile-first overrides without changing desktop */
@media (max-width: 768px) {
    header { padding: 0.75rem 0.9rem; }
    .header-inner { padding: 0; gap: 0.6rem; align-items: flex-start; }
    .header-left h1 { font-size: 1.25rem; line-height: 1.2; }
    .header-left .subtitle { font-size: 0.72rem; }
    .settings-btn { padding: 0.35rem 0.5rem; font-size: 1rem; }

    main {
        padding: 0.9rem 0.75rem calc(1rem + env(safe-area-inset-bottom));
    }
    section { margin-bottom: 1rem; }

    .section-toggles {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.4rem;
        margin-bottom: 0.8rem;
    }
    .section-toggle { width: 100%; min-width: 0; text-align: center; padding: 0.42rem 0.55rem; font-size: 0.8rem; }

    .filter-row {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.55rem;
    }
    .filter-group,
    .filter-search,
    .filter-sort,
    .filter-actions {
        width: 100%;
        flex: 0 0 auto;
        min-width: 0;
    }
    .filter-actions label { display: none; }
    .filter-group label { font-size: 0.72rem; }
    .filter-group select,
    .filter-group input,
    .filter-group button {
        min-height: 38px;
        font-size: 0.84rem;
    }
    .sort-chips {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: visible !important;
        flex-wrap: wrap !important;
        gap: 0.35rem;
    }
    .sort-chip {
        flex: 1 1 calc(50% - 0.35rem);
        min-width: 0;
        text-align: center;
    }

    .stats-grid { grid-template-columns: 1fr; }
    .goals-grid { grid-template-columns: 1fr; }
    .training-plan-actions { gap: 0.42rem; }
    .training-plan-actions button { min-height: 38px; }

    .activity-list h2 { font-size: 1.05rem; }
    #activities { gap: 0.5rem; }

    .settings-panel { width: 100%; max-width: 100vw; }
    .settings-body { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }

    .modal-panel {
        width: min(94vw, 420px);
        max-height: min(90vh, 760px);
        overflow: auto;
    }
    .modal-body { padding-bottom: calc(0.95rem + env(safe-area-inset-bottom)); }
    .modal-body .goal-edit-row input,
    .modal-body .goal-edit-row select,
    .modal-body .goal-edit-row textarea {
        max-width: 100%;
        min-height: 38px;
    }

    .pace-analysis-wrap { height: 230px; }
    .pace-tab { font-size: 0.74rem; padding: 0.24rem 0.5rem; }
    .detail-chart-container canvas { max-height: 220px; }

    .mobile-step-list { display: flex; flex-direction: column; gap: 0.45rem; }
    .mobile-step-item {
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.45rem 0.55rem;
        background: rgba(255,255,255,0.01);
    }
    .mobile-step-title {
        font-size: 0.8rem;
        font-weight: 700;
        margin-bottom: 0.28rem;
        word-break: break-word;
        color: var(--text);
    }
    .mobile-step-meta {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.16rem;
        font-size: 0.76rem;
        color: var(--text);
        margin-bottom: 0.25rem;
    }
    .mobile-step-meta b { color: var(--muted); font-weight: 600; }
    .target-share {
        display: flex;
        gap: 0.3rem;
        flex-wrap: wrap;
        font-size: 0.68rem;
    }
}

@media (max-width: 480px) {
    .header-left h1 { font-size: 1.1rem; }
    .section-toggles { grid-template-columns: 1fr; }
    .section-toggle { font-size: 0.78rem; }
    .filter-group { flex: 1 1 100%; }
    .filter-sort { min-width: 0 !important; width: 100% !important; }
    .sort-chip { flex: 1 1 100%; }
    .chart-tabs { width: 100%; }
    .chart-tab { flex: 1 1 0; text-align: center; }
    .modal-panel {
        width: 96vw;
        border-radius: 10px;
    }
}

/* Hidden in-viewport layout for html2canvas (off-screen coords often fail to render) */
.activity-export-capture {
    position: fixed;
    left: 0;
    top: 0;
    z-index: -1;
    width: 800px;
    max-width: 800px;
    padding: 1rem;
    background: #0f1117;
    color: #aeb2bf;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}
.activity-export-capture .detail-header,
.activity-export-capture .detail-map,
.activity-export-capture .detail-chart-container {
    margin-bottom: 0.75rem;
}
.activity-export-capture .detail-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 0.5rem;
    margin: 0.75rem 0;
}
.activity-export-map-block .activity-export-map-img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 0 0 10px 10px;
}
