:root {
  --bg-body: #f7f9fc;
  --bg-header: #ffffff;
  --text-main: #2c3e50;
  --grid-line: #e2e8f0;
  --cell-height: 140px;
  --w-month: 35px;
  --w-day: 50px;
  --desktop-col-min: 170px;
  --mobile-col-width: 180px;

  --col-elin: #AEC6CF;
  --col-ida: #77DD77;
  --col-alva: #AAF0D1;
  --col-emil: #C3B1E1;
  --col-mareen: #FFB7B2;
  --col-manuel: #6C7A89;
  --col-familie: #FFDAC1;
  --col-ferien: #D5D5D5;
  --col-geburtstage: #FF6961;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: "Roboto", "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background-color: var(--bg-header);
  height: 75px;
  min-height: 75px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 25px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  z-index: 1000;
  position: relative;
  margin-bottom: 5px;
  flex-shrink: 0;
}

.header-left {
  font-size: 1.2rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 12px;
  background: #f8fafc;
  transition: all 0.2s;
}

.header-left:active {
  transform: scale(0.96);
  background: #e2e8f0;
}

.header-center {
  text-align: center;
  cursor: pointer;
  background: #f1f3f5;
  padding: 8px 30px;
  border-radius: 25px;
  transition: all 0.2s;
  flex: 0 0 auto; /* Back to auto width for "island" look */
}

.header-spacer {
  flex: 1;
  min-width: 20px; /* Minimum space to ensure center positioning */
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-center {
  text-align: center;
  cursor: pointer;
  background: #f1f3f5;
  padding: 8px 30px;
  border-radius: 25px;
  transition: all 0.2s;
}

.header-center:active {
  transform: scale(0.96);
}

.btn-upcoming {
  background: #fff;
  color: #333;
  border: 2px solid #e2e8f0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
}

.btn-upcoming:active {
  transform: scale(0.9);
  background: #e2e8f0;
}

#clock {
  font-size: 1.5rem;
  font-weight: 700;
  color: #333;
  line-height: 1;
}

#date-text {
  font-size: 0.85rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

.btn-add,
.btn-recipes,
.btn-login,
.btn-logout {
  background: #222;
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  font-size: 1.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.btn-add:active,
.btn-recipes:active {
  transform: scale(0.9);
}

.btn-recipes {
  margin-right: 10px;
  background: #e67e22;
}

.btn-login {
  background: #4a5568;
}

.btn-logout {
  background: #e53e3e; /* Red for logout */
}

/* Desktop-specific adjustments */
@media (min-width: 769px) {
  header {
    padding: 0 25px;
  }
  
  .header-right {
    overflow-x: visible; /* No scrolling needed on desktop */
    scrollbar-width: auto;
    padding-bottom: 0;
  }
}

/* GRID */
.calendar-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0; 
  max-width: 100vw; 
  overflow-y: auto;
  overflow-x: auto;
  position: relative;
  scroll-behavior: smooth;
  padding-top: 5px;
  -webkit-overflow-scrolling: touch; /* Wichtig für flüssiges Wischen */
  width: 100%;
}

#calendar-grid-container {
  display: contents;
}

.grid {
  display: grid;
  /* 1. Monat, 2. Tag, 3.-9. Personen, 10. Ferien (w-day!), 11. Geburtstage */
  grid-template-columns: var(--w-month) var(--w-day) repeat(7, minmax(var(--desktop-col-min), 1fr)) var(--w-day) minmax(var(--desktop-col-min), 1fr);
  grid-auto-rows: var(--cell-height);
  grid-template-rows: 50px;
  
  width: 100%; /* Sorgt dafür, dass sich das Grid auf großen PCs ausdehnt */
  
  /* DAS IST DIE MAGIE: Wir zwingen das Grid, mathematisch IMMER mindestens so breit zu sein wie alle Mindestbreiten der Spalten zusammen. 
     Dadurch sprengt das Grid den Rahmen des Tablets und erzeugt den Scrollbalken! */
  min-width: calc(var(--w-month) + var(--w-day) + 7 * var(--desktop-col-min) + var(--w-day) + var(--desktop-col-min));
}

.thead {
  display: contents;
}

.th {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 50px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--grid-line);
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
  color: #444;
}

.cell {
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  padding: 4px;
  overflow: hidden;
  position: relative;
  background: #fff;
}

.month-col {
  position: sticky;
  left: 0;
  z-index: 12;
  background: #fff;
  border-right: 1px solid var(--grid-line);
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-weight: 700;
  font-size: 0.8rem;
  color: #cbd5e0;
  letter-spacing: 2px;
}

.date-col {
  position: sticky;
  left: var(--w-month);
  z-index: 12;
  background: #fff;
  border-right: 1px solid var(--grid-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 10px;
  color: #64748b;
}

.day-name {
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 2px;
}

.day-num {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1;
}

.holiday-label {
  font-size: 0.6rem;
  text-transform: none;
  color: #e11d48;
  margin-top: 6px;
  text-align: center;
  line-height: 1.1;
  font-weight: 700;
  word-wrap: break-word;
  width: 100%;
}

.cell.row-weekend {
  background: #fafafa repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(0, 0, 0, 0.01) 10px,
    rgba(0, 0, 0, 0.01) 20px
  ) !important;
}

.date-col.row-weekend,
.month-col.row-weekend {
  background-color: #f1f5f9 !important;
  color: #94a3b8 !important;
}

.cell.row-holiday {
  background: #fff1f2 repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 5px,
    rgba(225, 29, 72, 0.03) 5px,
    rgba(225, 29, 72, 0.03) 10px
  ) !important;
}

.date-col.row-holiday,
.month-col.row-holiday {
  background-color: #ffe4e6 !important;
  color: #e11d48 !important;
}

.cell.row-new-month {
  border-top: 4px solid #cbd5e0 !important;
}

.date-col.row-new-month,
.month-col.row-new-month {
  border-top: 4px solid #94a3b8 !important;
  background-color: #e2e8f0 !important;
  color: #475569 !important;
}

.cell.row-today {
  background-color: #fffbeb !important;
  border-top: 2px solid #fcd34d !important;
  border-bottom: 2px solid #fcd34d !important;
}

.date-col.row-today,
.month-col.row-today {
  color: #b45309 !important;
  background-color: #fef3c7 !important;
  font-weight: 900 !important;
  border-right: 2px solid #fcd34d !important;
  border-top: 2px solid #fcd34d !important;
}

/* Ferien column (10th column) - same width as day column */
.cell:nth-child(10),
.th:nth-child(10) {
  width: var(--w-day) !important;
  min-width: var(--w-day) !important;
  max-width: var(--w-day) !important;
}

.ferien-cell {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ferien-strip {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.event {
  margin-bottom: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.25;
  border-left: 4px solid #ccc;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: transform 0.1s;
}

.event:active {
  transform: scale(0.98);
}

.ev-time {
  font-weight: 800;
  font-size: 0.75rem;
  margin-right: 4px;
  opacity: 0.8;
}

.is-all-day {
  font-weight: 600;
  border-left-width: 6px;
  padding: 5px 8px;
}

/* MODAL */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: #fff;
  padding: 25px;
  border-radius: 24px;
  width: 95%;
  max-width: 750px;
  box-sizing: border-box;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal h3 {
  margin: 0 0 15px 0;
  font-size: 1.3rem;
  color: #1e293b;
  text-align: center;
}

.form-group {
  margin-bottom: 12px;
  width: 100%;
}

input,
select,
textarea {
  width: 100%;
  box-sizing: border-box !important;
  padding: 12px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  color: #334155;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #94a3b8;
  background: #fff;
}

.modal-btns {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary,
.btn-secondary,
.btn-today,
.btn-danger {
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

.btn-primary {
  background: #0f172a;
  color: white;
  flex: 2;
}

.btn-secondary {
  background: #f1f5f9;
  color: #64748b;
}

.btn-today {
  background: #e67e22;
  color: white;
}

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
}

.form-layout {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

@media (min-width: 600px) {
  .form-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
  }

  .col-span-2 {
    grid-column: span 2;
  }
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  background: #f8fafc;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
}

.checkbox-wrapper input {
  width: auto;
  margin-right: 10px;
}

.checkbox-wrapper label {
  flex: 1;
  font-weight: 600;
  color: #334155;
}

/* Mini Cal */
.mini-cal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 10px;
}

.mini-cal-btn {
  background: #f1f5f9;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-weight: bold;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mini-cal-selects {
  display: flex;
  gap: 5px;
  flex-grow: 1;
  justify-content: center;
}

.mini-cal-selects select {
  padding: 8px;
  font-weight: bold;
  width: auto;
  background: transparent;
  border: none;
  font-size: 1.1rem;
}

.mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.mini-day-head {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 700;
  margin-bottom: 5px;
}

.mini-day {
  height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 5px;
  position: relative;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.1s;
  border: 1px solid transparent;
}

.mini-day:hover {
  background: #f8fafc;
  border-color: #cbd5e0;
  z-index: 10;
}

.mini-day.is-today {
  background: #fcd34d;
  color: #78350f;
  font-weight: bold;
}

.mini-day.is-selected {
  background: #0f172a;
  color: #fff;
}

.mini-day.is-empty {
  cursor: default;
}

.mini-dots-row {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  padding: 0 4px;
}

.mini-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}

.cal-tooltip {
  visibility: hidden;
  opacity: 0;
  width: 200px;
  background-color: #1e293b;
  color: #fff;
  text-align: left;
  border-radius: 8px;
  padding: 10px;
  position: absolute;
  z-index: 100;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  font-size: 0.7rem;
  line-height: 1.4;
  pointer-events: none;
  transition: opacity 0.2s;
}

.cal-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #1e293b transparent transparent transparent;
}

.mini-day:hover .cal-tooltip {
  visibility: visible;
  opacity: 1;
}

.tt-row {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
  align-items: center;
}

.tt-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tt-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

/* Upcoming */
.upcoming-list {
  max-height: 350px;
  overflow-y: auto;
  margin: -10px -10px 0;
  padding: 5px;
}

.up-item {
  display: flex;
  align-items: center;
  background: #f8fafc;
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: transform 0.1s;
}

.up-item:active {
  transform: scale(0.98);
}

.up-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-right: 12px;
  min-width: 45px;
}

.up-d-name {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: #64748b;
  font-weight: 700;
}

.up-d-num {
  font-size: 1.2rem;
  font-weight: 800;
  color: #334155;
  line-height: 1;
}

.up-content {
  flex: 1;
  overflow: hidden;
}

.up-title {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.up-meta {
  font-size: 0.75rem;
  color: #64748b;
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.up-color-strip {
  width: 5px;
  border-radius: 3px;
  height: 35px;
  margin-right: 10px;
}

/* Weather */
#weatherModal .modal-content {
  max-width: 600px;
  padding: 25px;
}

.weather-hourly {
  display: flex;
  overflow-x: auto;
  gap: 15px;
  padding-bottom: 10px;
  margin-bottom: 20px;
  scrollbar-width: thin;
}

.hour-card {
  min-width: 60px;
  text-align: center;
  background: #f8fafc;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.hour-icon {
  font-size: 1.5rem;
  margin: 5px 0;
}

.weather-daily {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 15px;
  background: #fff;
  border-bottom: 1px solid #eee;
}

/* Detail */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 10px;
}

.detail-icon {
  font-size: 3rem;
  line-height: 1;
}

/* Recipes Popup */
.recipes-popup {
  display: none;
  position: fixed;
  top: 80px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1500;
  background: rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(3px);
}

.recipes-popup-content {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.recipes-popup-content iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* =====================
   MOBILE
   ===================== */
@media (max-width: 768px) {

  body {
    overflow: hidden;
  }

  header {
    padding: 0 10px;
    gap: 8px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 75px;
    z-index: 1000;
    display: flex;
    align-items: center;
  }
  
  .header-spacer {
    flex: 1;
    min-width: 10px; /* Less space for mobile */
  }
  
  .header-right {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Hide scrollbar */
    -ms-overflow-style: none; /* IE and Edge */
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 5px; /* Space for hidden scrollbar */
    max-width: 60%; /* Limit width to enable scrolling */
  }
  
  .header-right::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome, Safari and Opera */
  }

  .header-right {
    gap: 8px;
  }
  
  .btn-recipes {
    margin-right: 0;
    display: flex !important; /* Show in mobile too */
  }

  .header-center {
    padding: 8px 14px;
  }

  #clock {
    font-size: 1.15rem;
  }

  #date-text {
    font-size: 0.7rem;
    letter-spacing: 0.5px;
  }

  .calendar-wrapper {
    position: fixed;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: 100vw; /* <-- Sorgt dafür, dass es beim iPad im Hochformat nicht abgeschnitten wird */
  }

  .grid {
    display: grid;
    width: max-content;
    min-width: calc(var(--w-month) + var(--w-day) + 7 * var(--mobile-col-width) + var(--w-day) + var(--mobile-col-width));
    grid-template-columns: var(--w-month) var(--w-day) repeat(7, var(--mobile-col-width)) var(--w-day) var(--mobile-col-width);
    grid-auto-rows: var(--cell-height);
    grid-template-rows: 50px;
  }

 /* Normale Personen-Spalten und Geburtstage (180px) */
  .th:not(:nth-child(-n+2)):not(:nth-child(10)),
  .cell:not(.month-col):not(.date-col):not(:nth-child(10)) {
    width: var(--mobile-col-width);
    min-width: var(--mobile-col-width);
    max-width: var(--mobile-col-width);
  }

  /* Ferien-Spalte (10. Kind) schmal halten wie "Tag" */
  .th:nth-child(10),
  .cell:nth-child(10) {
    width: var(--w-day);
    min-width: var(--w-day);
    max-width: var(--w-day);
  }

  .month-col {
    position: sticky;
    left: 0;
    z-index: 15;
  }

  .date-col {
    position: sticky;
    left: var(--w-month);
    z-index: 15;
  }

  .th:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 30;
    background: #fff;
  }

  .th:nth-child(2) {
    position: sticky;
    left: var(--w-month);
    z-index: 30;
    background: #fff;
  }
}  

/* =====================
   TABLET (Kiosk-Modus an der Wand)
   ===================== */
@media (min-width: 769px) and (max-width: 1550px) {
  .grid {
    /* Hebt die 1500px Mindestbreite wieder auf, damit es exakt auf den Bildschirm passt */
    min-width: 100%;
    
    /* Wir ersetzen das "minmax(170px, 1fr)" durch ein simples "1fr". 
       So werden die Personen-Spalten einfach so schmal wie nötig, um auf 100% Breite zu passen. */
    grid-template-columns: var(--w-month) var(--w-day) repeat(7, 1fr) var(--w-day) 1fr;
  }

  /* Etwas kleinere Schriften und weniger Padding, damit der Text in den schmaleren Spalten (ca. 110px) noch gut aussieht */
  .th {
    font-size: 0.75rem;
    padding: 2px;
  }
  
  .cell {
    padding: 2px;
  }

  .event {
    font-size: 0.7rem;
    padding: 3px 4px;
    border-left-width: 3px; /* Minimal schmalerer Farbstreifen */
  }

  /* Auch die Wochentage minimal anpassen, damit nichts überlappt */
  .day-num {
    font-size: 1.2rem;
  }
}