/**
 * High 5 Connect CRM — V2 Calendar Styles
 * Month, week, and day views with continuous Gantt bars.
 */

/* ─── Calendar Page ─────────────────────────────────────────── */
.calendar-page {
  padding: var(--s4);
  height: calc(100dvh - var(--topbar-height, 56px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.calendar-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  min-width: 160px;
  text-align: center;
}

.calendar-controls {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.calendar-view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: var(--r-md);
  padding: 2px;
}

.calendar-filter {
  max-width: 160px;
  font-size: var(--text-sm);
  padding: var(--s1) var(--s2);
}

.calendar-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ─── Month View ──────────────────────────────────────────── */
.cal-month {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-card);
}

.cal-month-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--bg-page);
  border-bottom: 2px solid var(--border);
}

.cal-day-name {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-label);
  text-align: center;
  padding: var(--s2) var(--s1);
  letter-spacing: 0.5px;
}

/* ─── Week Row (one row of the month grid) ──────────────── */
.cal-week-row {
  display: flex;
  flex-direction: column;
  position: relative;
  border-bottom: 1px solid var(--border);
  flex: 1 0 auto;
}

.cal-week-row:last-child {
  border-bottom: none;
}

/* Day number cells row */
.cal-week-row > .cal-cells-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
}

.cal-cell {
  border-right: 1px solid var(--border);
  padding: 4px var(--s1);
  min-height: 32px;
  position: relative;
  overflow: visible;
  transition: background var(--t-fast);
}

.cal-cell:last-child {
  border-right: none;
}

.cal-cell-empty {
  background: var(--bg-page);
  opacity: 0.5;
}

.cal-cell-today {
  background: color-mix(in srgb, var(--accent) 6%, var(--bg-card));
}

.cal-cell-num {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--r-full);
}

.cal-today-num {
  background: var(--accent);
  color: var(--text-inverse);
}

/* ─── Drag & Drop ─────────────────────────────────────────── */
.cal-cell.drag-over {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ─── Bar Area (directly below day numbers, flush with top) */
.cal-bar-area {
  position: relative;
  pointer-events: none;
  margin: 0;
  padding: 2px 0 0;
  overflow: visible;
}

/* Vertical grid lines in bar area — matches 7-column day cells */
.cal-bar-area::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(100% / 7 - 1px),
    var(--border) calc(100% / 7 - 1px),
    var(--border) calc(100% / 7)
  );
  z-index: 1;
}

/* ─── Gantt Bars (multi-day work orders) ─────────────────── */
.gantt-bar {
  position: absolute;
  height: 20px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--bar-color) 55%, white);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 20px;
  padding: 0 6px;
  cursor: pointer;
  pointer-events: auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-sizing: border-box;
  transition: filter var(--t-fast);
  z-index: 3;
}

.gantt-bar:hover {
  filter: brightness(1.08);
  z-index: 10;
}

/* Continuation classes — flatten edges when bar spans across week rows */
.gantt-bar.bar-start {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.gantt-bar.bar-end {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.gantt-bar.bar-mid {
  border-radius: 0;
}

/* ─── Soft variant: light bar + dark tip on left ─────────
   Used by Job Schedule blocks so they read like an oversized
   gantt-single pill. Same pattern as Follow-up / Setmore events.
   Override the solid fill + white text from .gantt-bar above. */
.gantt-bar.gantt-bar-soft {
  background: color-mix(in srgb, var(--bar-color) 15%, transparent);
  border-left: 3px solid color-mix(in srgb, var(--bar-color) 70%, white);
  color: var(--bar-color);
}

.gantt-bar.gantt-bar-soft:hover {
  background: color-mix(in srgb, var(--bar-color) 25%, transparent);
  filter: none;
}

/* When a soft bar spans week rows, only show the dark tip on the
   FIRST week segment — middle/end segments are seamless light bar. */
.gantt-bar.gantt-bar-soft.bar-mid,
.gantt-bar.gantt-bar-soft.bar-end {
  border-left: none;
}

/* ─── Single-day items (follow-ups, tasks) ───────────────── */
.gantt-single {
  position: absolute;
  height: 20px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--bar-color) 15%, transparent);
  border-left: 3px solid color-mix(in srgb, var(--bar-color) 70%, white);
  color: var(--bar-color);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 20px;
  padding: 0 6px;
  cursor: pointer;
  pointer-events: auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-sizing: border-box;
  transition: background var(--t-fast);
  z-index: 3;
}

.gantt-single:hover {
  background: color-mix(in srgb, var(--bar-color) 25%, transparent);
  z-index: 10;
}

/* Bar label text */
.bar-label {
  pointer-events: none;
}

/* ─── Week View ──────────────────────────────────────────── */
.cal-week {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  min-height: 400px;
  background: var(--bg-card);
}

.cal-week-header-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 2px solid var(--border);
  background: var(--bg-page);
}

.cal-week-header-cell {
  text-align: center;
  padding: var(--s2) var(--s1);
  border-right: 1px solid var(--border);
}

.cal-week-header-cell:last-child {
  border-right: none;
}

.cal-week-header-cell.cal-cell-today {
  background: color-mix(in srgb, var(--accent) 6%, var(--bg-card));
}

.cal-week-day {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-label);
  display: block;
}

.cal-week-num {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.cal-week-bar-area {
  position: relative;
  background: var(--bg-card);
  padding-top: var(--s1);
}

/* Week view bars inherit same styles as month bars, just taller */
.cal-week-bar-area .gantt-bar {
  height: 24px;
  line-height: 24px;
  font-size: 0.72rem;
}

.cal-week-bar-area .gantt-single {
  height: 24px;
  line-height: 24px;
  font-size: 0.72rem;
}

/* ─── Day View ───────────────────────────────────────────── */
.cal-day {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  max-width: 600px;
}

.cal-day-event {
  display: flex;
  align-items: stretch;
  cursor: pointer;
  overflow: hidden;
}

.cal-day-event:hover {
  box-shadow: var(--shadow-md);
}

.cal-day-event-color {
  width: 5px;
  flex-shrink: 0;
  background: var(--bar-color);
  border-radius: var(--r-sm) 0 0 var(--r-sm);
}

.cal-day-event-body {
  padding: var(--s3) var(--s4);
  flex: 1;
}

.cal-day-event-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

.cal-day-event-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--s1);
}

.cal-day-event-cat {
  font-size: var(--text-xs);
  color: var(--text-label);
  text-transform: uppercase;
  margin-top: var(--s1);
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .calendar-page {
    padding: var(--s2) 0;
    height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top) - var(--bottomnav-height));
  }

  .calendar-toolbar {
    flex-direction: column;
    align-items: center;
    gap: var(--s2);
    padding: 0 var(--s3);
    margin-bottom: var(--s2);
  }

  .calendar-nav {
    justify-content: center;
  }

  .calendar-controls {
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Hide Day/Week/Month toggle — Month is best for mobile */
  .calendar-view-toggle {
    display: none;
  }

  /* Full-width calendar grid */
  .cal-month {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .cal-cell {
    min-height: 0;
    aspect-ratio: 1;
    padding: 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .cal-cell-num {
    font-size: 12px;
    width: 22px;
    height: 22px;
    line-height: 22px;
  }

  .gantt-bar,
  .gantt-single {
    height: 18px;
    line-height: 18px;
    font-size: 10px;
    padding: 0 4px;
  }

  .cal-bar-area .gantt-bar,
  .cal-bar-area .gantt-single {
    height: 18px;
    line-height: 18px;
  }

  .cal-week {
    min-height: 300px;
  }

  .cal-week-header-cell {
    padding: var(--s1);
  }

  .cal-week-day {
    font-size: 10px;
  }

  .cal-week-num {
    font-size: var(--text-base);
  }

  .cal-week-bar-area .gantt-bar,
  .cal-week-bar-area .gantt-single {
    height: 20px;
    line-height: 20px;
    font-size: 11px;
  }
}
