:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #e2e6ec;
    --text: #1f2933;
    --muted: #6b7280;
    --primary: #2563eb;
    --pos: #15803d;
    --neg: #b91c1c;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    background: #111827;
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    color: #cbd5e1;
    font-size: 0.9rem;
}
.topnav .user { color: #94a3b8; }
.topnav a { color: #fff; text-decoration: none; }
.topnav a:hover { text-decoration: underline; }

.login-card { max-width: 380px; margin: 3rem auto; }
.login-card .checkbox { display: flex; align-items: center; gap: 0.4rem; font-weight: 400; margin-top: 0.8rem; }
.login-card .checkbox input { width: auto; }

.container {
    max-width: 1180px;
    margin: 1.5rem auto;
    padding: 0 1.25rem;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

h1 { font-size: 1.6rem; margin: 0; }

.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.btn {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin: 1.25rem 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem 1.25rem;
}

.card h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }

dl { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 1rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.table-title { margin: 1.5rem 0 0.5rem; }

.grid {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    font-size: 0.88rem;
}

.grid th, .grid td { padding: 0.5rem 0.65rem; text-align: left; border-bottom: 1px solid var(--border); }
.grid th { background: #f0f3f7; font-weight: 600; }
.grid td { font-variant-numeric: tabular-nums; }

/* Zukünftige Zeilen (Prognose): gedämpft, kursiv und mit Streifenmuster abgesetzt. */
.grid tr.is-future td {
    color: var(--muted);
    font-style: italic;
    background-image: repeating-linear-gradient(
        135deg,
        rgba(37, 99, 235, 0.05),
        rgba(37, 99, 235, 0.05) 7px,
        transparent 7px,
        transparent 14px
    );
}
.grid tr.is-future td:first-child { border-left: 3px solid var(--primary); }

.forecast-tag {
    font-style: normal;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--primary);
    background: #e0e9ff;
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    vertical-align: middle;
}
.forecast-val { color: var(--primary); white-space: nowrap; }

.badge {
    display: inline-block;
    min-width: 1.5rem;
    text-align: center;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.78rem;
    background: #e5e7eb;
}
.badge-N { background: #dbeafe; }
.badge-P { background: #ddd6fe; }
.badge-U { background: #fde68a; }
.badge-K { background: #fecaca; }
.badge-F { background: #bfdbfe; }

/* --- Tagesübersicht: Karten-/Listenansicht --- */

.list-head {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin: 1.5rem 0 0.6rem;
}
.list-head .table-title { margin: 0; }
.list-count {
    font-size: 0.82rem;
    color: var(--muted);
    background: #eef1f5;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
}

/* Monatsgruppe: aufklappbarer Abschnitt (<details>/<summary>). */
.month-group { margin-bottom: 0.6rem; }
.month-summary {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem 0.9rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.month-summary::-webkit-details-marker { display: none; }
.month-summary::marker { content: ''; }
.month-summary:hover { background: #f7f9fc; }
.month-group[open] > .month-summary {
    border-radius: 10px 10px 0 0;
    border-bottom-color: transparent;
}
.month-chevron {
    color: var(--muted);
    font-size: 0.8rem;
    transition: transform 0.15s ease;
}
.month-group[open] > .month-summary .month-chevron { transform: rotate(90deg); }
.month-name { font-weight: 700; font-size: 1rem; }
.month-count { color: var(--muted); font-size: 0.83rem; }
.month-meta {
    margin-left: auto;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    font-size: 0.83rem;
    color: var(--muted);
}
.month-balance { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Innenliegende Tagesliste an die Gruppen-Überschrift anschließen. */
.month-group > .day-list {
    margin-bottom: 0;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
}

.day-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.day-card {
    /* Akzentfarbe je Tagestyp – Standard (Arbeitstag) bleibt neutral. */
    --accent: #cbd5e1;
    display: grid;
    grid-template-columns: 3.25rem minmax(0, 1fr) auto auto;
    grid-template-areas: "date main stats actions";
    align-items: center;
    gap: 0.5rem 1.1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    padding: 0.65rem 0.9rem;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.day-card:hover { box-shadow: 0 3px 12px rgba(15, 23, 42, 0.09); }

.day-card.type-P { --accent: #7c3aed; }
.day-card.type-U { --accent: #d97706; }
.day-card.type-K { --accent: #dc2626; }
.day-card.type-F { --accent: #0891b2; }

/* Datums-Kästchen (Wochentag / Tag / Monat) als kompakter "Avatar". */
.dc-date {
    grid-area: date;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.15;
    padding: 0.25rem 0;
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 18%, #fff);
}
.dc-dow {
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.dc-day { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dc-mon { font-size: 0.64rem; color: var(--muted); }
.day-card.is-weekend .dc-dow { color: var(--neg); }

.day-card.is-missed {
    --accent: #f59e0b;
    background: color-mix(in srgb, #f59e0b 6%, var(--card));
    border-left-width: 5px;
    box-shadow: 0 0 0 1px color-mix(in srgb, #f59e0b 30%, transparent);
}
.day-card.is-missed:hover {
    box-shadow: 0 3px 12px rgba(245, 158, 11, 0.25), 0 0 0 1px color-mix(in srgb, #f59e0b 40%, transparent);
}
.missed-tag {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #92400e;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    padding: 0.08rem 0.4rem;
    border-radius: 4px;
}

.dc-main { grid-area: main; min-width: 0; }
.dc-headline { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.dc-type { font-weight: 600; }
.dc-today {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #fff;
    background: var(--primary);
    padding: 0.08rem 0.4rem;
    border-radius: 4px;
}
.dc-sub {
    margin-top: 0.2rem;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.dc-sub .sep { opacity: 0.45; }
.dc-times { font-variant-numeric: tabular-nums; color: var(--text); }
.dc-notes { font-style: italic; }

.dc-stats { grid-area: stats; display: flex; gap: 1.4rem; }
.dc-stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.dc-stat-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dc-stat-lbl {
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.dc-actions { grid-area: actions; display: flex; gap: 0.2rem; align-items: center; }
.dc-actions a, .dc-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 7px;
    border: none;
    background: none;
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.12s ease, color 0.12s ease;
}
.dc-actions a:hover { background: #eef2ff; color: var(--primary); }
.dc-actions button:hover { background: #fef2f2; color: var(--neg); }

/* Heute hervorheben. */
.day-card.is-today {
    border-color: var(--primary);
    border-left-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

/* Zukünftige Tage (Prognose): gedämpft und mit Streifenmuster. */
.day-card.is-future {
    background-image: repeating-linear-gradient(
        135deg,
        rgba(37, 99, 235, 0.045),
        rgba(37, 99, 235, 0.045) 7px,
        transparent 7px,
        transparent 14px
    );
}
.day-card.is-future .dc-type,
.day-card.is-future .dc-sub { font-style: italic; }
.day-card.is-future .dc-stat-val { color: var(--muted); font-weight: 600; }

.day-empty {
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 1.75rem;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 720px) {
    .day-card {
        grid-template-columns: 3.25rem minmax(0, 1fr) auto;
        grid-template-areas:
            "date main actions"
            "date stats stats";
        row-gap: 0.55rem;
    }
    .dc-stats {
        justify-content: space-between;
        gap: 0.5rem;
        padding-top: 0.55rem;
        border-top: 1px solid var(--border);
    }
    .dc-stat { align-items: flex-start; }
    .dc-actions { align-self: start; }
    .month-summary { flex-wrap: wrap; gap: 0.4rem 0.55rem; }
    .month-meta-lbl { display: none; }
}

.form-card { max-width: 520px; }
.form-card label { display: block; font-weight: 600; margin: 0.7rem 0 0.25rem; }
.form-card input, .form-card select, .form-card textarea {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
}
.form-actions { margin-top: 1.1rem; }

.flash {
    padding: 0.7rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-danger { background: #fee2e2; color: #991b1b; }

.legend { color: var(--muted); font-size: 0.85rem; margin-top: 1rem; }
.legend code { background: #eef1f5; padding: 0.05rem 0.3rem; border-radius: 4px; }

/* Springt zum heutigen Tag bzw. wieder nach oben. */
.floating-nav {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 50;
}
.fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.55rem 1rem;
    border: none;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
}
.fab:hover { filter: brightness(1.08); }
.fab-top { background: #374151; }

/* Heute-Karte beim Anspringen kurz hervorheben. */
.day-card:target { animation: target-flash 1.4s ease-out 1; }
@keyframes target-flash {
    0% { background-color: #fde68a; }
    100% { background-color: var(--card); }
}

/* --- Überstunden-Analyse --- */

/* Senkrechtes Balkendiagramm: Saldo je Monatsende. */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    height: 220px;
    padding: 1rem 1.1rem 0;
    margin: 0.5rem 0 1.25rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow-x: auto;
}
.chart-col {
    flex: 1 1 0;
    min-width: 38px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}
.chart-bar-wrap {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}
.chart-value {
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    margin-bottom: 0.2rem;
}
.chart-bar {
    width: 60%;
    min-height: 2px;
    border-radius: 4px 4px 0 0;
    background: var(--primary);
    transition: height 0.2s ease;
}
.chart-bar.pos { background: var(--pos); }
.chart-bar.neg { background: var(--neg); }
.chart-col.is-forecast .chart-bar {
    opacity: 0.55;
    background-image: repeating-linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.45),
        rgba(255, 255, 255, 0.45) 4px,
        transparent 4px,
        transparent 8px
    );
}
.chart-col.is-forecast .chart-value { font-style: italic; color: var(--muted); }
.chart-label {
    margin-top: 0.35rem;
    font-size: 0.72rem;
    color: var(--muted);
}

/* Waagerechte Balken: Verteilung der Überstunden nach Alter. */
.grid .bar-col { width: 40%; vertical-align: middle; }
.hbar-track {
    background: #eef1f5;
    border-radius: 999px;
    height: 0.7rem;
    overflow: hidden;
}
.hbar {
    height: 100%;
    min-width: 2px;
    background: var(--primary);
    border-radius: 999px;
}

.empty-note {
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    color: var(--muted);
    text-align: center;
}

/* Slider zur Wahl des Stichtags für die Altersbetrachtung. */
.age-explorer { margin: 0.5rem 0 1rem; }
.age-slider {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
}
.age-slider-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}
.age-slider-head label { color: var(--muted); }
.age-ref-label { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.age-slider input[type="range"] { width: 100%; accent-color: var(--primary); cursor: pointer; }
.age-slider-ends {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 0.25rem;
}
.age-summary {
    grid-template-columns: 1fr auto;
    max-width: 420px;
    margin-bottom: 1rem;
}
[hidden] { display: none !important; }
