/* ============================================================
   timedb · Zeitauswertung - Design System
   Clean & simple: white background, system (San Francisco) font stack,
   flat surfaces. b-net green as the single accent. No web-font dependency.
   ============================================================ */

:root {
    --bg:        #ffffff;
    --card:      #ffffff;
    --panel:     #fafafa;
    --sidebar:   #fafafa;

    --ink:       #1d1d1f;
    --muted:     #6e6e73;
    --faint:     #8e8e93;

    --line:      #e5e5e7;
    --line-soft: #ececee;

    --green:      #7a9a2e;
    --green-ink:  #5f8f3a;
    --green-soft: #eef4dd;
    --green-tint: #f3f7e8;

    --tan:        #cf9a45;
    --feast:      #d9c48e;
    --terra:      #c9524a;
    --terra-d:    #b23b34;
    --terra-soft: #fdeceb;
    --purple:     #9b6fb0;
    --sun-fill:   #c5a9cc;
    --night:      #5b67c0;
    --vac:        #c4cdd6;

    --radius:  14px;
    --radius-lg: 18px;
    --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- base ---------- */
/* Globaler Reset (ersetzt Bootstraps entfernten Reset) - border-box verhindert,
   dass width:100% durch Padding/Border überläuft (Ursache für unsymmetrische Felder). */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(122, 154, 46, .16); }

.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* Einheitlicher Fokus-Stil für alle Eingabefelder (kein dunkler UA-Umriss) */
input:focus { outline: none; }
.emp-search input:focus,
.rp-custom input:focus,
.range-btn:focus-visible {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(122, 154, 46, .15);
}

/* ---------- app shell ---------- */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.topbar-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.topbar-brand img { width: 26px; height: 26px; border-radius: 6px; }
.topbar-brand .name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.topbar-brand .divider { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.topbar-brand .tenant { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: 14px; position: relative; }

.user-chip { display: flex; align-items: center; gap: 9px; line-height: 1.15; }
.user-chip .who { font-size: 12.5px; font-weight: 600; }
.user-chip .role { font-size: 11px; color: var(--faint); }

.avatar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    background: #eef0e6;
    color: var(--green);
}
.avatar.sm { width: 32px; height: 32px; border-radius: 50%; font-size: 12px; }

.btn-ghost {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    border-radius: 9px;
    padding: 7px 12px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: inherit;
}
.btn-ghost:hover { color: var(--ink); background: var(--panel); }

.btn-solid {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--green);
    color: #fff;
    border: 0;
    border-radius: 9px;
    padding: 9px 15px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn-solid:hover { filter: brightness(.96); }

/* ---------- range picker ---------- */
.range-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 7px 12px;
    font-size: 12.5px;
    color: var(--ink);
    cursor: pointer;
    font-family: inherit;
}
.range-btn:hover { background: var(--panel); }
.range-btn .lbl { color: var(--faint); }
.range-btn .val { font-weight: 600; }

/* Wrapper, damit das Menü direkt unter dem Zeitraum-Button ankert (nicht am rechten Rand). */
.range-wrap { position: relative; }

.range-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: auto;
    width: 300px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 16px 40px -14px rgba(0,0,0,.22);
    padding: 10px;
    z-index: 1050;
}

.range-menu .head {
    font-size: 10.5px;
    letter-spacing: .07em;
    font-weight: 700;
    color: var(--faint);
    padding: 4px 8px 8px;
}

.rp-preset {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
}
.rp-preset:hover { background: var(--panel); }
.rp-preset.active { background: var(--green-soft); color: var(--green-ink); font-weight: 600; }
.rp-preset .tag { color: var(--faint); font-size: 11px; }

.rp-custom {
    border-top: 1px solid var(--line);
    margin-top: 8px;
    padding-top: 10px;
    display: flex;
    gap: 8px;
}
.rp-custom label { font-size: 10px; color: var(--faint); display: block; margin-bottom: 3px; }
.rp-custom .fld { flex: 1 1 0; min-width: 0; }
.rp-custom input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12px;
    color: var(--ink);
    color-scheme: light;
    font-family: inherit;
}

/* ---------- workspace ---------- */
.workspace { flex: 1; display: flex; align-items: stretch; min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar {
    width: 260px;
    flex: 0 0 260px;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
    padding: 16px 12px;
    overflow-y: auto;
}

.emp-search { position: relative; margin-bottom: 12px; }
.emp-search input {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 9px;
    padding: 9px 12px 9px 32px;
    font-size: 13px;
    font-family: inherit;
    color: var(--ink);
}
.emp-search .icon { position: absolute; left: 11px; top: 8px; color: var(--faint); font-size: 14px; }

.emp-count { font-size: 10.5px; letter-spacing: .07em; font-weight: 700; color: var(--faint); padding: 2px 6px 8px; }

.emp-list { display: flex; flex-direction: column; gap: 1px; }

.emp-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 0 9px 9px 0;
    cursor: pointer;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.emp-row:hover { background: #f2f2f4; }
.emp-row.active { border-left-color: var(--green); background: var(--green-tint); }

.emp-row .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: 12px; background: #ececee; color: var(--muted); }
.emp-row.active .avatar { background: var(--green); color: #fff; }

.emp-row .who { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.emp-row .nm { display: block; max-width: 100%; font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emp-row .pnr { display: block; font-size: 11px; color: var(--faint); font-family: var(--mono); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: #d2d2d7; }
.status-dot.ok  { background: var(--green); }
.status-dot.warn{ background: var(--tan); }
.status-dot.bad { background: var(--terra); }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; background: var(--bg); padding: 22px 26px 40px; overflow-x: auto; }
.main-empty { color: var(--faint); font-size: 14px; padding: 40px 4px; }

.emp-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.emp-header .eyebrow { font-size: 10.5px; letter-spacing: .08em; font-weight: 700; color: var(--faint); margin-bottom: 5px; }
.emp-header .id { display: flex; align-items: center; gap: 12px; }
.emp-header .avatar { width: 44px; height: 44px; border-radius: 13px; font-size: 16px; background: var(--green); color: #fff; font-weight: 700; }
.emp-header .nm { font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.emp-header .sub { font-size: 13px; color: var(--muted); margin-top: 3px; }

.tabs { display: inline-flex; background: #f0f0f2; border-radius: 10px; padding: 3px; }
.tab { padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; border: 0; background: none; font-family: inherit; }
.tab.active { background: #fff; font-weight: 600; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.pane.hidden { display: none; }

/* ---------- cards ---------- */
.card-soft { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-sub { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.placeholder-note { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 14px; }
.kpi {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.kpi.accent-green { border-left: 3px solid var(--green); }
.kpi.accent-terra { border-left: 3px solid var(--terra); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.kpi-row { display: flex; align-items: baseline; gap: 10px; }
.kpi-value { font-family: var(--mono); font-size: 28px; font-weight: 600; letter-spacing: -.02em; color: var(--ink); white-space: nowrap; }
.kpi-value.pos { color: var(--green-ink); }
.kpi-value.neg { color: var(--terra); }
.kpi-value.skeleton { color: var(--faint); opacity: .5; }
.kpi-pill { font-size: 12px; font-weight: 600; color: var(--green-ink); background: var(--green-soft); padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.kpi-pill.pill-neg { color: var(--terra-d); background: var(--terra-soft); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 8px; }
.kpi-bar { display: flex; height: 8px; border-radius: 5px; overflow: hidden; margin-top: 12px; background: #eeeeef; }
.kpi-bar .seg.base { background: var(--green); }
.kpi-bar .seg.over { background: #c6d97f; }
.kpi-barlabels { display: flex; justify-content: space-between; margin-top: 7px; font-size: 11.5px; font-family: var(--mono); color: var(--muted); }
@media (max-width: 900px) { .kpi-grid { grid-template-columns: 1fr; } }

/* ---------- adaptive heatmap ---------- */
.heat-body { margin-top: 14px; }

/* month calendar */
.cal-wrap { max-width: 620px; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-weekdays span { text-align: center; font-size: 10px; font-weight: 700; color: var(--faint); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
    aspect-ratio: 1.7;
    border-radius: 7px;
    padding: 6px 7px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid rgba(0, 0, 0, .04);
    color: #4a4636;
    min-width: 0;
}
.cal-cell.empty { background: transparent !important; border: 0; }
.cal-d { font-size: 12px; font-weight: 700; }
.cal-h { font-size: 11px; font-family: var(--mono); opacity: .9; white-space: nowrap; overflow: hidden; }

/* contribution strip */
.strip-labels { display: flex; gap: 3px; margin-bottom: 5px; }
.strip-lbl { flex: 1 1 0; min-width: 0; max-width: 60px; font-size: 9.5px; color: var(--faint); font-family: var(--mono); white-space: nowrap; }
.strip-grid { display: flex; gap: 3px; }
/* Year (~53 cols, ~28px) and 6 months (~27 cols, ~58px) stay untouched — the cap only bites
   on short ranges like 3 months (~14 cols), which would otherwise stretch to ~115px per cell. */
.strip-col { display: flex; flex-direction: column; gap: 3px; flex: 1 1 0; min-width: 0; max-width: 60px; }
.strip-cell { width: 100%; aspect-ratio: 1; border-radius: 3px; }

/* instant tooltip */
.heat-tip {
    position: fixed;
    z-index: 2000;
    background: var(--ink);
    color: #fff;
    font-size: 12px;
    padding: 6px 9px;
    border-radius: 8px;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 8px 20px -6px rgba(0, 0, 0, .4);
}

/* legend */
.heat-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 15px; font-size: 11px; color: var(--muted); }
.heat-legend .ramp { display: inline-flex; gap: 3px; }
.heat-legend .ramp i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.heat-legend .leg-item { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }
.heat-legend .leg-item:hover { color: var(--ink); }
/* Spotlight: clicking a legend key blurs/dims the non-matching cells for a moment. */
.cal-cell, .strip-cell { transition: filter .3s ease, opacity .3s ease; }
.cal-cell.heat-dim, .strip-cell.heat-dim { filter: blur(1.6px); opacity: .3; }
.heat-legend .leg-item i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.heat-legend .leg-sep { width: 1px; height: 13px; background: var(--line); margin: 0 2px; }

/* ---------- analysis grid (saldo chart + composition) ---------- */
.analysis-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
@media (max-width: 900px) { .analysis-grid { grid-template-columns: 1fr; } }

/* composition */
.comp-bar { display: flex; height: 14px; border-radius: 8px; overflow: hidden; margin: 14px 0; background: var(--panel); }
.comp-bar .seg { height: 100%; }
.comp-list { display: flex; flex-direction: column; gap: 11px; }
.comp-row { display: flex; align-items: center; gap: 9px; }
.comp-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.comp-name { font-size: 12.5px; flex: 1; }
.comp-val { font-size: 12.5px; font-family: var(--mono); font-weight: 600; }
.comp-pct { font-size: 11px; color: var(--faint); width: 52px; text-align: right; font-family: var(--mono); }
.comp-note { border-top: 1px solid var(--line-soft); margin-top: 14px; padding-top: 11px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.comp-note strong { color: var(--ink); }

/* monthly saldo diverging chart */
.dev-wrap { position: relative; margin-top: 16px; }
.dev-baseline { position: absolute; left: 0; right: 0; top: 74px; border-top: 1px dashed var(--line); z-index: 0; }
.dev-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; position: relative; z-index: 1; }
.dev-col { display: flex; flex-direction: column; align-items: center; cursor: pointer; border-radius: 6px; }
.dev-col:hover { background: var(--panel); }
.dev-up { height: 74px; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.dev-down { height: 74px; width: 100%; display: flex; flex-direction: column; justify-content: flex-start; align-items: center; }
.dev-bar { width: 55%; }
.dev-bar.up { background: var(--green); border-radius: 4px 4px 0 0; }
/* Deficit is red (green surplus / red deficit) so amber is free to mean only Feiertag. */
.dev-bar.down { background: var(--terra); border-radius: 0 0 4px 4px; }
.dev-vlbl { font-size: 10px; font-weight: 700; margin: 2px 0; }
.dev-vlbl.pos { color: var(--green-ink); }
.dev-vlbl.neg { color: var(--terra); }
.dev-m { font-size: 10px; color: var(--faint); font-family: var(--mono); margin-top: 5px; }

/* ---------- Stundenzettel table ---------- */
.sheet-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.sheet-range { display: flex; gap: 9px; }
.range-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 12.5px; font-family: var(--mono); color: var(--muted); }

.sheet-card { padding: 0; overflow: hidden; }

.sheet-table { width: 100%; border-collapse: collapse; font-size: 12px; font-family: var(--mono); }
.sheet-table thead th {
    background: var(--panel);
    text-align: left;
    padding: 11px 10px;
    font-weight: 600;
    color: var(--muted);
    font-family: var(--sans);
    white-space: nowrap;
}
.sheet-table td { padding: 10px; border-top: 1px solid var(--line-soft); white-space: nowrap; }
.sheet-table td.rt, .sheet-table th.rt { text-align: right; }
.sheet-table td.free, .sheet-table th.free { font-family: var(--sans); white-space: normal; }
.sheet-table .col-night { color: var(--night); }
.sheet-table .col-sun   { color: var(--purple); }
.sheet-table .col-feast { color: var(--tan); }
.sheet-table tr.excluded { color: var(--faint); font-style: italic; }
.sheet-table tfoot td { background: var(--panel); font-weight: 600; border-top: 2px solid var(--line); font-family: var(--mono); }
.sheet-table tfoot td.lbl { font-family: var(--sans); text-align: right; }

.sheet-note { font-size: 11.5px; color: var(--muted); margin-top: 11px; line-height: 1.5; }

/* ============================================================
   Login-Ansicht
   ============================================================ */
#loginView { display: none; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
body.logged-out #loginView { display: flex; }
body.logged-out .topbar,
body.logged-out .workspace { display: none !important; }

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px -14px rgba(0,0,0,.15);
    padding: 30px 28px;
}
.login-card h1 { font-size: 20px; font-weight: 700; text-align: center; margin: 0 0 2px; }
.login-card .lead { color: var(--muted); text-align: center; font-size: 13px; margin: 0 0 22px; }
.login-card label { font-size: 12.5px; font-weight: 600; margin-bottom: 5px; display: block; }
.login-card .field { margin-bottom: 16px; }
.login-card input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
}
.login-card input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(122,154,46,.15); }

.password-field { position: relative; }
.password-field input { padding-right: 2.75rem; }
.password-toggle {
    position: absolute; top: 0; right: 0; height: 100%; width: 2.75rem;
    display: flex; align-items: center; justify-content: center;
    padding: 0; border: 0; background: transparent; color: var(--faint); cursor: pointer;
}
.password-toggle:hover, .password-toggle:focus-visible { color: var(--ink); }
.password-toggle svg { width: 1.15rem; height: 1.15rem; display: block; }

.login-error { display: none; background: var(--terra-soft); color: var(--terra-d); border-radius: 10px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px; }
.login-error.show { display: block; }

.login-submit { width: 100%; background: var(--green); color: #fff; border: 0; border-radius: 10px; padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; }
.login-submit:hover { filter: brightness(.96); }
.login-submit:disabled { opacity: .6; cursor: default; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 820px) {
    .sidebar { width: 210px; flex-basis: 210px; }
    .topbar-brand .tenant { display: none; }
    .main { padding: 18px 16px 40px; }
}

/* ============================================================
   Druck (Phase 1: nur die Tabelle sauber drucken; A4-Report folgt in Phase 6)
   ============================================================ */
@media print {
    @page { size: A4; margin: 14mm; }
    .topbar, .sidebar, .tabs, .sheet-toolbar, .emp-header .id .avatar { display: none !important; }
    body { background: #fff; }
    .main { background: #fff; padding: 0; }
    .sheet-card { border: none; }
    .sheet-table thead th, .sheet-table tfoot td {
        background: #f0f0f2 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .sheet-table td, .sheet-table th { border: 1px solid #ccc !important; }
}
