:root {
    --color-primary: #3b82f6;
    --color-primary-dark: #2563eb;
    --color-danger: #ef4444;
    --color-bg: #f7f8fa;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-today: #eff6ff;
    --color-holiday: #fef2f2;
    --color-holiday-text: #b91c1c;
    --color-weekend: #fafafa;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.08);
    font-size: 15px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

/* ===================== Buttons ===================== */
.btn {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-outline { background: #fff; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: #f3f4f6; }
.btn-danger { background: #fff; border-color: var(--color-danger); color: var(--color-danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-block { width: 100%; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-icon {
    background: #fff; border: 1px solid var(--color-border);
    width: 34px; height: 34px; border-radius: 8px;
    font-size: 1.1rem; line-height: 1; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: #f3f4f6; }
.btn-close {
    background: none; border: none; font-size: 1.4rem; cursor: pointer;
    color: var(--color-text-muted); line-height: 1;
}
.btn-close:hover { color: var(--color-text); }

/* ===================== Login ===================== */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1rem;
    background: linear-gradient(135deg, #eef2ff 0%, #f7f8fa 100%);
}
.login-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-subtitle { color: var(--color-text-muted); margin: 0 0 1.5rem; }
.login-form { text-align: left; display: flex; flex-direction: column; gap: 0.3rem; }
.login-form label { font-size: 0.85rem; font-weight: 600; margin-top: 0.6rem; }
.login-form input {
    padding: 0.6rem 0.75rem; border-radius: 8px; border: 1px solid var(--color-border);
    font-size: 1rem; width: 100%;
}
.login-form button { margin-top: 1.2rem; }

.alert { padding: 0.6rem 0.8rem; border-radius: 8px; font-size: 0.88rem; margin-bottom: 0.8rem; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-warning ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }
.alert-warning li { margin-bottom: 0.15rem; }

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

.topbar {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
    gap: 0.75rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.7rem 1.2rem;
    position: sticky; top: 0; z-index: 20;
}
.app-title { font-size: 1.15rem; margin: 0; white-space: nowrap; }
.topbar-left, .topbar-center, .topbar-right { display: flex; align-items: center; gap: 0.6rem; }
.topbar-center { flex-wrap: wrap; }
.range-label { font-size: 1.05rem; margin: 0 0 0 0.4rem; font-weight: 600; white-space: nowrap; }

.view-switch { display: flex; border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; }
.view-btn {
    background: #fff; border: none; padding: 0.45rem 0.9rem; cursor: pointer;
    font-size: 0.85rem; color: var(--color-text-muted); border-right: 1px solid var(--color-border);
}
.view-btn:last-child { border-right: none; }
.view-btn.active { background: var(--color-primary); color: #fff; }
.view-btn:hover:not(.active) { background: #f3f4f6; }

.user-menu { display: flex; align-items: center; gap: 0.5rem; margin-left: 0.5rem; }
.user-name { font-size: 0.85rem; color: var(--color-text-muted); }

.calendar-container { flex: 1; padding: 1rem; }
.calendar-view { background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

/* ===================== Monatsansicht ===================== */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-weekday-header {
    padding: 0.6rem 0; text-align: center; font-size: 0.78rem; font-weight: 600;
    color: var(--color-text-muted); border-bottom: 1px solid var(--color-border);
    text-transform: uppercase; letter-spacing: 0.03em;
}
.month-cell {
    min-height: 110px; border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
    padding: 0.35rem; position: relative; cursor: pointer; transition: background 0.1s;
}
.month-cell:hover { background: #fafbff; }
.month-cell.other-month { background: #fbfbfc; color: #c1c5cc; }
.month-cell.today { background: var(--color-today); }
.month-cell.weekend { background: var(--color-weekend); }
.month-cell.holiday { background: var(--color-holiday); }
.month-cell:nth-child(7n) { border-right: none; }

.cell-date { font-size: 0.85rem; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.cell-date .day-num.today-badge {
    background: var(--color-primary); color: #fff; border-radius: 50%;
    width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: 0.78rem;
}
.holiday-label { font-size: 0.65rem; color: var(--color-holiday-text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.event-pill {
    font-size: 0.72rem; padding: 1px 6px; border-radius: 5px; color: #fff; margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.event-pill:hover { filter: brightness(0.92); }
.more-events { font-size: 0.7rem; color: var(--color-text-muted); margin-top: 2px; cursor: pointer; }

/* ===================== Wochen-/Tagesansicht (Zeitraster) ===================== */
.time-grid-wrapper { display: flex; flex-direction: column; }
.time-grid-header { display: flex; border-bottom: 1px solid var(--color-border); position: sticky; top: 0; background: #fff; z-index: 5;}
.time-grid-gutter { width: 55px; flex-shrink: 0; }
.time-grid-day-header {
    flex: 1; text-align: center; padding: 0.55rem 0.2rem; border-left: 1px solid var(--color-border);
    font-size: 0.82rem;
}
.time-grid-day-header.today { background: var(--color-today); }
.time-grid-day-header.holiday { background: var(--color-holiday); }
.time-grid-day-header .weekday-name { color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.68rem;}
.time-grid-day-header .day-number { font-size: 1.1rem; font-weight: 700; }
.time-grid-day-header .holiday-name { font-size: 0.62rem; color: var(--color-holiday-text); }

.allday-row { display: flex; border-bottom: 1px solid var(--color-border); min-height: 30px; }
.allday-gutter { width: 55px; flex-shrink: 0; font-size: 0.65rem; color: var(--color-text-muted); padding: 4px; }
.allday-cell { flex: 1; border-left: 1px solid var(--color-border); padding: 2px 4px; }

.time-grid-body { display: flex; position: relative; max-height: 65vh; overflow-y: auto; }
.time-grid-gutter-col { width: 55px; flex-shrink: 0; }
.time-slot-label {
    height: 48px; font-size: 0.68rem; color: var(--color-text-muted);
    text-align: right; padding-right: 6px; transform: translateY(-6px);
}
.time-grid-day-col { flex: 1; border-left: 1px solid var(--color-border); position: relative; }
.time-slot-cell { height: 48px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.time-slot-cell:hover { background: #fafbff; }

.time-event {
    position: absolute; left: 3px; right: 3px; border-radius: 6px; color: #fff;
    padding: 2px 6px; font-size: 0.72rem; overflow: hidden; cursor: pointer; box-shadow: var(--shadow);
}
.time-event .event-time { font-size: 0.65rem; opacity: 0.9; display: block; }
.time-event:hover { filter: brightness(0.94); }

.current-time-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--color-danger); z-index: 4; }
.current-time-line::before {
    content: ''; position: absolute; left: -4px; top: -4px; width: 10px; height: 10px;
    background: var(--color-danger); border-radius: 50%;
}

/* ===================== Modal ===================== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(17,24,39,0.45);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 4vh 1rem; z-index: 100; overflow-y: auto;
}
.modal {
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 460px;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.2rem; border-bottom: 1px solid var(--color-border);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 0.3rem; }
.modal-body label { font-size: 0.82rem; font-weight: 600; margin-top: 0.55rem; }
.modal-body input[type=text], .modal-body input[type=date], .modal-body input[type=time],
.modal-body textarea {
    padding: 0.5rem 0.6rem; border-radius: 8px; border: 1px solid var(--color-border); font-size: 0.92rem; width: 100%;
    font-family: inherit;
}
.modal-body input[type=color] { width: 60px; height: 34px; padding: 2px; border: 1px solid var(--color-border); border-radius: 6px; }
.modal-body select { padding: 0.5rem 0.6rem; border-radius: 8px; border: 1px solid var(--color-border); font-size: 0.92rem; width: 100%; font-family: inherit; background: #fff; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; font-weight: 500 !important; margin-top: 0.7rem !important; }
.checkbox-label input { width: auto; }

.form-row { display: flex; gap: 0.7rem; }
.form-col { flex: 1; }

.field-hint { font-size: 0.75rem; color: var(--color-text-muted); margin: 0.3rem 0 0; }

#recurrenceFields {
    margin-top: 0.4rem; padding: 0.7rem 0.8rem; background: #f8f9fb;
    border-radius: 8px; border: 1px solid var(--color-border);
}

.modal-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 1.3rem; }
.modal-footer-right { display: flex; gap: 0.5rem; }

/* ===================== Serie-Auswahl-Modal ===================== */
.modal-small { max-width: 340px; }
.scope-choice-buttons { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }

/* ===================== Wiederkehrende-Termin-Kennzeichnung ===================== */
.event-pill.recurring, .time-event.recurring { border-left: 3px solid rgba(255,255,255,0.85); }
.recurring-icon { opacity: 0.9; margin-right: 2px; }

/* ===================== Überschneidungs-Kennzeichnung ===================== */
.event-pill.has-conflict, .time-event.has-conflict {
    box-shadow: 0 0 0 2px #f59e0b inset;
}

/* ===================== Responsive ===================== */
@media (max-width: 800px) {
    .topbar { flex-direction: column; align-items: stretch; }
    .topbar-left, .topbar-center, .topbar-right { justify-content: space-between; }
    .range-label { font-size: 0.95rem; }
    .month-cell { min-height: 80px; }
    .calendar-container { padding: 0.5rem; }
}

@media (max-width: 520px) {
    .app-title { font-size: 1rem; }
    .user-name { display: none; }
    .month-cell { min-height: 64px; font-size: 0.8rem; }
    .holiday-label, .event-pill { font-size: 0.62rem; }
    .form-row { flex-direction: column; gap: 0; }
    .view-btn { padding: 0.4rem 0.6rem; font-size: 0.78rem; }
}
