:root {
  --CELL-HEIGHT-SCALE: 1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1f2937;
  background: #f8fafc;
}

h1 {
  margin: 0;
}

/* --------------------------------
   Calendar container
--------------------------------- */

#calendar {
  width: calc(100% - 20px);
  /* max-width: min-content; */
  margin: 40px 10px;
  overflow: hidden;

  -ms-overflow-style: none;
  scrollbar-width: none;

  &::-webkit-scrollbar {
    display: none;
  }
}

.calendar-wrapper {
  width: 100%;
  max-width: max-content;
  margin: 0 auto;

  overflow: scroll;
  -ms-overflow-style: none;
  scrollbar-width: none;

  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);

  &::-webkit-scrollbar {
    display: none;
  }
}

.calendar-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.calendar-header .other-availability {
  color: #555;
  pointer-events: auto;
  background: rgba(150, 150, 150, 0.35);
  border: 1px solid rgba(100, 100, 100, 0.5);
}

/* --------------------------------
   Week header
--------------------------------- */

.week-header {
  position: sticky;
  top: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: 70px repeat(7, minmax(0, 1fr));
  max-width: 100%;

  border-bottom: 1px solid #e5e7eb;
}

.week-header > div {
  z-index: 25;
  min-width: 0;
  padding: 14px 8px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  text-align: center;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
}

.week-header > div:first-child {
  border-left: none;
}

/* --------------------------------
   Calendar body
--------------------------------- */

.calendar-body {
  display: grid;
  grid-template-columns: 70px repeat(7, minmax(0, 1fr));
  width: 100%;
  max-height: 650px;

  -ms-overflow-style: none;
  scrollbar-width: none;

  &::-webkit-scrollbar {
    display: none;
  }
}

/* --------------------------------
   Time column
--------------------------------- */

.time-column {
  position: relative;
  font-size: 11px;
  color: #64748b;
  user-select: none;
  background: #fafafa;
}

.calendar-body > .time-column {
  border-right: 1px solid #e5e7eb;
}

.time-column > div {
  height: calc(60px * var(--CELL-HEIGHT-SCALE, 1));
  padding: 4px 8px 0 0;
  text-align: right;
  border-bottom: 1px solid transparent;
}

/* --------------------------------
   Day columns
--------------------------------- */

.day-column {
  position: relative;
  min-width: 100px;
  height: calc(1440px * var(--CELL-HEIGHT-SCALE, 1));
  touch-action: none;
  cursor: crosshair;
  background-color: #ffffff;
  background-image: linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
  background-size: 100% 60px;
  border-left: 1px solid #e5e7eb;
}

/* Half-hour lines */

.day-column::before {
  position: absolute;

  top: 30px;
  right: 0;
  left: 0;
  height: 1px;

  pointer-events: none;
  content: "";
  background: #f1f5f9;

  box-shadow:
    0 calc(60px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(120px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(180px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(240px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(300px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(360px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(420px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(480px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(540px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(600px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(660px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(720px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(780px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(840px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(900px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(960px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1020px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1080px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1140px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1200px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1260px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1320px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9,
    0 calc(1380px * var(--CELL-HEIGHT-SCALE, 1)) #f1f5f9;
}

/* --------------------------------
   Hover state
--------------------------------- */

.day-column:hover {
  background-color: #fcfdff;
}

/* --------------------------------
   Drag selection
--------------------------------- */

.drag-selection {
  position: absolute;
  right: 3px;
  left: 3px;
  z-index: 5;
  min-height: 4px;
  pointer-events: none;
  background: rgba(59, 130, 246, 0.25);
  border: 1px solid #3b82f6;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(59, 130, 246, 0.15);
}

/* --------------------------------
   Saved available time
--------------------------------- */

.available-time {
  position: absolute;
  right: 3px;
  left: 3px;
  z-index: 10;
  min-height: 20px;
  padding: 5px 7px;
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: #1b991b;
  cursor: pointer;
  user-select: none;
  background: #e2fee2;
  border: 1px solid #a5fca5;
  border-left: 4px solid #44ef44;
  border-radius: 4px;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;

  &.leader-availability,
  &.other-availability {
    pointer-events: none;
    opacity: 0.5;
  }

  &:not(.leader-availability, .other-availability) {
    z-index: 20;
  }

  &.leader-availability {
    color: #991b99;
    background: #fee2fe;
    border: 1px solid #fca5fc;
    border-left: 4px solid #ef44ef;
  }

  &.other-availability {
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #fca5a5;
    border-left: 4px solid #ef4444;
  }
}

.available-time:hover {
  background: #cafeca;
  border-color: #71f871;
  box-shadow: 0 2px 5px rgba(68, 239, 68, 0.15);

  &.leader-availability {
    background: #fecafe;
    border-color: #f871f8;
    box-shadow: 0 2px 5px rgba(239, 68, 239, 0.15);
  }

  &.other-availability {
    background: #fecaca;
    border-color: #f87171;
    box-shadow: 0 2px 5px rgba(239, 68, 68, 0.15);
  }
}

/* Time text inside saved block */

.available-time .time {
  display: block;
  white-space: nowrap;
}

/* Optional label */

.available-time .label {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 500;
  color: #1cb91c;
  white-space: nowrap;
}

/* --------------------------------
   Delete button
--------------------------------- */

.available-time .delete-button {
  position: absolute;
  top: 3px;
  right: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 16px;
  color: #1b991b;
  cursor: pointer;
  background: transparent;
  border: none;
  border-radius: 4px;
  opacity: 0;

  transition:
    opacity 0.15s ease,
    background-color 0.15s ease;
}

.available-time:hover .delete-button,
.available-time:focus-within .delete-button {
  opacity: 1;
}

.available-time .delete-button:hover {
  background: rgba(27, 153, 27, 0.1);
}

/* --------------------------------
   Current time indicator
--------------------------------- */

.current-time-line {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 15;
  height: 2px;
  pointer-events: none;
  background: #44ef44;
}

.current-time-line::before {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 10px;
  height: 10px;
  content: "";
  background: #44ef44;
  border-radius: 50%;
}

/* --------------------------------
   Today's column
--------------------------------- */

.day-column.today {
  background-color: #f8fbff;
}

.week-header > div.today {
  color: #2563eb;
  background: #eff6ff;
}

/* --------------------------------
   Selected day
--------------------------------- */

.day-column.selected {
  background-color: #f8fbff;

  box-shadow:
    inset 2px 0 #3b82f6,
    inset -2px 0 #3b82f6;
}

/* --------------------------------
   Dragging state
--------------------------------- */

#calendar.is-dragging {
  user-select: none;
}

#calendar.is-dragging .day-column {
  cursor: crosshair;
}

#calendar.is-dragging .available-time {
  pointer-events: none;
}

/* --------------------------------
   Buttons
--------------------------------- */

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.35);
  outline-offset: 2px;
}

/* --------------------------------
   Mobile
--------------------------------- */

@media (max-width: 768px) {
  #calendar {
    margin: 20px 10px;
    border-radius: 8px;
  }

  .week-header,
  .calendar-body {
    grid-template-columns: 55px repeat(7, minmax(90px, 1fr));
  }

  .week-header > div {
    padding: 10px 4px;
    font-size: 12px;
  }

  .time-column > div {
    padding-right: 5px;
    font-size: 10px;
  }

  .day-column {
    min-width: 90px;
  }

  .available-time {
    right: 2px;
    left: 2px;
    padding: 4px;
    font-size: 11px;
  }
}

@media (max-height: 700px) {
  .calendar-body {
    max-height: 450px;
  }
}

/* --------------------------------
   Reduced motion
--------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .available-time,
  .delete-button {
    transition: none;
  }
}
