/* ========================================
   Grundlagen und Zurücksetzen
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4F46E5;
    --primary-dark: #4338CA;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --info: #3B82F6;
    --bg: #F3F4F6;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-light: #6B7280;
    --border: #E5E7EB;

    /* Layout-Maße zentral steuerbar */
    --container-max: 1500px;
    --container-pad: 32px;
    --card-pad: 28px;
    --gap: 24px;
    --section-gap: 28px;

    /* Kompatibilitäts-Aliase für ältere Regeln */
    --bg-secondary: var(--bg);
    --text-secondary: var(--text-light);
    --border-color: var(--border);
    --primary-color: var(--primary);
}

body {
    min-height: 100vh;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }

/* ========================================
   Login
   ======================================== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.login-container { width: 100%; max-width: 420px; }

.login-card {
    padding: 44px 34px;
    border-radius: 20px;
    background: var(--card-bg);
    box-shadow: 0 20px 60px rgba(31, 41, 55, 0.2);
}

.login-card h1 { margin-bottom: 8px; text-align: center; font-size: 28px; }
.subtitle { margin-bottom: 30px; color: var(--text-light); text-align: center; }

/* ========================================
   Navigation und Layout
   ======================================== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px var(--container-pad);
    background: var(--card-bg);
    box-shadow: 0 2px 10px rgba(31, 41, 55, 0.06);
}

.navbar-brand { font-size: 19px; font-weight: 700; }
.navbar-menu { display: flex; flex-wrap: wrap; gap: 10px; }
.nav-link { padding: 8px 14px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; }
.nav-link:hover, .nav-link.active { background: var(--bg); }

.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 32px var(--container-pad);
}

.dashboard-hero { margin-bottom: 32px; }
.dashboard-hero h1 { margin-bottom: 4px; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.hero-subtitle { color: var(--text-light); }
.hero-date { margin-top: 4px; color: var(--text-light); font-size: 13px; }

.content-grid { display: grid; gap: var(--gap); }
@media (min-width: 900px) {
    .content-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); align-items: start; }
}

/* ========================================
   Karten und Überschriften
   Alle Karten haben Standardabstand nach unten.
   ======================================== */
.card, .form-card, .chart-card, .progress-card, .health-card {
    margin-bottom: var(--section-gap);
    padding: var(--card-pad);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(31, 41, 55, 0.1);
}

/* Nur Karten INNERHALB eines Grids brauchen keinen eigenen
   Abstand, da dort das gap greift. */
.content-grid > .card,
.content-grid > .form-card,
.content-grid > .chart-card,
.content-grid > .progress-card,
.health-grid > .health-card,
.stats-grid > .card {
    margin-bottom: 0;
}

/* Letzte Karte im Container braucht keinen Abstand mehr */
.container > :last-child { margin-bottom: 0; }

.card h3 { margin-bottom: 16px; color: var(--text-light); font-size: 16px; }
.section-heading { margin-bottom: 14px; font-size: 18px; }
.section-heading-spaced { margin: 32px 0 16px; font-size: 18px; }
.section-rule { height: 1px; margin: 28px 0; border: 0; background: var(--border); }
.icon-disc { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; background: #EEF2FF; color: var(--primary); }

/* ========================================
   Statistiken
   ======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--gap);
    margin-bottom: var(--section-gap);
}
.stat-card { padding: 24px 26px; border-radius: 16px; background: var(--card-bg); box-shadow: 0 1px 3px rgba(31, 41, 55, 0.1); }
.stat-label { margin-bottom: 6px; color: var(--text-light); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-value-sm { font-size: 20px; }
.stats-hint { margin: -14px 0 24px; color: #9CA3AF; font-size: 12px; text-align: right; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* ========================================
   Gesundheitskarten
   ======================================== */
.health-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
    align-items: stretch;
    margin-bottom: var(--section-gap);
}
@media (min-width: 700px) { .health-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .health-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.health-grid .health-card { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.health-card .card-kicker { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.health-card .card-kicker span:last-child { white-space: nowrap; font-size: .85rem; opacity: .7; }
.health-reading, .health-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: .6rem; }
.health-reading strong { font-size: 1.6rem; line-height: 1.1; }
.health-meta b { font-size: 1.1rem; }
.health-meta small { font-weight: 500; opacity: .7; }
.activity-values { display: flex; flex-wrap: wrap; gap: 1.75rem; }
.activity-values > div { display: flex; align-items: baseline; gap: .4rem; }
.activity-values strong { font-size: 1.6rem; line-height: 1.1; }
.activity-values span { opacity: .75; font-size: .9rem; }
.health-card .empty-state { padding: 0; opacity: .6; font-size: .9rem; text-align: left; }
.empty-state { padding: 28px 14px; color: var(--text-light); text-align: center; }

.health-form-toggle { margin-bottom: 1.5rem; }
.health-form-toggle .btn { display: inline-flex; align-items: center; gap: .5rem; font-size: 1rem; }
.health-form-toggle .btn:disabled { opacity: .65; cursor: not-allowed; }
.evening-only-fields { transition: opacity .25s; }
.evening-only-fields.hidden { display: none; }

/* ========================================
   Badges und Fortschritt
   ======================================== */
.badge { display: inline-block; margin-left: 6px; padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-info { background: #DBEAFE; color: #1E40AF; }
.badge-muted { background: var(--bg); color: var(--text-light); }

.progress-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.progress-target { color: var(--text-light); font-size: 13px; }
.progress-bar-container { height: 20px; margin-bottom: 14px; overflow: hidden; border-radius: 20px; background: var(--border); }
.progress-bar { height: 100%; border-radius: 20px; background: linear-gradient(90deg, var(--primary), var(--success)); transition: width .5s ease; }
.progress-text { color: var(--text-light); font-weight: 600; text-align: center; }

/* ========================================
   Formulare
   ======================================== */
.form-group { margin-bottom: 22px; }
.form-group:last-of-type { margin-bottom: 0; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-bottom: 22px; }
.form-row:last-of-type { margin-bottom: 0; }
.form-row .form-group { margin-bottom: 0; }
.input-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
label, .field-label { display: block; margin-bottom: 8px; color: var(--text-light); font-size: 14px; font-weight: 500; }
input, select, textarea {
    width: 100%;
    padding: 13px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 16px;
    transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.slot-radios, .radio-row { display: flex; flex-wrap: wrap; gap: 14px; }
.radio-inline, .radio-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-weight: 400; }
.radio-inline input, .radio-label input { width: auto; }
.form-hint { margin-top: 6px; color: var(--text-light); font-size: 12px; }


/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 12px 22px;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    transition: transform .1s, background .2s, box-shadow .2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    min-height: 22px;
    padding: 5px 10px;
    border: 1.5px solid var(--primary);
    background: #fff;
    color: var(--primary);
    font-size: 12px;
}
.btn-secondary:hover { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-block { width: 100%; margin-top: 24px; }
.btn-sm, .btn-small { min-height: 40px; padding: 8px 16px; font-size: 13px; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; min-height: 38px; padding: 0; border-radius: 8px; background: var(--card-bg); text-decoration: none; font-size: 16px; }
.edit-form .form-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }

/* Page-Header-Buttons bewusst kompakter */
.page-header-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.page-header-actions .btn { min-height: 36px; padding: 6px 14px; font-size: 13px; }

/* ========================================
   Hinweise und Trennlinie
   ======================================== */
.alert { margin-bottom: 20px; padding: 15px 18px; border: 1px solid transparent; border-radius: 10px; }
.alert-danger { background: #FEE2E2; color: #991B1B; border-color: #FECACA; }
.alert-success { background: #D1FAE5; color: #065F46; border-color: #A7F3D0; }
.alert-info { background: #DBEAFE; color: #1E40AF; border-color: #BFDBFE; }

.divider { position: relative; margin: 24px 0 18px; color: var(--text-light); font-size: 13px; font-weight: 600; text-align: center; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: 30%; height: 1px; background: var(--border); }
.divider::before { left: 0; }
.divider::after { right: 0; }

/* ========================================
   Diagramm
   ======================================== */
.chart-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.tab-btn {
    min-height: 44px;
    padding: 8px 18px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.tab-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

.chart-range-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 22px; }
.chart-range-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: inherit;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.chart-range-btn:hover { background: rgba(79, 70, 229, .08); }
.chart-range-btn.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chart-range-info { margin-top: .7rem; font-size: .85rem; opacity: .7; }

.chart-wrapper { position: relative; height: 380px; margin-top: 8px; }
.chart-subheading { margin-bottom: 16px; color: var(--text-light); font-size: 14px; }
.chart-legend-note { margin-top: 14px; color: var(--text-light); font-size: 12px; }
#weightChart { max-height: 380px; }

/* ========================================
   Tabellen und Benutzerverwaltung
   ======================================== */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; margin-top: 18px; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { position: sticky; top: 0; background: var(--bg-secondary); color: var(--text-secondary); font-weight: 600; }
.data-table tbody tr:hover { background: var(--bg-secondary); }

.user-list { display: flex; flex-direction: column; gap: 14px; }
.user-card { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; padding: 20px 24px; border-radius: 12px; background: var(--card-bg); }
.user-info { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.user-actions { display: flex; gap: 10px; }

.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 28px; }
.back-link { color: var(--primary); text-decoration: none; font-size: 14px; }
.back-link:hover { text-decoration: underline; }

/* ========================================
   Offline-Modus und iOS-Sicherheit
   ======================================== */
.offline-banner {
    display: none;
    position: fixed;
    top: 0; right: 0; left: 0;
    z-index: 999;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--danger);
    color: #fff;
    text-align: center;
    font-size: 14px;
}
body.is-offline .offline-banner { display: block; }
body.is-offline { padding-top: 44px; }
.dashboard { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

/* ========================================
   Mobile Anpassungen
   ======================================== */
@media (max-width: 900px) {
    :root { --container-pad: 24px; --card-pad: 24px; --gap: 20px; --section-gap: 22px; }
}

@media (max-width: 700px) {
    .form-row, .input-pair { grid-template-columns: 1fr; }
    .chart-wrapper { height: 300px; }
    #weightChart { max-height: 300px; }
}

@media (max-width: 600px) {
    :root { --container-pad: 16px; --card-pad: 18px; --gap: 16px; --section-gap: 18px; }

    .navbar { padding: 14px 16px; }
    .navbar-menu { width: 100%; justify-content: space-around; }
    .nav-link { padding: 6px 10px; font-size: 12px; }

    h1 { font-size: 22px; }

    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-card { padding: 16px; }
    .stat-value { font-size: 22px; }

    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 6px; }

    .page-header { align-items: flex-start; }
    .page-header-actions { width: 100%; }
    .page-header-actions .btn { min-height: 32px; padding: 5px 12px; font-size: 12px; }

    .chart-range-btn { flex: 1 1 auto; min-width: 0; padding: 0 12px; }
}

/* ========================================
   Blockabstände zwischen Hauptbereichen
   ======================================== */
.content-grid,
.health-grid,
.stats-grid,
.progress-card,
.chart-card,
.form-card,
.dashboard-hero {
    margin-bottom: var(--section-gap);
}

/* Karten in Grids: Abstand kommt vom gap */
.health-grid > .card,
.health-grid > .health-card,
.content-grid > .card,
.content-grid > .form-card,
.content-grid > .chart-card,
.content-grid > .progress-card,
.stats-grid > .card,
.stats-grid > .stat-card {
    margin-bottom: 0;
}

/* Überschrift vor einer Kartengruppe */
.health-grid + .section-heading,
.content-grid + .section-heading,
.section-heading-spaced {
    margin-top: var(--section-gap);
}



.filter-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

/* ========================================
   Pagination (details.php)
   ======================================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 24px 0;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: background .2s, color .2s, border-color .2s;
}

.pagination a:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.pagination .active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    cursor: default;
}

.pagination .disabled {
    opacity: .4;
    pointer-events: none;
    cursor: not-allowed;
}

.pagination .dots {
    border: none;
    background: transparent;
    min-width: auto;
    padding: 0 4px;
    color: var(--text-light);
}

.pagination-info {
    text-align: center;
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

@media (max-width: 600px) {
    .pagination a,
    .pagination span {
        min-width: 36px;
        min-height: 36px;
        padding: 4px 8px;
        font-size: 13px;
    }
}

/* ========================================
   Checkbox im Login-Formular
   ======================================== */
.form-group-check {
    margin-bottom: 18px;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    min-height: 32px;
}

.check-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.check-label input[type="checkbox"]:disabled {
    cursor: not-allowed;
}

.check-label input[type="checkbox"]:disabled + span {
    opacity: .5;
}

/* Letzte Messungen: 4 Kacheln pro Reihe */
.health-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 24px;
}

/* Tablet: 2 Kacheln pro Reihe */
@media (max-width: 1100px) {
    .health-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Handy: 1 Kachel pro Reihe */
@media (max-width: 640px) {
    .health-grid {
        grid-template-columns: 1fr;
    }
}