: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; }
.grid tr.is-today { outline: 2px solid var(--primary); outline-offset: -2px; }
.grid tr.type-U { background: #fffbea; }
.grid tr.type-F { background: #eef6ff; }
.grid tr.type-K { background: #fff1f1; }
.grid tr.type-P { background: #f3f0ff; }

/* Zukünftige Tage (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; }

.grid .notes { color: var(--muted); }
.grid .empty { text-align: center; color: var(--muted); padding: 1.5rem; }

.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; }

.row-actions { display: flex; gap: 0.4rem; align-items: center; }
.row-actions a, .link-btn {
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.95rem;
}

.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-Zeile beim Anspringen kurz hervorheben. */
:target.is-today, tr:target { animation: target-flash 1.4s ease-out 1; }
@keyframes target-flash {
    0% { background-color: #fde68a; }
    100% { background-color: transparent; }
}

/* --- Ü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; }
