/* =============================================================
   Brotas Beauty - tela da agenda (item 4).

   Visões: dia e semana em grade de horários com uma coluna por
   profissional; mês em calendário; e lista de atendimentos.
   ============================================================= */

:root {
  /* Altura de uma hora na grade. Também usada pelo JavaScript para
     posicionar os cartões, então os dois precisam concordar. */
  --hour-height: 52px;
  --time-col: 54px;
}

/* ---------------------------------------------------------------
   Barra de controles
   --------------------------------------------------------------- */
.agenda-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 0;
  padding: 0;
}

.agenda-period {
  display: flex;
  align-items: center;
  gap: 6px;
}

.period-label {
  min-width: 175px;
  font-size: .86rem;
  font-weight: 600;
  text-transform: capitalize;
}

/* Alternador Dia / Semana / Mês / Lista */
.view-switch {
  display: inline-flex;
  padding: 2px;
  background: #f1ede9;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.switch-btn {
  min-height: 28px;
  padding: 4px 10px;
  background: none;
  border: 0;
  border-radius: 2px;
  color: var(--ink-soft);
  font: inherit;
  font-size: .76rem;
  cursor: pointer;
}

.switch-btn:hover { color: var(--ink); }

.switch-btn.active {
  background: #ff7b42;
  box-shadow: var(--shadow);
  color: #fff;
  font-weight: 600;
}

.agenda-filters,
.agenda-side {
  display: grid;
  gap: 9px;
  align-items: stretch;
  margin-bottom: 10px;
}

#view-agenda {
  display: none;
}

#view-agenda.active {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  grid-template-areas:
    "filters toolbar"
    "filters content"
    "legend content";
  gap: 0;
  height: calc(100dvh - var(--topbar-h));
  min-height: 0;
}

#view-agenda .agenda-toolbar {
  grid-area: toolbar;
  min-height: 55px;
  padding: 8px 10px;
  background: #fff;
  border: 0;
  border-bottom: 1px solid #d7d1cc;
  border-left: 1px solid #d7d1cc;
  border-radius: 0;
}
#view-agenda .agenda-side {
  grid-area: filters;
  align-self: start;
  height: 100%;
  padding: 24px 15px 12px;
  background: #fff;
  border: 0;
  border-right: 1px solid #d7d1cc;
  border-radius: 0;
  overflow-y: auto;
}
#view-agenda #agenda-content {
  grid-area: content;
  min-width: 0;
  min-height: 0;
}
#view-agenda .agenda-legend {
  grid-area: legend;
  align-self: start;
  margin: 0;
  border-right: 1px solid #d7d1cc;
}

#view-agenda .agenda-side select,
#view-agenda .agenda-side input {
  min-height: 34px;
  font-size: .82rem;
}

.agenda-mini-calendar {
  padding: 8px 10px 12px;
  background: #fff;
  border: 1px solid #bfb7b1;
  border-radius: 5px;
}

.mini-cal-head {
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  align-items: center;
  margin-bottom: 8px;
  color: #706964;
  font-size: .78rem;
  text-align: center;
}

.mini-cal-head button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: 0;
  color: #9b938d;
  font: inherit;
  font-size: 1.1rem;
  cursor: pointer;
}

.mini-cal-week,
.mini-cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.mini-cal-week span {
  color: #6f6862;
  font-size: .62rem;
  text-align: center;
  text-transform: lowercase;
}

.mini-cal-days button {
  display: grid;
  place-items: center;
  min-width: 0;
  height: 24px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  color: #6a625d;
  font: inherit;
  font-size: .67rem;
  cursor: pointer;
}

.mini-cal-days button:hover {
  border-color: #f29a67;
  color: var(--brand-dark);
}

.mini-cal-days button.other {
  color: #bbb4af;
}

.mini-cal-days button.active {
  border-color: #f29a67;
  color: var(--brand-dark);
  font-weight: 700;
}

#view-agenda .agenda-side .search-input,
#view-agenda .agenda-side .select-inline {
  width: 100%;
  margin: 0;
  border-color: #bfb7b1;
  border-radius: 0;
  box-shadow: none;
}

#view-agenda .agenda-side .search-input {
  margin-top: 11px;
  border-radius: 5px 5px 0 0;
}

#view-agenda .agenda-side .select-inline + .select-inline,
#view-agenda .agenda-side .search-input + .select-inline {
  border-top: 0;
}

#view-agenda .agenda-side #agenda-clear {
  justify-content: flex-start;
  min-height: 36px;
  margin-top: 8px;
  color: #8c817a;
  border-color: #c8c0ba;
  border-radius: 5px;
}

/* ---------------------------------------------------------------
   Grade de horários (dia e semana)
   --------------------------------------------------------------- */
.agenda-grid {
  background: var(--surface);
  border: 0;
  border-left: 1px solid #d7d1cc;
  border-radius: 0;
  box-shadow: none;
  overflow: auto;
  height: 100%;
  max-height: none;
}

/* Cabeçalho com os nomes dos profissionais (ou dos dias). */
.grid-head {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8f8f6;
  border-bottom: 1px solid #c7c0bb;
}

.grid-head .corner {
  width: var(--time-col);
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 4;
  background: #f8f8f6;
  border-right: 1px solid #c7c0bb;
}

.grid-col-head {
  flex: 1;
  min-width: 138px;
  padding: 6px 7px;
  text-align: center;
  border-left: 1px solid #cfc8c3;
}

.grid-col-head .name {
  font-size: .74rem;
  font-weight: 600;
}

.grid-col-head .sub {
  color: var(--ink-soft);
  font-size: .68rem;
}

/* Dia de hoje ganha destaque na visão semanal. */
.grid-col-head.today .name { color: var(--brand); }
.grid-col-head.today { background: var(--brand-soft); }

.grid-body {
  display: flex;
  position: relative;
}

/* Coluna das horas, fixa na rolagem horizontal. */
.time-col {
  width: var(--time-col);
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 2;
  background: #faf9f8;
  border-right: 1px solid var(--line);
}

.time-slot {
  height: var(--hour-height);
  padding: 2px 7px 0 0;
  color: #655d57;
  font-size: .66rem;
  text-align: right;
  border-bottom: 1px solid #d2ccc8;
}

.grid-col {
  flex: 1;
  min-width: 138px;
  position: relative;
  border-left: 1px solid #d2ccc8;
}

/* Faixa clicável de cada hora: clicar cria agendamento (item 5). */
.hour-cell {
  height: var(--hour-height);
  border-bottom: 1px solid #d2ccc8;
  cursor: pointer;
  transition: background .12s;
}

.hour-cell:hover { background: var(--brand-soft); }

/* Meia hora marcada com linha mais clara, para orientar o olho. */
.hour-cell::after {
  content: "";
  display: block;
  height: 50%;
  border-bottom: 1px dashed rgba(184, 176, 170, .55);
}

/* Faixa fora do expediente fica riscada e não recebe clique. */
.hour-cell.closed {
  background: repeating-linear-gradient(
    45deg, transparent, transparent 6px,
    rgba(154, 147, 161, .07) 6px, rgba(154, 147, 161, .07) 12px
  );
  cursor: not-allowed;
}
.hour-cell.closed:hover { background-color: transparent; }

/* ---------------------------------------------------------------
   Cartão do agendamento
   --------------------------------------------------------------- */
.appt {
  position: absolute;
  left: 3px;
  right: 3px;
  padding: 4px 5px;
  border-left: 4px solid var(--brand);
  border-radius: 3px;
  background: var(--surface);
  box-shadow: 0 1px 5px rgba(60, 52, 48, .25);
  font-size: .69rem;
  line-height: 1.16;
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
  transition: box-shadow .12s, transform .12s;
}

.appt:hover {
  box-shadow: 0 3px 9px rgba(60, 52, 48, .32);
  transform: translateY(-1px);
  z-index: 2;
}

.appt .appt-time {
  font-size: .62rem;
  font-weight: 600;
  opacity: .9;
}

.appt .appt-client {
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appt .appt-service,
.appt .appt-info {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .92;
}

/* Cartão curto esconde o que não cabe, para não estourar a altura. */
.appt.short .appt-service,
.appt.short .appt-info { display: none; }
.appt.short { padding: 2px 6px; }

/* Cores por situação (item 4). Mesmos tons da legenda em agenda.js:
   azul enquanto está por vir, amarelo/laranja enquanto acontece,
   verde quando termina bem, vermelho/cinza quando não acontece.
   A faixa da esquerda continua com a cor da profissional. */
.appt.st-agendado              { background: #76a9e8; }
.appt.st-confirmado            { background: #65bd12; color: #fff; }
.appt.st-chegou                { background: #f0b42f; }
.appt.st-em_atendimento        { background: #f28b35; }
.appt.st-aguardando_fechamento { background: #a982e0; color: #fff; }
.appt.st-finalizado            { background: #20976a; color: #fff; }
.appt.st-cancelado             { background: #a99eb2; opacity: .9; text-decoration: line-through; }
.appt.st-faltou                { background: #cf3b52; color: #fff; opacity: .94; }
.appt.st-estornado             { background: #a88778; color: #fff; opacity: .9; }

.appt.st-confirmado .appt-client,
.appt.st-aguardando_fechamento .appt-client,
.appt.st-finalizado .appt-client,
.appt.st-faltou .appt-client,
.appt.st-estornado .appt-client {
  color: #fff;
}

.agenda-cancel-alert {
  margin: 0 0 10px;
  border: 1px solid var(--danger);
  border-left: 4px solid var(--danger);
  border-radius: 3px;
  background: var(--danger-bg);
  overflow: hidden;
}

.agenda-cancel-alert > button {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  color: #8e2132;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.agenda-cancel-details {
  display: grid;
  gap: 6px;
  padding: 0 12px 10px;
  color: var(--ink);
  font-size: .84rem;
}

.agenda-cancel-details span {
  display: block;
  color: var(--ink-soft);
}

/* ---------------------------------------------------------------
   Visão de mês
   --------------------------------------------------------------- */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(60, 52, 48, .12);
}

.month-head {
  padding: 8px 6px;
  background: var(--brand-soft);
  color: var(--ink-soft);
  font-size: .74rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
}

.month-day {
  min-height: 104px;
  padding: 5px 6px;
  background: var(--surface);
  cursor: pointer;
  transition: background .12s;
}

.month-day:hover { background: var(--brand-soft); }
.month-day.other-month { background: #fbfafc; color: var(--ink-faint); }
.month-day.today { box-shadow: inset 0 0 0 2px var(--brand); }

.month-day .day-number {
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: 3px;
}

.month-day.today .day-number { color: var(--brand); }

.month-appt {
  padding: 2px 5px;
  margin-bottom: 2px;
  border-left: 3px solid var(--brand);
  border-radius: 3px;
  background: var(--brand-soft);
  font-size: .7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-more {
  color: var(--ink-soft);
  font-size: .68rem;
  font-weight: 600;
}

/* ---------------------------------------------------------------
   Legenda de cores
   --------------------------------------------------------------- */
.agenda-legend {
  display: grid;
  gap: 7px;
  margin-top: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 0;
  border-top: 1px solid #d7d1cc;
  border-radius: 0;
  font-size: .7rem;
}

.agenda-legend::before {
  content: "Status";
  color: #6b625d;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
}

/* Cor cheia: com o tom claro do cartão a bolinha some no branco. */
.legend-dot {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  flex-shrink: 0;
}

.agenda-legend .legend-item { color: var(--ink); }

/* ---------------------------------------------------------------
   Horários sugeridos quando dá conflito (item 11)
   --------------------------------------------------------------- */
.slot-suggestions {
  margin-top: 10px;
  padding: 11px 13px;
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
}

.slot-suggestions .title {
  margin-bottom: 8px;
  font-size: .82rem;
  font-weight: 600;
  color: #8a5f10;
}

.slot-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.slot-chip {
  min-height: 34px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  color: #8a5f10;
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
}

.slot-chip:hover { background: var(--warn); color: #fff; }

/* ---------------------------------------------------------------
   Campo com botão "+" de cadastro rápido (item 6)
   --------------------------------------------------------------- */
.field-with-add {
  display: flex;
  align-items: flex-end;
  gap: 7px;
}

.field-with-add .field {
  flex: 1;
  margin-bottom: 0;
}

/* ---------------------------------------------------------------
   Campo de pesquisa com lista de resultados
   --------------------------------------------------------------- */
.combo-results {
  position: relative;
  z-index: 5;
  max-height: 230px;
  margin-top: -8px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}

.combo-item {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.combo-item:last-child { border-bottom: 0; }
.combo-item:hover,
.combo-item.active { background: var(--brand-soft); }

.combo-label {
  display: block;
  font-size: .9rem;
  font-weight: 600;
}

.combo-sub {
  display: block;
  color: var(--ink-soft);
  font-size: .76rem;
}

.combo-empty {
  padding: 12px;
  color: var(--ink-soft);
  font-size: .84rem;
  text-align: center;
}

/* ---------------------------------------------------------------
   Celular
   --------------------------------------------------------------- */
@media (max-width: 720px) {
  #view-agenda {
    display: block;
  }

  #view-agenda .agenda-side,
  #view-agenda .agenda-legend {
    margin-bottom: 10px;
  }

  .agenda-toolbar,
  .agenda-filters,
  .agenda-side { gap: 7px; }

  .period-label {
    order: -1;
    width: 100%;
    min-width: 0;
    text-align: center;
  }

  .view-switch { width: 100%; }
  .switch-btn { flex: 1; }

  .agenda-filters .select-inline,
  .agenda-filters .search-input,
  .agenda-side .select-inline,
  .agenda-side .search-input { flex: 1; min-width: 130px; }

  .agenda-grid { max-height: calc(100dvh - 270px); }

  .grid-col,
  .grid-col-head { min-width: 118px; }

  .month-day { min-height: 74px; padding: 3px; }
  .month-day .day-number { font-size: .74rem; }
  .month-appt { font-size: .62rem; padding: 1px 3px; }
}
