/* ═══════════════════════════════════════════════════════════════════════
   MOBILE FIRST
   Die Anwendung wird überwiegend am Telefon benutzt. Basis sind deshalb die
   kleinen Bildschirme; Tablet und Desktop kommen als Erweiterung obendrauf.
   Wird nach style.css geladen und überschreibt sie gezielt.
   ═══════════════════════════════════════════════════════════════════════ */

html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }

/* Platz für die feste Navigationsleiste, inklusive Home-Indikator auf dem
   iPhone. Ohne das verdeckt die Leiste den letzten Eintrag jeder Seite. */
body.has-nav main { padding-bottom: calc(5.2rem + env(safe-area-inset-bottom)); }

main { padding: 0.9rem; max-width: 1100px; margin: 0 auto; }

/* Berührungsziele: alles Klickbare mindestens 44 px hoch. */
.btn, button, .chip, select, input[type=submit] { min-height: 44px; }

/* --- Kopfzeile -------------------------------------------------------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    padding-top: calc(0.7rem + env(safe-area-inset-top));
    position: sticky; top: 0; z-index: 30;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
}
.brand {
    font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.05rem;
    display: inline-flex; align-items: center; min-height: 44px;
}
.topnav { display: none; }           /* am Telefon übernimmt die untere Leiste */

/* --- Untere Navigationsleiste ---------------------------------------- */
.bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.15rem;
    padding: 0.5rem 0.2rem 0.45rem;
    min-height: 52px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.66rem;
    line-height: 1.1;
    border-top: 2px solid transparent;
}
.bottomnav a.is-active { color: var(--primary); border-top-color: var(--primary); }
.bn-ic { font-size: 1.25rem; line-height: 1; }
.bn-tx { white-space: nowrap; }

/* --- Tabellen: die grösste Schwachstelle auf schmalen Bildschirmen ---- */
.history, .review-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    font-size: 0.85rem;
}

/* --- Kacheln: Kennzahlen ---------------------------------------------- */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 0.5rem;
    margin: 0.9rem 0;
}
.stat {
    padding: 0.6rem 0.5rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
}
.stat-v { font-size: 1.05rem; font-weight: 700; }
.stat-l { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15rem; }

/* --- Zonenbalken ------------------------------------------------------ */
.zbar {
    display: flex; width: 100%; height: 12px;
    border-radius: 6px; overflow: hidden;
    background: var(--border);
    margin: 0.5rem 0;
}
.zbar-seg { display: block; height: 100%; }
.zone-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 0.35rem 0.8rem;
    margin: 0.6rem 0;
}
.zl { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; }
.zl-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.zl-k { font-weight: 700; min-width: 2.2rem; }
.zl-p { color: var(--text-muted); margin-left: auto; }
.zone-summary {
    padding: 0.9rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 1.2rem;
}
.zone-summary h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.small { font-size: 0.78rem; line-height: 1.5; }

/* --- Trainingsliste --------------------------------------------------- */
.range-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.range-chips .chip { text-decoration: none; display: inline-flex; align-items: center; }
.workout-list { display: flex; flex-direction: column; gap: 0.55rem; }
.workout {
    display: block;
    padding: 0.7rem 0.8rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 9px;
    text-decoration: none;
    color: var(--text);
}
.workout:active { background: var(--bg-card); }
.wo-head { display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; }
.wo-name { font-weight: 600; font-size: 0.95rem; }
.wo-date { font-size: 0.76rem; color: var(--text-muted); flex: none; }
.wo-meta {
    display: flex; flex-wrap: wrap; gap: 0.15rem 0.7rem;
    font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem;
}
.workout .zbar { height: 8px; margin: 0.5rem 0 0; }
.workout-detail h2 { font-size: 1rem; margin: 1.4rem 0 0.4rem; }

/* --- Verlaufsübersicht ------------------------------------------------ */
.search-wrap { position: sticky; top: 3.6rem; z-index: 20; padding: 0.5rem 0; background: var(--bg); }
#marker-search {
    width: 100%; padding: 0.7rem 0.9rem; min-height: 44px;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--bg-elev); color: var(--text); font-size: 1rem;
}
.mk-cat h3 { font-size: 0.9rem; margin: 1rem 0 0.4rem; color: var(--cat-color, var(--text)); }
.mk-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: 8px; overflow: hidden; }
.mk-row {
    display: flex; flex-direction: column; gap: 0.2rem;
    padding: 0.65rem 0.8rem; min-height: 44px;
    background: var(--bg-elev); text-decoration: none; color: var(--text);
}
.mk-row:active { background: var(--bg-card); }
.mk-row-name { font-size: 0.92rem; }
.mk-row-meta { display: flex; gap: 0.6rem; font-size: 0.75rem; color: var(--text-muted); }
.mk-row-n::after { content: " Werte"; }
.mk-row-last { margin-left: auto; }

/* --- Bestehende Bausteine schmal machen ------------------------------- */
@media (max-width: 767px) {
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.05rem; }
    .categories { grid-template-columns: 1fr; }
    .food-cols { grid-template-columns: 1fr; }
    .test-header { flex-direction: column; align-items: stretch; gap: 0.7rem; }
    .test-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; }
    .test-nav form { flex: 1 1 100%; }
    .test-nav select { width: 100%; }
    .test-nav .btn { flex: 1 1 auto; text-align: center; }
    .toc { display: flex; overflow-x: auto; gap: 0.4rem; padding-bottom: 0.4rem; }
    .toc-link { flex: none; }
    .filter-bar .chips { display: flex; overflow-x: auto; gap: 0.4rem; padding-bottom: 0.3rem; }
    .filter-bar .chip { flex: none; }
    .markers { grid-template-columns: 1fr; }
    .zone-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .wc-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid button { width: 100%; }
    .user-actions { flex-direction: column; align-items: stretch; }
    .user-actions form { width: 100%; }
    .user-actions input { max-width: none; flex: 1; }
    .review-actions { flex-direction: column; }
    .review-actions .btn { width: 100%; text-align: center; }
    .rec-block { padding: 0.9rem; }
}

/* --- Ab Tablet: Navigation nach oben, mehr Luft ----------------------- */
@media (min-width: 768px) {
    main { padding: 1.4rem; }
    body.has-nav main { padding-bottom: 2rem; }
    .bottomnav { display: none; }
    .topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
    .topnav a { text-decoration: none; color: var(--text-muted); font-size: 0.92rem; }
    .topnav a:hover { color: var(--text); }
    .topnav a.is-active { color: var(--primary); font-weight: 600; }
    .history, .review-table { display: table; white-space: normal; font-size: 0.9rem; }
    .mk-row { flex-direction: row; align-items: center; justify-content: space-between; }
    .mk-row-meta { flex: none; }
    .search-wrap { top: 4rem; }
}
