* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #fdf5e6;
  --surface: #fffcf4;
  --border: #dfc9a8;
  --text: #3d2b1f;
  --muted: #8b6f57;
  --accent: #b8763a;
  --accent-bg: #f3e6d3;
  --accent-shadow: rgba(184, 118, 58, 0.3);
  --drop-bg: rgba(184, 118, 58, 0.15);
  --ghost-bg: rgba(184, 118, 58, 0.22);
}

body {
  font-family: 'Quicksand', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: var(--surface);
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.week-label { font-size: 22px; font-weight: 600; }
.week-nav { display: flex; gap: 8px; align-items: center; }

.nav-btn {
  width: 48px; height: 48px;
  border-radius: 12px; border: none;
  background: var(--bg);
  font-size: 20px; cursor: pointer;
  transition: background 0.15s;
}
.nav-btn:active { background: var(--accent-bg); transform: scale(0.95); }

.today-btn {
  padding: 0 20px; height: 48px;
  border-radius: 12px; border: none;
  background: var(--accent); color: white;
  font-weight: 600; font-size: 15px; cursor: pointer;
}

/* Family bar */
.family-bar {
  display: flex; gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.avatar {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer; opacity: 0.4;
  transition: opacity 0.2s;
  min-width: 60px;
}
.avatar.active { opacity: 1; }
.avatar-circle {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: white;
}
.avatar-name { font-size: 12px; font-weight: 500; }

/* Calendar */
.calendar {
  flex: 1; overflow: auto;
  background: var(--surface);
  margin: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
}
.grid {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  min-width: 100%;
}
.grid-header-row {
  display: contents;
}
.grid-header-cell {
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 10;
  padding: 12px 8px;
  text-align: center;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
}
.grid-header-cell:last-child { border-right: none; }

.day-name { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.day-num { font-size: 20px; font-weight: 600; margin-top: 2px; }
.day-num.today {
  background: var(--accent); color: white;
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}

.time-slot {
  height: 60px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
  padding: 4px 6px; text-align: right;
}
.day-slot {
  height: 60px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  cursor: pointer; position: relative;
  transition: background 0.1s;
}
.day-slot:last-child { border-right: none; }
.day-slot:active { background: var(--accent-bg); }

/* Events */
.event {
  position: absolute;
  z-index: 5;
  left: 3px; right: 3px;
  border-radius: 8px;
  padding: 6px 8px;
  color: white;
  font-size: 13px; font-weight: 500;
  overflow: hidden;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.event-emoji { font-size: 18px; flex-shrink: 0; }
.event-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Drag & Drop + Resize ---------- */
.event {
  user-select: none;
  -webkit-user-select: none;
}

.event-resize-handle.top {
  top: 0;
  bottom: auto;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(to top, transparent, rgba(0,0,0,0.15));
}
.event-resize-handle.top::after {
  bottom: auto;
  top: 2px;
}

.event-resize-handle {
  position: absolute;
  bottom: 0;
  left: 25%;
  right: 25%;
  height: 6px;
  cursor: ns-resize;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.15));
  border-radius: 0 0 8px 8px;
  opacity: 0;
  transition: opacity 0.15s;
}
.event-resize-handle.top {
  left: 25%;
  right: 25%;
}
.event:hover .event-resize-handle {
  opacity: 1;
}

.event-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: rgba(255,255,255,0.7);
  border-radius: 1px;
}
.day-slot.drop-target {
  background: var(--drop-bg) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

/* Drag-Tooltip: zeigt Zeit/Dauer während Drag oder Resize */
.drag-tooltip {
  position: fixed;
  z-index: 10000;
  background: rgba(17, 24, 39, 0.95);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  white-space: nowrap;
  transform: translate(12px, -50%);
  opacity: 0;
  transition: opacity 0.1s ease;
}
.drag-tooltip.visible { opacity: 1; }
.drag-tooltip .dt-arrow { opacity: 0.6; margin: 0 4px; }
.drag-tooltip .dt-duration {
  margin-left: 6px;
  padding-left: 6px;
  border-left: 1px solid rgba(255,255,255,0.3);
  opacity: 0.85;
}

/* Smoother Drag-Visualisierung */
.event.dragging {
  opacity: 0.85;
  z-index: 1000;
  cursor: grabbing !important;
  box-shadow: 0 12px 32px rgba(0,0,0,0.35);
  transition: none !important;
}
.event.resizing {
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transition: none !important;
}

.event.event-stacked {
  font-size: 0.78rem;
  padding: 4px 6px;
}
.event.event-stacked .event-text {
  font-size: 0.75rem;
}

.event-ghost {
  position: absolute;
  left: 3px; right: 3px;
  background: var(--ghost-bg);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  pointer-events: none;
  z-index: 999;
}

/* ---------- Now-Line: aktuelle Uhrzeit Indikator ---------- */
.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #ef4444;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}
.now-line::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
  animation: nowPulse 2s ease-out infinite;
}
@keyframes nowPulse {
  0%   { box-shadow: 0 0 0 0    rgba(239, 68, 68, 0.6); }
  70%  { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0    rgba(239, 68, 68, 0); }
}
.day-slot.is-today {
  background: rgba(239, 68, 68, 0.025);
}

/* Wochenende leicht absetzen */
.grid-header-cell.weekend,
.day-slot.weekend {
  background: var(--ls-sage-bg, #edf4ec);
}
.day-slot.weekend.is-today {
  background: rgba(239, 68, 68, 0.04);
}

/* Modal */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal-bg.active { display: flex; }
.modal {
  background: var(--surface);
  width: 100%; max-width: 500px;
  border-radius: 24px 24px 0 0;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal h2 { margin-bottom: 16px; font-size: 20px; }
.modal-info {
  background: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--muted);
}
.label {
  font-size: 12px; font-weight: 600;
  margin: 16px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.emoji-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.emoji-btn {
  aspect-ratio: 1;
  border: 2px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  font-size: 26px;
  cursor: pointer;
  transition: all 0.15s;
}
.emoji-btn.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
  transform: scale(1.05);
}
.person-picker {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.person-btn {
  flex: 1; min-width: 80px;
  padding: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  font-size: 13px; font-weight: 500;
}
.person-btn.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.person-btn-emoji { font-size: 24px; }
.modal input {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions {
  display: flex; gap: 8px;
  margin-top: 24px;
}
.btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-cancel { background: var(--bg); color: var(--text); }
.btn-save { background: var(--accent); color: white; }
.btn-delete {
  flex: 0 0 auto;
  padding: 16px 20px;
  background: #fee2e2; color: #dc2626;
}

/* ===== TODAY BANNER  ===== */
#todayBanner {
  width: 100%;
  box-sizing: border-box;
  margin: 12px 0;
  background: linear-gradient(135deg, var(--ls-sage, #6b8f71) 0%, var(--ls-accent, #b8763a) 100%);
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-size: 13px;
  max-height: 200px;
  overflow: hidden;
}
#todayBanner .tb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}
#todayBanner .tb-title-main { font-size: 14px; }
#todayBanner .tb-toggle { font-size: 12px; opacity: 0.85; }
#todayBanner .tb-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
  max-height: 160px;
  overflow: hidden;
  transition: max-height 0.25s ease, margin-top 0.25s ease, opacity 0.2s ease;
}
#todayBanner .tb-body.collapsed {
  max-height: 0;
  margin-top: 0;
  opacity: 0;
}
#todayBanner .tb-col {
  background: rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
#todayBanner .tb-col-header {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.9;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#todayBanner .tb-count {
  background: rgba(255,255,255,0.25);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
}
#todayBanner .tb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 140px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px;
}
#todayBanner .tb-list::-webkit-scrollbar { width: 5px; }
#todayBanner .tb-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.35);
  border-radius: 3px;
}
#todayBanner .tb-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 5px;
  cursor: pointer;
  line-height: 1.3;
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#todayBanner .tb-item:hover { background: rgba(255,255,255,0.18); }
#todayBanner .tb-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 12px;
  opacity: 0.95;
  flex-shrink: 0;
}
#todayBanner .tb-emoji { flex-shrink: 0; }
#todayBanner .tb-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
#todayBanner .tb-person {
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
  background: rgba(255,255,255,0.22);
  border-radius: 10px;
  padding: 1px 7px;
  letter-spacing: 0.2px;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#todayBanner .tb-empty {
  font-size: 12px;
  opacity: 0.65;
  font-style: italic;
  padding: 4px 6px;
}
.event-highlight {
  animation: tb-pulse 0.5s ease 0s 3;
  box-shadow: 0 0 0 3px #ffd700, 0 0 12px rgba(255,215,0,0.6) !important;
  z-index: 10;
}
@keyframes tb-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
@media (max-width: 600px) {
  #todayBanner { font-size: 12px; padding: 8px 10px; }
  #todayBanner .tb-body {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  #todayBanner .tb-list { max-height: 140px; }
}

/* ===== Recurrence UI (legacy) ===== */
.recurrence-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}
.recurrence-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.recurrence-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  min-width: 90px;
}
.recurrence-select,
.recurrence-date,
.recurrence-count {
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.recurrence-select { flex: 1; min-width: 140px; }
.recurrence-count {
  width: 70px;
  text-align: center;
  -moz-appearance: textfield;
}
.recurrence-count::-webkit-outer-spin-button,
.recurrence-count::-webkit-inner-spin-button {
  opacity: 1;
}
.recurrence-end-options {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  padding-left: 4px;
}
.recurrence-end-options.active { display: flex; }
.recurrence-weekdays {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 6px;
  padding-left: 4px;
  font-size: 13px;
  color: #4b5563;
}
.recurrence-weekdays.active { display: flex; }
.recurrence-weekdays input[type="checkbox"] {
  accent-color: #6366f1;
}

.recurrence-end-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #4b5563;
}
.recurrence-end-row input[type="radio"] {
  accent-color: #6366f1;
}
.recurrence-hint {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
  font-style: italic;
}

/* ===== Recurrence UI v2 (Modern) ===== */
.recurrence-section {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 16px;
  border: 1px solid var(--border);
}
.recurrence-section .label { margin-top: 0; }

/* Frequency Pills */
.rec-freq-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.rec-pill {
  flex: 1;
  min-width: 70px;
  padding: 10px 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.rec-pill:active { transform: scale(0.96); }
.rec-pill.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
}

/* Sub-labels inside section */
.rec-sublabel {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 8px;
}

/* Weekday Picker */
.rec-weekdays { display: none; }
.rec-weekdays.active { display: block; }
.rec-day-pills {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.rec-day-pill {
  padding: 10px 0;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.rec-day-pill:active { transform: scale(0.94); }
.rec-day-pill.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
}
.rec-day-pill.rec-day-weekend { color: var(--muted); }
.rec-day-pill.rec-day-weekend.selected { color: var(--accent); }

.rec-quick-link {
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
}
.rec-quick-link:hover { text-decoration: underline; }

/* End Options */
.rec-end-block { display: none; }
.rec-end-block.active { display: block; }

.rec-end-segmented {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.rec-seg-btn {
  flex: 1;
  padding: 8px 6px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.rec-seg-btn.selected {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 3px var(--accent-shadow);
}

.rec-end-detail {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.rec-end-detail.active { display: flex; }
.rec-end-detail input[type="date"],
.rec-end-detail input[type="number"] {
  flex: 0 1 auto;
  width: auto;
  padding: 10px 12px;
  font-size: 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-family: inherit;
}
.rec-end-detail input[type="number"] { width: 80px; text-align: center; }
.rec-end-detail span {
  font-size: 13px;
  color: var(--muted);
}

/* Live Preview */
.rec-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}
.rec-preview-icon { font-size: 16px; }
.rec-preview.is-recurring {
  background: var(--accent-bg);
  border-color: var(--accent);
  border-style: solid;
  color: var(--accent);
}
