/* Kalender App — Design System (Material-inspiriert, kein Build-Step) */

:root {
  --color-primary: #6750A4;
  --color-primary-hover: #5a4791;
  --color-on-primary: #ffffff;
  --color-bg: #FEF7FF;
  --color-surface: #ffffff;
  --color-surface-alt: #F3EDF7;
  --color-border: #E7E0EC;
  --color-text: #1D1B20;
  --color-text-muted: #49454F;
  --color-danger: #B3261E;
  --color-success: #146C2E;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.06);
  --sidebar-width: 264px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --color-primary: #D0BCFF;
  --color-primary-hover: #b89ef2;
  --color-on-primary: #381E72;
  --color-bg: #141218;
  --color-surface: #1D1B20;
  --color-surface-alt: #2B2930;
  --color-border: #49454F;
  --color-text: #E6E0E9;
  --color-text-muted: #CAC4D0;
  --color-danger: #F2B8B5;
  --color-success: #7EE0A0;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-primary: #D0BCFF;
    --color-primary-hover: #b89ef2;
    --color-on-primary: #381E72;
    --color-bg: #141218;
    --color-surface: #1D1B20;
    --color-surface-alt: #2B2930;
    --color-border: #49454F;
    --color-text: #E6E0E9;
    --color-text-muted: #CAC4D0;
    --color-danger: #F2B8B5;
    --color-success: #7EE0A0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  transition: background-color .2s ease, color .2s ease;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-weight: 600; margin: 0 0 .5em; }

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform .2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px;
  font-size: 18px;
  font-weight: 700;
}
.sidebar-brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--color-primary); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  color: var(--color-text);
  font-weight: 500;
}
.nav-link:hover { background: var(--color-surface-alt); text-decoration: none; }
.nav-link.active { background: var(--color-primary); color: var(--color-on-primary); }

.sidebar-section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  margin: 18px 14px 6px;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar h1 { font-size: 26px; margin: 0; }

.menu-toggle { display: none; }

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-card .value { font-size: 32px; font-weight: 700; }
.stat-card .label { color: var(--color-text-muted); font-size: 13px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s ease, box-shadow .15s ease;
}
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); text-decoration: none; }
.btn-secondary { background: var(--color-surface-alt); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-border); text-decoration: none; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: 50%; background: transparent; color: var(--color-text); }
.btn-icon:hover { background: var(--color-surface-alt); }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input[type=number], textarea, select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
textarea { resize: vertical; min-height: 90px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 160px; }

.color-swatch-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected { border-color: var(--color-text); }

/* --- Auth pages --- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { padding: 36px; }
.auth-footer { text-align: center; margin-top: 16px; font-size: 14px; color: var(--color-text-muted); }

/* --- Flash messages --- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.flash-error { background: color-mix(in srgb, var(--color-danger) 15%, transparent); color: var(--color-danger); }
.flash-success { background: color-mix(in srgb, var(--color-success) 15%, transparent); color: var(--color-success); }

/* --- Calendar grid --- */
.calendar-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.calendar-toolbar .spacer { flex: 1; }
.view-switch { display: flex; background: var(--color-surface-alt); border-radius: 999px; padding: 4px; gap: 2px; }
.view-switch a { padding: 7px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--color-text); }
.view-switch a.active { background: var(--color-surface); box-shadow: var(--shadow-sm); }
.view-switch a:hover { text-decoration: none; }
.period-label { font-weight: 700; font-size: 14px; padding: 0 4px; white-space: nowrap; }

/* --- Legende / Kalenderauswahl --- */
.calendar-layout { display: flex; align-items: flex-start; gap: 20px; }
.legend-panel {
  width: 220px; flex-shrink: 0;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  overflow: hidden;
}
.legend-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--color-surface-alt); border: none; cursor: pointer;
  font-weight: 700; font-size: 13px; color: var(--color-text); text-transform: uppercase; letter-spacing: .03em;
}
.legend-chevron { transition: transform .15s ease; }
.legend-panel.collapsed .legend-chevron { transform: rotate(-90deg); }
.legend-panel.collapsed .legend-list { display: none; }
.legend-list { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.legend-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.legend-item:hover { background: var(--color-surface-alt); }
.legend-item input { display: none; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--legend-color); flex-shrink: 0; }
.legend-item input:not(:checked) ~ .legend-swatch { background: transparent; border: 2px solid var(--legend-color); }
.legend-item input:not(:checked) ~ .legend-name { color: var(--color-text-muted); text-decoration: line-through; }
.calendar-content { flex: 1; min-width: 0; }
.calendar-hidden { display: none !important; }

@media (max-width: 900px) {
  .calendar-layout { flex-direction: column; }
  .legend-panel { width: 100%; }
}

.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--color-border); border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.month-grid .weekday { background: var(--color-surface-alt); padding: 8px; text-align: center; font-size: 12px; font-weight: 700; color: var(--color-text-muted); }
.month-cell { background: var(--color-surface); min-height: 110px; padding: 6px; position: relative; cursor: pointer; }
.month-cell:hover { background: var(--color-surface-alt); }
.month-cell.outside { background: var(--color-bg); opacity: .55; }
.month-cell.outside:hover { background: var(--color-bg); opacity: .8; }
.month-cell.today .day-num { background: var(--color-primary); color: var(--color-on-primary); }
.day-num { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; font-size: 12px; font-weight: 700; margin-bottom: 4px; }

.event-chip {
  display: block;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 11px;
  line-height: 1.3;
  font-weight: 500;
  color: #fff;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  cursor: grab;
}

.event-chip.is-blocked,
.timed-event.is-blocked {
  cursor: pointer;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.15) 0 6px, transparent 6px 12px);
}

.week-grid, .day-grid { display: grid; grid-template-columns: 60px 1fr; border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; background: var(--color-surface); }
.week-grid { grid-template-columns: 60px repeat(5, 1fr); }
.time-col { border-right: 1px solid var(--color-border); }
.time-slot { height: 52px; font-size: 11px; color: var(--color-text-muted); text-align: right; padding: 2px 6px; border-top: 1px solid var(--color-border); }
.day-col { border-right: 1px solid var(--color-border); position: relative; }
.day-col.today { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }
.day-col-header { text-align: center; padding: 10px 4px; border-bottom: 1px solid var(--color-border); font-weight: 700; font-size: 13px; background: var(--color-surface-alt); }
.day-col-header .sub { font-weight: 400; color: var(--color-text-muted); font-size: 11px; }
.hour-row { height: 52px; border-top: 1px solid var(--color-border); position: relative; cursor: pointer; }
.hour-row:hover { background: var(--color-surface-alt); }
.timed-event {
  position: absolute;
  left: 3px; right: 3px;
  border-radius: 3px;
  color: #fff;
  font-size: 11px;
  line-height: 1.35;
  padding: 3px 6px;
  overflow: hidden;
  cursor: grab;
  box-shadow: var(--shadow-sm);
}
.timed-event strong { font-size: 10px; }

.list-table { width: 100%; border-collapse: collapse; }
.list-table th, .list-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 14px; }
.list-table th { color: var(--color-text-muted); font-size: 12px; text-transform: uppercase; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--color-surface-alt); }
.dot-sm { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px; border-bottom: 1px solid var(--color-border); }
.table th { font-size: 12px; text-transform: uppercase; color: var(--color-text-muted); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal { background: var(--color-surface); border-radius: var(--radius-lg); width: 100%; max-width: 560px; padding: 28px; box-shadow: var(--shadow-md); }

.empty-state { text-align: center; padding: 48px 16px; color: var(--color-text-muted); }

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 40; transform: translateX(-100%); box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .main { padding: 16px; }
  .week-grid { grid-template-columns: 44px repeat(5, minmax(90px,1fr)); overflow-x: auto; }
}
