:root {
    --bg: #f6f7f9;            /* helle, freundliche Seitenfarbe */
    --surface: #ffffff;       /* Karten & Menue */
    --surface-2: #f1f3f6;     /* leichte Einfaerbung */
    --border: #e6e8ec;
    --text: #232831;
    --muted: #717784;
    --accent: #ff5c5c;        /* leichtes Rot */
    --accent-strong: #e23b3b; /* kraeftigeres Rot fuer Links/Hover */
    --accent-2: #e23b3b;
    --danger: #e5484d;
    --ok: #16a34a;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(20, 24, 31, .06), 0 6px 18px rgba(20, 24, 31, .05);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Topbar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 6px rgba(20, 24, 31, .05);
    position: sticky;
    top: 0;
    z-index: 200;
}
.brand { display: flex; align-items: center; flex: none; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 38px; display: block; }

/* Desktop-Nav */
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
    color: var(--muted);
    padding: 7px 12px;
    border-radius: 999px;
    font-weight: 600;
    white-space: nowrap;
}
.nav a:hover { color: var(--accent-strong); background: rgba(255, 92, 92, .1); text-decoration: none; }
.nav a.active { color: #fff; background: var(--accent); }

.user-area { display: flex; align-items: center; gap: 10px; flex: none; }
.hi { color: var(--muted); font-size: .9rem; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }
.user-chip:hover { text-decoration: none; color: var(--accent-strong); }

/* ---- Hamburger-Button (nur Mobile) ---- */
.burger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px; height: 40px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    margin-left: auto;
    flex: none;
}
.burger span {
    display: block; height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform .25s, opacity .25s;
}
.burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.burger.open span:nth-child(2) { opacity: 0; }
.burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Overlay hinter dem Menü */
.nav-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 190;
}
.nav-overlay.open { display: block; }

/* Mobile-only User-Zeile im Nav (versteckt auf Desktop) */
.nav-user-mobile { display: none; }

/* ---- Mobile: Responsive ---- */
@media (max-width: 767px) {
    .burger { display: flex; }
    .user-area { display: none; }

    /* Slide-in Menü von links */
    .nav {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(280px, 80vw);
        background: #fff;
        flex-direction: column;
        gap: 0;
        padding: 72px 12px 24px;
        box-shadow: 4px 0 24px rgba(0,0,0,.12);
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        z-index: 300;
        overflow-y: auto;
    }
    .nav.open { transform: translateX(0); }
    .nav a {
        padding: 13px 16px;
        border-radius: 12px;
        font-size: 1.05rem;
    }
    .nav-user-mobile {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin-top: auto;
        padding-top: 20px;
        border-top: 1px solid var(--border);
    }
    body.nav-open { overflow: hidden; }
}

/* ---- Avatare ---- */
.avatar { border-radius: 50%; object-fit: cover; display: inline-flex; vertical-align: middle; flex: none; }
.avatar-fallback { align-items: center; justify-content: center; color: #fff; font-weight: 700; line-height: 1; }

/* ---- Profil ---- */
.profile-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.profile-name { font-size: 1.4rem; font-weight: 800; }
.profile-facts { width: 100%; }
.profile-facts th { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 600; width: 40%; }
.avatar-input { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.avatar-preview { display: inline-flex; }
.avatar-actions { display: flex; flex-direction: column; gap: 8px; }
.cam-wrap { margin-top: 6px; }
.cam-wrap video, .cam-wrap canvas { width: 100%; max-width: 360px; aspect-ratio: 1/1; object-fit: cover; border-radius: 12px; background: #000; display: block; margin: 0 auto; }
.cam-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }

/* ---- Layout ---- */
.container { max-width: 960px; margin: 0 auto; padding: 24px; }
.container-wide { max-width: 1320px; }
.site-footer { text-align: center; color: var(--muted); padding: 32px; font-size: .85rem; }

h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 1.6rem; margin-top: 0; }
.muted { color: var(--muted); }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.stat { text-align: center; }
.stat .num { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.stat .num-sub { font-size: 1rem; color: var(--muted); font-weight: 600; }

/* ---- Dashboard-Uebersichtstabelle ---- */
.table-wrap { overflow-x: auto; }
.overview { min-width: 560px; }
.overview .num-col { text-align: right; white-space: nowrap; }
.overview tbody tr.me-row { background: rgba(255, 92, 92, .08); }
.overview tbody td { font-variant-numeric: tabular-nums; }
.overview tfoot td { border-top: 2px solid var(--border); border-bottom: none; }

/* ---- Zeitraum-Filter ---- */
.period-filter { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.period-btn {
    padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: .85rem;
    color: var(--muted); white-space: nowrap;
}
.period-btn:hover { text-decoration: none; color: var(--accent-strong); }
.period-btn.active { background: var(--accent); color: #fff; }
.period-btn.active:hover { color: #fff; }

/* Kalender-Tage im gewählten Zeitraum hervorgehoben */
.cal-cell.in-range { background: rgba(255, 92, 92, .08); }
.cal-cell.today.in-range { background: rgba(255, 92, 92, .14); }

/* ---- Dashboard: User-Kacheln nebeneinander ---- */
.user-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.user-tile {
    flex: 1 1 200px; text-align: left; cursor: pointer; color: var(--text);
    font: inherit; background: var(--surface);
    border: 1px solid var(--border); border-top: 3px solid var(--accent);
    border-radius: var(--radius); padding: 16px; transition: border-color .15s, box-shadow .15s;
}
.user-tile:hover { border-color: var(--accent); }
.user-tile.active { box-shadow: 0 0 0 2px var(--accent) inset; }
.user-tile h3 { margin: 0 0 12px; font-size: 1.1rem; }
.tile-head { display: flex; align-items: center; gap: 8px; }
.tile-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.tile-metrics .m-val { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.tile-metrics .m-lbl { color: var(--muted); font-size: .8rem; }
.user-tile .hint { margin-top: 12px; font-size: .75rem; color: var(--muted); }
.user-tile.active .hint { color: var(--accent); }

.user-detail { display: none; margin-top: 12px; }
.user-detail.open { display: block; }

/* ---- Druckansicht (Trainingsplan) ---- */
.print-month { display: none; }   /* nur beim Drucken sichtbar */
@media print {
    .print-month { display: inline; }
    @page { size: landscape; margin: 1cm; }
    body { background: #fff; color: #000; }
    .topbar, .site-footer, .no-print, .burger, .nav-overlay { display: none !important; }
    .container { max-width: none; margin: 0; padding: 0; }
    .card { background: #fff; border: none; box-shadow: none; padding: 0; margin: 0 0 8px; }
    h1, h2, h3 { color: #000; }
    a { color: #000; text-decoration: none; }

    .calendar { padding: 0; }
    .cal-grid { gap: 2px; }
    .cal-dow { color: #000; }
    .cal-cell {
        background: #fff; border: 1px solid #999; min-height: 90px;
        break-inside: avoid; page-break-inside: avoid;
    }
    .cal-cell.empty { border: none; }
    .cal-cell.today { box-shadow: none; border: 2px solid #000; }
    .cal-daynum { color: #000; }
    .cal-event {
        background: #fff; border: 1px solid #bbb; border-left-width: 4px !important;
        color: #000;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    .cal-event.done .cal-ev-title { color: #666; }
    .cal-ev-actions, .cal-ev-garmin { display: none !important; }
    .tag { border: 1px solid #999; color: #000; background: #fff; }
    .dot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---- Forms ---- */
.form-narrow { max-width: 380px; margin: 48px auto; }
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: .9rem; }
input, textarea, select {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
    display: inline-block;
    padding: 10px 16px;
    border: none;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    font-size: 1rem;
    box-shadow: 0 2px 6px rgba(255, 92, 92, .25);
}
.btn:hover { background: var(--accent-strong); text-decoration: none; }
.btn-block { width: 100%; }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent-strong); }
.btn-sm { padding: 5px 12px; font-size: .85rem; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; }
.alert-error { background: #fdecec; border: 1px solid #f5b5b5; color: #b42318; }
.alert-ok { background: #e9f7ef; border: 1px solid #aee0c2; color: #11703a; }

/* ---- Workouts ---- */
.workout { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-bottom: 1px solid var(--border); }
.workout:last-child { border-bottom: none; }
.workout.done .w-title { text-decoration: line-through; color: var(--muted); }
.w-body { flex: 1; }
.w-title { font-weight: 700; }
.w-meta { color: var(--muted); font-size: .85rem; }
.tag {
    display: inline-block; font-size: .7rem; text-transform: uppercase;
    letter-spacing: .04em; padding: 2px 8px; border-radius: 999px;
    background: var(--surface-2); color: var(--accent-2); font-weight: 700;
}

/* ---- Tabelle ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Chat ---- */
.chat-window {
    height: 50vh; overflow-y: auto; padding: 12px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 12px;
    display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 75%; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; }
.msg .who { font-size: .75rem; font-weight: 700; opacity: .8; margin-bottom: 2px; }
.msg .when { font-size: .65rem; opacity: .6; margin-top: 2px; }
.chat-form { display: flex; gap: 8px; align-items: flex-start; }
.chat-form input { flex: 1; }
.mention-wrap { position: relative; flex: 1; }
.mention-wrap input { width: 100%; }

/* @-Mention im Nachrichtentext */
.mention { background: rgba(255, 92, 92, .15); color: var(--accent-strong); font-weight: 700; padding: 0 3px; border-radius: 4px; }

/* Autocomplete-Box */
.mention-box {
    position: absolute; bottom: calc(100% + 4px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow); overflow: hidden; z-index: 50;
}
.mention-item { padding: 9px 12px; cursor: pointer; font-size: .95rem; }
.mention-item.active, .mention-item:hover { background: rgba(255, 92, 92, .1); }

/* Push-Button aktiv */
#pushBtn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.flex { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }

/* ---- Athleten-Auswahl (Workout fuer mehrere) ---- */
.for-users { grid-column: 1 / -1; }
.athlete-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.athlete-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 13px; border: 1px solid var(--border); border-radius: 999px;
    cursor: pointer; font-weight: 600; font-size: .9rem; background: #fff; user-select: none;
}
.athlete-chip input { width: auto; margin: 0; accent-color: var(--accent); }
.athlete-chip:has(input:checked) { border-color: var(--accent); background: rgba(255, 92, 92, .1); color: var(--accent-strong); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-right: 4px; }

/* ---- Freigaben ---- */
.share-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.share-row:last-child { border-bottom: none; }
.share-user { display: flex; align-items: center; gap: 10px; }
.share-name { font-weight: 700; }
.share-detail { font-weight: 400; color: var(--muted); font-size: .85rem; margin-left: 4px; }

/* ---- Pager (Seitennavigation) ---- */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.pager-info { color: var(--muted); font-size: .85rem; font-weight: 600; }

/* ---- Rangliste ---- */
.rank-list { display: flex; flex-direction: column; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid var(--border); }
.rank-row:last-child { border-bottom: none; }
.rank-row.winner { background: rgba(255, 212, 0, .12); border-radius: 10px; }
.rank-pos { width: 28px; text-align: center; font-weight: 800; font-size: 1.05rem; }
.rank-name { flex: 1; font-weight: 600; }
.rank-km { font-weight: 800; color: var(--accent-strong); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Admin-Aktionen ---- */
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-actions form { margin: 0; }
.tag-ok { background: #e9f7ef; color: #11703a; }
.user-search { margin-bottom: 8px; }
.shared-with-me { display: flex; flex-wrap: wrap; gap: 8px; }
.shared-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 5px; border: 1px solid var(--border); border-radius: 999px; font-weight: 600; font-size: .9rem; }

/* ---- Kalender ---- */
.calendar { padding: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-head { margin-bottom: 8px; }
.cal-dow { text-align: center; color: var(--muted); font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.cal-cell {
    min-height: 140px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px; overflow: hidden; cursor: pointer;
}
.cal-cell[data-date]:hover { border-color: var(--accent); }
.cal-cell.empty { background: transparent; border: none; }
.cal-cell.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.cal-daynum { font-size: 1.05rem; color: var(--text); font-weight: 700; margin-bottom: 6px; }
.cal-event {
    display: flex; align-items: center; gap: 5px;
    background: var(--surface); border-left: 4px solid var(--accent);
    border-radius: 5px; padding: 5px 7px; margin-bottom: 5px; font-size: .9rem;
}
.cal-event.done .cal-ev-title { text-decoration: line-through; opacity: .55; }
.cal-ev-user { display: none; }
.cal-ev-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev-actions { display: flex; gap: 2px; }
.cal-ev-actions form { margin: 0; }
.cal-ev-actions button {
    background: transparent; border: none; color: var(--muted); cursor: pointer;
    font-size: .8rem; line-height: 1; padding: 0 2px;
}
.cal-ev-actions button:hover { color: var(--text); }
.cal-ev-garmin { text-decoration: none; font-size: .8rem; }
.cal-ev-garmin:hover { text-decoration: none; }

@media (max-width: 767px) {
    /* Layout */
    .container, .container-wide { padding: 14px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .user-row { flex-direction: column; }
    .user-tile { flex: none; width: 100%; }

    /* Tabellen horizontal scrollbar */
    .table-wrap { -webkit-overflow-scrolling: touch; }

    /* Buttons grösser für Touch */
    .btn { padding: 12px 18px; font-size: 1rem; min-height: 44px; }
    .btn-sm { padding: 8px 14px; font-size: .9rem; min-height: 38px; }
    input, select, textarea { min-height: 44px; font-size: 1rem; }

    /* Formulare einspaltig */
    .for-users .athlete-picker { flex-direction: column; }
    .athlete-chip { width: 100%; }

    /* Kalender */
    .cal-grid { gap: 2px; }
    .cal-cell { min-height: 64px; padding: 3px; }
    .cal-daynum { font-size: .8rem; margin-bottom: 2px; }
    .cal-event { font-size: .65rem; padding: 2px 3px; }

    /* Chat */
    .chat-window { height: 55vh; }
    .msg { max-width: 88%; }

    /* Profile */
    .profile-head { flex-direction: column; text-align: center; }
    .avatar-input { flex-direction: column; align-items: flex-start; }

    /* Dashboard Kacheln */
    .tile-metrics { grid-template-columns: repeat(3, 1fr); }

    /* Modal */
    .modal { padding: 16px; }

    /* Karte */
    .map { height: 260px; }
}

/* ---- Popup / Modal (Kalender-Detail) ---- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, .6);
    display: none; align-items: center; justify-content: center;
    z-index: 100; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); width: 100%; max-width: 480px;
    max-height: 85vh; overflow-y: auto; padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 1.25rem; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 1.8rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-item {
    border-left: 4px solid var(--accent); background: var(--surface-2);
    border-radius: 6px; padding: 12px 14px; margin-bottom: 10px;
}
.modal-item:last-child { margin-bottom: 0; }
.modal-item.done .mi-title { text-decoration: line-through; opacity: .6; }
.modal-item .mi-title { font-weight: 700; font-size: 1.05rem; }
.modal-item .mi-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.modal-item .mi-desc { margin-top: 6px; }
.modal-item .mi-link { margin-top: 8px; }

/* ---- Karte & Charts ---- */
.map { height: 380px; border-radius: 8px; overflow: hidden; }
.chart { width: 100%; display: block; margin-bottom: 16px; }
.chart-label { color: var(--muted); font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.bar { height: 10px; border-radius: 999px; min-width: 2px; }
