/* Agenda (Booking). Só o que o Tailwind não expressa: a geometria da grade
   semanal e o empilhamento em camadas. Ver docs/tailwind-migration-patterns.md */

.bookings-page {
  width: 100%;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

.bookings-page .app-form__form,
.bookings-page .app-form__panel {
  width: 100%;
  max-width: none;
}

.bookings-form {
  width: 100%;
  max-width: 1180px;
}

/* ---------- Grade semanal ---------- */

.bookings-cal-scroll {
  overflow: auto;
  max-height: 70vh;
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  background: #fff;
}

.bookings-cal {
  --bk-row-h: 1.25rem;   /* uma linha = 15 min */
  --bk-gutter: 3.5rem;   /* calha da régua de horas */
  --bk-days: 6;
  --bk-line-soft: #f1f5f9;
  --bk-line-strong: #e2e8f0;

  position: relative;
  display: grid;
  grid-template-columns: var(--bk-gutter) repeat(var(--bk-days), minmax(6.5rem, 1fr));
  /* Linha 1 é o cabeçalho dos dias e dimensiona pelo conteúdo; as linhas
     implícitas (as faixas de 15 min) têm altura fixa. */
  grid-template-rows: auto;
  grid-auto-rows: var(--bk-row-h);
}

/* z-index concentrado aqui de propósito, para não caçar `z-` espalhado no ERB. */
.bookings-cal__corner  { position: sticky; top: 0; left: 0; z-index: 40; background: #fff; }
.bookings-cal__dayhead { position: sticky; top: 0; z-index: 30; background: #fff; }
.bookings-cal__hour    { position: sticky; left: 0; z-index: 20; background: #fff; }
.bookings-cal__slot    { z-index: 0; }
.bookings-cal__block   { z-index: 5; }
.bookings-cal__event   { z-index: 10; }
.bookings-cal__now     { z-index: 15; }

.bookings-cal__corner,
.bookings-cal__dayhead {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--bk-line-strong);
  border-left: 1px solid var(--bk-line-soft);
}

.bookings-cal__dayhead.is-today {
  background: #eff6ff;
  box-shadow: inset 0 -2px 0 0 #1489e5;
}

.bookings-cal__hour {
  grid-column: 1;
  padding-right: 0.5rem;
  text-align: right;
  font-size: 0.6875rem;
  line-height: 1;
  color: #94a3b8;
  border-top: 1px solid var(--bk-line-strong);
}

.bookings-cal__slot {
  border-top: 1px solid var(--bk-line-soft);
  border-left: 1px solid var(--bk-line-soft);
  transition: background-color 120ms ease;
}

/* Cada slot clicável cobre 30 min (2 linhas); a linha da hora cheia é mais forte. */
.bookings-cal__slot.is-hour { border-top-color: var(--bk-line-strong); }
.bookings-cal__slot:hover { background: #eff6ff; }
.bookings-cal__slot.is-off { background: #f8fafc; cursor: default; }
.bookings-cal__slot.is-off:hover { background: #f8fafc; }

.bookings-cal__block {
  margin: 1px;
  border-radius: 0.375rem;
  background: repeating-linear-gradient(45deg, #f1f5f9 0 6px, #e2e8f0 6px 12px);
  pointer-events: none;
}

/* ---------- Evento ---------- */

.bookings-cal__event {
  --bk-lane: 0;
  --bk-lanes: 1;

  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
  overflow: hidden;
  justify-self: start;
  width: calc(100% / var(--bk-lanes) - 2px);
  margin-inline-start: calc(100% / var(--bk-lanes) * var(--bk-lane));
  padding: 0.1875rem 0.375rem;
  border-radius: 0.375rem;
  border-left-width: 3px;
  border-left-style: solid;
  background: #fff;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.08);
  font-size: 0.6875rem;
  line-height: 1.15;
  text-decoration: none;
}

.bookings-cal__event:hover { box-shadow: 0 4px 10px rgb(15 23 42 / 0.12); }

/* Cancelado continua na grade, mas apagado e com a borda tracejada: o
   tracejado diz que aquele horário não está ocupado. Ao passar o mouse volta
   inteiro, para deixar claro que ainda dá para abrir e reabrir. */
.bookings-cal__event.is-cancelled {
  opacity: 0.55;
  background: #f8fafc;
  border-left-style: dashed;
  box-shadow: none;
}

.bookings-cal__event.is-cancelled:hover {
  opacity: 1;
  box-shadow: 0 4px 10px rgb(15 23 42 / 0.12);
}

.bookings-cal__event.is-cancelled .bookings-cal__event-title { text-decoration: line-through; }

.bookings-cal__event-time { font-weight: 600; color: #64748b; }
.bookings-cal__event-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.bookings-cal__more {
  font-size: 0.625rem;
  font-weight: 600;
  color: #64748b;
}

/* ---------- Grade do mês ---------- */

.bookings-month-scroll {
  overflow-x: auto;
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  background: #fff;
}

.bookings-month {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  /* Sete colunas ilegíveis abaixo disso; abaixo da largura, o wrapper rola. */
  min-width: 44rem;
}

.bookings-month__head {
  padding: 0.5rem;
  text-align: center;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  background: #f8fafc;
  border-bottom: 1px solid var(--bk-line-strong, #e2e8f0);
  border-left: 1px solid var(--bk-line-soft, #f1f5f9);
}
.bookings-month__head:first-child { border-left: 0; }

.bookings-month__cell {
  display: flex;
  flex-direction: column;
  gap: 0.1875rem;
  min-height: 7rem;
  padding: 0.375rem;
  border-top: 1px solid var(--bk-line-soft, #f1f5f9);
  border-left: 1px solid var(--bk-line-soft, #f1f5f9);
}
/* Primeira coluna de cada semana sem borda esquerda dupla. */
.bookings-month__cell:nth-child(7n + 1) { border-left: 0; }
.bookings-month__cell.is-outside { background: #f8fafc; }

.bookings-month__cellhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
}

.bookings-month__daynum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
}
.bookings-month__daynum:hover { background: #eff6ff; }
.is-outside .bookings-month__daynum { color: #cbd5e1 !important; }
.bookings-month__daynum.is-today {
  background: #1489e5;
  color: #fff !important;
}
.bookings-month__daynum.is-today:hover { background: #1177c9; }

.bookings-month__chip {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.0625rem 0.125rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  line-height: 1.2;
  text-decoration: none;
}
.bookings-month__chip:hover { background: #f1f5f9; }

.bookings-month__dot {
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
}

.bookings-month__chip-time { font-weight: 600; color: #64748b; }
.bookings-month__chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.bookings-month__more {
  padding-left: 0.125rem;
  font-size: 0.625rem;
  font-weight: 600;
  text-decoration: none;
}
.bookings-month__more:hover { text-decoration: underline; }

@media print {
  .bookings-month-scroll { overflow: visible; border: 0; }
  .bookings-month { min-width: 0; }
}

/* ---------- Arrastar-e-soltar ---------- */

.bookings-cal__event[draggable="true"] { cursor: grab; }
.bookings-cal__event.is-dragging { opacity: 0.4; cursor: grabbing; }

/* Sombra do horário-alvo enquanto se arrasta: mesma geometria do evento. */
.bookings-cal__drop-target {
  z-index: 12;
  margin: 1px;
  border-radius: 0.375rem;
  border: 2px dashed #1489e5;
  background: rgb(20 137 229 / 0.08);
  pointer-events: none;
}

.bookings-cal__feedback {
  position: sticky;
  top: 0;
  z-index: 45;
  margin: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
  font-size: 0.8125rem;
  font-weight: 500;
}
.bookings-cal__feedback.is-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

@media (prefers-reduced-motion: reduce) {
  .bookings-cal__slot { transition: none; }
}

/* ---------- Linha do "agora" ---------- */

.bookings-cal__now {
  position: absolute;
  top: var(--bk-now-top, 0);
  left: var(--bk-gutter);
  right: 0;
  height: 1px;
  background: #f43f5e;
  pointer-events: none;
}

.bookings-cal__now::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -3px;
  width: 7px;
  height: 7px;
  border-radius: 9999px;
  background: #f43f5e;
}

/* ---------- Impressão ---------- */
/* A agenda do dia é impressa no balcão. */
@media print {
  .bookings-cal-scroll { overflow: visible; max-height: none; border: 0; }
  .bookings-cal { --bk-row-h: 1.5rem; }
  .bookings-cal__slot:hover { background: transparent; }
}
