/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --clr-border:    #e5e7eb;
    --clr-primary:   #2563eb;
    --clr-ja:        #86efac;   /* green-300  */
    --clr-ja-dark:   #4ade80;   /* green-400  */
    --clr-nein:      #fca5a5;   /* red-300    */
    --clr-nein-dark: #f87171;   /* red-400    */
    --clr-kmt:       #fde68a;   /* amber-200  */
    --clr-kmt-dark:  #fbbf24;   /* amber-400  */
    --clr-today:     #c7d2fe;   /* indigo-200 */
    --clr-today-hd:  #a5b4fc;   /* indigo-300 */
    --clr-we:        #f5f3ff;   /* violet-50  */
    --clr-even-we:   #818cf8;   /* indigo-400 */
    --radius:        8px;
    --shadow:        0 1px 3px rgba(0,0,0,.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f3f4f6;
    color: #111827;
    margin: 0;
}

/* ── Login-Seite ─────────────────────────────────── */
.login-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.login-wrap {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem 2rem 1.5rem;
    width: 100%;
    max-width: 480px;
    text-align: center;
}
.login-title { font-size: 1.6rem; font-weight: 700; margin-bottom: .25rem; }
.login-sub   { color: #6b7280; margin-bottom: 1.5rem; }

.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: .6rem;
    margin-bottom: 1.5rem;
}
.user-btn {
    background: #fff;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius);
    padding: .65rem .5rem;
    font-size: .95rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .15s, background .15s, color .15s;
    width: 100%;
}
.user-btn:hover, .user-btn:focus-visible {
    border-color: var(--clr-primary);
    background: var(--clr-primary);
    color: #fff;
    outline: none;
}
.admin-link { font-size: .8rem; color: #9ca3af; text-decoration: none; }
.admin-link:hover { color: #6b7280; }

/* ── App-Header ──────────────────────────────────── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #fff;
    border-bottom: 1px solid var(--clr-border);
    padding: .5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
}
.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: .4rem;
}
.nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1.5px solid var(--clr-border);
    font-size: 1.4rem;
    line-height: 1;
    color: #374151;
    text-decoration: none;
    transition: background .15s;
    flex-shrink: 0;
}
.nav-btn:hover { background: #f3f4f6; color: #111827; }

.week-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 96px;
}
.kw-label   { font-weight: 700; font-size: .9rem; line-height: 1.2; }
.date-range { font-size: .7rem; color: #6b7280; white-space: nowrap; }

.today-btn {
    font-size: .78rem;
    padding: .22rem .55rem;
    border-radius: 6px;
    border: 1.5px solid var(--clr-border);
    background: #fff;
    color: #374151;
    text-decoration: none;
    transition: background .15s;
    white-space: nowrap;
}
.today-btn:hover { background: #f3f4f6; color: #111827; }

.kw-switch {
    font-size: .78rem;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
    margin-left: .2rem;
}
.kw-switch label { cursor: pointer; }

.active-user-chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--clr-primary);
    color: #fff;
    border-radius: 20px;
    padding: .2rem .65rem .2rem .75rem;
    font-size: .82rem;
    font-weight: 600;
    white-space: nowrap;
}
.deselect-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.75);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}
.deselect-btn:hover { color: #fff; }

/* ── Kalender-Tabelle ────────────────────────────── */
.cal-wrap {
    padding: .75rem .75rem 3rem;
}
.cal-scroll {
    overflow-x: auto;
    overflow-y: clip;
    -webkit-overflow-scrolling: touch;
}
.cal-table {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    min-width: 660px;
    width: 100%;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}


/* Sticky Name-Spalte */
.cal-table .col-name {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #fff;
    width: 110px;
    padding: .4rem .6rem;
    border-right: 1.5px solid var(--clr-border);
    border-bottom: 1px solid var(--clr-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-table thead .col-name { background: #f9fafb; z-index: 5; }

/* Tag-Spalten Header */
.cal-table thead th.col-day {
    text-align: center;
    padding: .35rem .3rem;
    background: #f9fafb;
    color: #111827;
    border-bottom: 1.5px solid var(--clr-border);
    border-right: 1px solid var(--clr-border);
    width: 78px;
    overflow: hidden;
}
.cal-table thead th.col-day:last-child { border-right: none; }

.day-name { font-weight: 700; font-size: .82rem; }
.day-date { font-size: .7rem;  color: #6b7280; }
.day-sub  {
    font-size: .62rem;
    color: #9ca3af;
    margin-top: .1rem;
    min-height: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Header: Heute */
.cal-table thead .col-today {
    background: var(--clr-today-hd);
    color: #111827;   /* immer schwarz */
}
.cal-table thead .col-today .day-date { color: #4338ca; }
.cal-table thead .col-today .day-sub  { color: #6366f1; }

/* Header: Wochenende */
.cal-table thead .col-we      { background: var(--clr-we); }
/* Header: Feiertag */
.cal-table thead .col-feiertag { background: #dbeafe; }
/* Heute hat immer Vorrang */
.cal-table thead .col-today   { background: var(--clr-today-hd); }

/* Body-Zellen */
.cal-table tbody td.col-day {
    text-align: center;
    vertical-align: middle;
    padding: 3px;
    border-bottom: 1px solid var(--clr-border);
    border-right: 1px solid var(--clr-border);
    height: 54px;
    overflow: hidden;
}
.cal-table tbody td.col-day:last-child { border-right: none; }
.cal-table tbody tr:last-child td      { border-bottom: none; }

.cal-table tbody .col-we       { background: var(--clr-we); }
.cal-table tbody .col-feiertag { background: #eff6ff; }
.cal-table tbody .col-today    { background: var(--clr-today); }

/* ── Wochenend-Rahmen (nur gerade KW) ───────────── */
.even-we-sa { border-left:  2px solid var(--clr-even-we) !important; }
.even-we-so { border-right: 2px solid var(--clr-even-we) !important; }

.cal-table thead .even-we-sa,
.cal-table thead .even-we-so { border-top: 2px solid var(--clr-even-we) !important; }

.cal-table tbody tr:last-child .even-we-sa,
.cal-table tbody tr:last-child .even-we-so { border-bottom: 2px solid var(--clr-even-we) !important; }

/* Runde Ecken am WE-Rahmen */
.cal-table thead .even-we-sa                    { border-top-left-radius:     6px; }
.cal-table thead .even-we-so                    { border-top-right-radius:    6px; }
.cal-table tbody tr:last-child .even-we-sa      { border-bottom-left-radius:  6px; }
.cal-table tbody tr:last-child .even-we-so      { border-bottom-right-radius: 6px; }

/* ── Zellen-Füllung (JA / NEIN / Kommentar) ─────── */
.cell-fill {
    border-radius: 6px;
    width: 100%;
    height: 100%;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 3px 4px;
}
.fill-ja        { background: var(--clr-ja); }
.fill-nein      { background: var(--clr-nein); }
.fill-kommentar { background: var(--clr-kmt); }

/* Eigene Zeile: etwas kräftigere Farben */
.my-row .fill-ja        { background: var(--clr-ja-dark); }
.my-row .fill-nein      { background: var(--clr-nein-dark); }
.my-row .fill-kommentar { background: var(--clr-kmt-dark); }

/* Kommentar-Text in der Zelle: 2 Zeilen */
.cell-cmt {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: .67rem;
    line-height: 1.3;
    text-align: center;
    word-break: break-word;
    color: rgba(0,0,0,.7);
    width: 100%;
}

/* Gruppen-Spacer */
.cal-table tbody .group-spacer td {
    background: #f3f4f6;
    height: 5px;
    padding: 0;
    border: none !important;
}

/* Eigene Zeile */
.cal-table tbody .my-row .col-name { font-weight: 700; }
.cal-table tbody .my-row .col-today { background: #c7d2fe; }

/* Editierbare Zellen */
.editable { cursor: pointer; transition: filter .12s; }
.editable:hover { filter: brightness(.93); }

/* Termine-Zelle editierbar */
.editable-termine { cursor: pointer; }
.editable-termine:hover { filter: brightness(.93); }

/* Plus-Hint */
.cell-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1.5px solid #d1d5db;
    color: #9ca3af;
    font-size: .95rem;
    line-height: 1;
    pointer-events: none;
    background: #fff;
}
.editable:hover .cell-add,
.editable-termine:hover .cell-add {
    border-color: var(--clr-primary);
    color: var(--clr-primary);
}

/* Name-Buttons */
.name-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
    cursor: pointer;
    width: 100%;
    text-align: left;
    border-radius: 4px;
    transition: color .15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.name-btn:hover { color: var(--clr-primary); }
.name-active {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* ── Termine-Zeile ───────────────────────────────── */
.termine-label {
    font-size: .72rem !important;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #9ca3af;
}
.termine-label:hover { color: #6366f1 !important; }
.termine-row .col-day {
    height: 34px;
    min-height: 34px;
    padding: .2rem .3rem;
}
.is-feiertag { background: #dbeafe !important; }
.is-termin   { background: #fef3c7 !important; }

.feiertag-name, .termin-name {
    display: block;
    font-size: .67rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    text-align: center;
}
.feiertag-name { color: #1e40af; }
.termin-name   { color: #92400e; }

/* ── Modals ──────────────────────────────────────── */
.status-toggle {
    display: flex;
    gap: .75rem;
}
.status-btn {
    flex: 1;
    padding: .75rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all .15s;
    letter-spacing: .05em;
}
.status-ja   { background: var(--clr-ja);   color: #14532d; }
.status-nein { background: var(--clr-nein); color: #7f1d1d; }
.status-ja.active,   .status-ja:hover   { background: var(--clr-ja-dark);   border-color: #16a34a; }
.status-nein.active, .status-nein:hover { background: var(--clr-nein-dark); border-color: #dc2626; }

.field-error { color: #dc2626; font-size: .82rem; margin-top: .35rem; }
.field-warn  { color: #92400e; font-size: .82rem; margin-top: .35rem; }

/* ── Admin-Seite ─────────────────────────────────── */
.admin-page { background: #f3f4f6; }
.admin-table th {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #6b7280;
    background: #f9fafb;
    padding: .55rem .75rem;
}
.admin-table td { padding: .55rem .75rem; vertical-align: middle; }
.rollen-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .2rem .75rem;
}

/* ── Änderungshistorie ───────────────────────────── */
.history-wrap { margin: 0 .75rem 2rem; }

.history-summary {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .78rem;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
    list-style: none;
    padding: .3rem .1rem;
}
.history-summary::-webkit-details-marker { display: none; }
.history-summary::before { content: '▸'; font-size: .65rem; }
details[open] .history-summary::before { content: '▾'; }

.history-list {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-top: .35rem;
}
.history-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .75rem;
    font-size: .76rem;
    border-bottom: 1px solid var(--clr-border);
    overflow: hidden;
}
.history-row:last-child { border-bottom: none; }

.h-name   { font-weight: 600; min-width: 80px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-date   { color: #6b7280; white-space: nowrap; min-width: 34px; }
.h-action { font-size: .7rem; padding: .1rem .35rem; border-radius: 4px; white-space: nowrap;
            background: #f3f4f6; color: #374151; }
.h-erstellt   { background: #dcfce7; color: #166534; }
.h-geaendert  { background: #fef9c3; color: #854d0e; }
.h-geloescht  { background: #fee2e2; color: #991b1b; }
.h-zeitraum   { background: #dbeafe; color: #1e40af; }
.h-termin     { background: #f3e8ff; color: #6b21a8; }
.h-termin_del { background: #fee2e2; color: #991b1b; }

.h-detail { color: #374151; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-time   { color: #9ca3af; margin-left: auto; white-space: nowrap; font-size: .72rem; }
.history-empty { font-size: .78rem; color: #9ca3af; padding: .5rem .75rem; margin: 0; }

/* ── Versionshinweis ─────────────────────────────── */
.version-badge {
    position: fixed;
    bottom: .5rem;
    left: .6rem;
    font-size: .65rem;
    color: #d1d5db;
    pointer-events: none;
    z-index: 10;
}

/* Toast */
.toast.bg-success { background: #059669 !important; }
.toast.bg-danger  { background: #dc2626 !important; }
