:root{
  --bg: #0b0c10;
  --panel: #12141b;
  --panel2: #161a22;
  --text: #e9ecf1;
  --muted: #a8b0c2;
  --grid: rgba(255,255,255,0.08);

  --cellH: 42px;
  --timeW: 90px;
  --noteH: 64px;

  --dayMinW: 170px; /* mobile day width */
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* iOS Scroll-Lock für Modal */
body.modal-open{
  overflow: hidden;
}

.app{
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px;
}

.topbar{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar-left h1{
  margin:0;
  font-size: 22px;
  font-weight: 700;
}
.week-label{
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-right{
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
}
.btn{
  appearance:none;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor:pointer;
  font-weight: 600;
}

.calendar-wrap{
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  overflow: hidden;
}

/* Scroll-Container (native + JS Drag-to-Scroll) */
.calendar-scroll{
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

/* Grid */
.calendar{
  display: inline-grid; /* iOS: bessere intrinsic width */
  grid-template-columns: var(--timeW) repeat(7, 1fr);
  min-width: calc(var(--timeW) + 7 * 140px);
}

/* Kopfzeile */
.cell.head{
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(18,20,27,0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--grid);
  padding: 10px 10px;
  font-weight: 700;
}
.cell.head.day{ text-align:center; }
.cell.head.time{ text-align:left; }

/* Notizzeile */
.cell.note-time{
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  height: var(--noteH);
  padding: 10px 10px;
  color: var(--muted);
  font-size: 12px;
}
.cell.note{
  border-bottom: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
  height: var(--noteH);
  padding: 8px;
  background: rgba(255,255,255,0.02);
}
.day-note{
  width: 100%;
  height: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  resize: none;
  outline: none;
  padding: 8px;
  font-size: 13px;
  line-height: 1.2;
}

/* Zeitspalte */
.cell.time{
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  height: var(--cellH);
  padding: 10px 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Slots */
.cell.slot{
  border-bottom: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
  height: var(--cellH);
  position: relative;
  cursor: pointer;
  overflow: visible;
  touch-action: manipulation;
}
.cell.slot.weekend,
.cell.head.day.weekend{
  background: rgba(255,255,255,0.02);
}
.cell.slot.busy{
  background: rgba(255,255,255,0.02);
}

/* Terminblock */
.appointment{
  position:absolute;
  left: 6px;
  right: 6px;
  top: 6px;
  border-radius: 10px;
  border: 1px solid rgba(110,168,254,0.45);
  background: rgba(110,168,254,0.12);
  padding: 8px;
  font-size: 13px;
  line-height: 1.2;
  z-index: 5;
}
.appointment .title{ font-weight: 700; }
.appointment .meta{
  color: var(--muted);
  margin-top: 4px;
  font-size: 12px;
}

/* Modal */
.modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 999;
}
.modal-backdrop.open{ display:flex; }

.modal{
  width: min(560px, 100%);
  max-height: calc(100dvh - 24px); /* iOS: dvh */
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header, .modal-footer{
  padding: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}
.modal-footer{
  border-bottom: none;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.modal-body{
  padding: 14px;
  overflow: auto;                 /* Dialog-Inhalt scrollt */
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}

.modal-header h2{
  margin:0;
  font-size: 16px;
}
.icon-btn{
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor:pointer;
}

.form-row{ display:flex; flex-direction:column; gap: 6px; margin-bottom: 12px; }
.form-row.two{ display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label{ color: var(--muted); font-size: 12px; }

input, textarea{
  width:100%;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  outline: none;
}
textarea{ resize: vertical; }

/* Mitarbeiter-Combobox: schwarz auf weiß */
#inpEmployee{
  background: #ffffff;
  color: #000000;
  border-color: rgba(0,0,0,0.18);
}
#inpEmployee::placeholder{
  color: rgba(0,0,0,0.55);
}

.hint{
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.form-error{
  margin-top: 6px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,100,100,0.35);
  background: rgba(255,100,100,0.10);
  color: var(--text);
  font-size: 13px;
}

.btn.ghost{ background: transparent; }
.btn.primary{
  border-color: rgba(110,168,254,0.45);
  background: rgba(110,168,254,0.18);
}
.spacer{ flex: 1; }

/* Responsive */
@media (max-width: 900px){
  .app{ padding: 12px; }
  .topbar{
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .topbar-right{
    width: 100%;
    gap: 8px;
  }
  .btn{
    padding: 10px 10px;
    flex: 1 1 auto;
  }
}

@media (max-width: 640px){
  :root{
    --timeW: 72px;
    --cellH: 40px;
    --noteH: 70px;
  }

  /* harte Breite -> garantiert overflow, iOS-freundlich */
  .calendar{
    grid-template-columns: var(--timeW) repeat(7, var(--dayMinW));
    width: calc(var(--timeW) + 7 * var(--dayMinW));
    min-width: calc(var(--timeW) + 7 * var(--dayMinW));
  }

  .cell.head{ padding: 8px 6px; font-size: 13px; }
  .cell.time{ padding: 8px 6px; font-size: 12px; }
  .appointment{ font-size: 12px; padding: 7px; }
}
