/* ==========================================================================
   gra-timepicker - seletor de horas por scroll (Frontoffice e Backoffice)
   Carregar depois de cssnovo-style.css. Só usa tokens e classes do DS:
   tokens --color_*, classe .dark-mode (no <body>), fonte de ícones "gra",
   .form-control, .error, .graRequiredField, .graInfoField, .gra-btn
   (+ .btn-primary / .btn-secondary) e .visually-hidden.
   O acento amarelo do Incuba.Açores (FO) vive em incuba-tokens.css.
   ========================================================================== */

/* ---- Campo (mesma construção do .gra-daterangepicker-container do DS) ---- */
.gra-timepicker-container { position: relative; }
.gra-timepicker-container input { padding-left: 40px; }
.gra-timepicker-container:before {
  content: "\e954";                 /* icon-clock da fonte "gra" */
  font-family: gra;
  font-size: 24px;
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color_blue_800);
  pointer-events: none;
}
.dark-mode .gra-timepicker-container:before { color: var(--color_blue_300); }
.gra-timepicker-container.disabled:before { color: var(--color_gray_700); }
.dark-mode .gra-timepicker-container.disabled:before { color: var(--color_gray_300); }
/* Com mensagem de erro/ajuda dentro do contentor o ícone sobe (como no DS). */
.gra-timepicker-container:has(.graRequiredField):before,
.gra-timepicker-container:has(.graInfoField):before { top: 35%; }
.gra-timepicker-container input.focus { border-color: var(--color_blue_500); }
.dark-mode .gra-timepicker-container input.focus { border-color: var(--color_blue_300); }

/* ---- Painel ---------------------------------------------------------------
   Tokens locais (--gra-tp-*) mapeados nos tokens do DS: é aqui que o tema muda. */
.gra-timepicker {
  --gra-tp-bg: #fff;
  --gra-tp-fg: #000;
  --gra-tp-border: var(--color_blue_500);
  --gra-tp-title: var(--color_blue_800);
  --gra-tp-divider: var(--color_blue_200);
  --gra-tp-hover-bg: var(--color_blue_200);
  --gra-tp-hover-fg: var(--color_blue_900);
  --gra-tp-sel-bg: var(--color_blue_800);
  --gra-tp-sel-fg: #fff;
  --gra-tp-off: var(--color_gray_400);
  --gra-tp-link: var(--color_blue_800);
  --gra-tp-link-hover: var(--color_blue_600);
  --gra-tp-focus: #FFCB2D;          /* mesma cor do foco de acessibilidade (.form-accessibility) do DS */
  --gra-tp-row: 40px;               /* altura das linhas do seletor por scroll */

  position: absolute;
  z-index: 3001;                    /* mesma camada do datepicker (.daterangepicker) */
  box-sizing: border-box;
  width: 320px;
  max-width: calc(100vw - 16px);
  margin: 0;
  padding: 16px;
  background-color: var(--gra-tp-bg);
  color: var(--gra-tp-fg);
  border: 1px solid var(--gra-tp-border);
  border-radius: 10px;
  font-family: Lato, sans-serif;
  font-size: 14px;
  line-height: 24px;
  text-align: left;
  overscroll-behavior: contain;
}
.dark-mode .gra-timepicker {
  --gra-tp-bg: #000;
  --gra-tp-fg: #fff;
  --gra-tp-border: var(--color_blue_300);
  --gra-tp-title: var(--color_gray_200);
  --gra-tp-divider: var(--color_gray_800);
  --gra-tp-hover-bg: var(--color_gray_800);
  --gra-tp-hover-fg: #fff;
  --gra-tp-sel-bg: var(--color_gray_200);
  --gra-tp-sel-fg: #000;
  --gra-tp-off: var(--color_gray_700);
  --gra-tp-link: var(--color_gray_200);
  --gra-tp-link-hover: #fff;
}
.gra-timepicker[hidden], .gra-timepicker-mask[hidden] { display: none; }

/* ---- Cabeçalho: título + valor em texto ---- */
.gra-timepicker-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.gra-timepicker-head-main { flex: 1; min-width: 0; }
.gra-timepicker-title { display: block; font-size: 12px; line-height: 16px; font-weight: 700; color: var(--gra-tp-title); }
.gra-timepicker-close { background: none; border: 0; padding: 10px; margin: -8px -10px 0 0; line-height: 1; cursor: pointer; }  /* 44x44 */
.gra-timepicker-display { display: block; margin-top: 2px; font-size: 32px; line-height: 40px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gra-tp-fg); }
.gra-timepicker-sep { padding: 0 2px; font-size: 32px; line-height: 40px; font-weight: 700; color: var(--gra-tp-fg); }

/* ---- Botões ▲▼ ---- */
.gra-timepicker-step {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 4px;
  line-height: 1;
  cursor: pointer;
}
.gra-timepicker-step i { display: block; font-size: 16px; line-height: 16px; }
.gra-timepicker-step:hover:not(:disabled) { background-color: var(--gra-tp-hover-bg); }
.gra-timepicker-step:disabled { opacity: .3; cursor: not-allowed; }
.gra-timepicker :focus-visible { outline: 3px solid var(--gra-tp-focus); outline-offset: 1px; }

/* ---- Colunas roláveis com encaixe (scroll-snap) ---- */
.gra-timepicker-wheels { display: flex; align-items: center; justify-content: center; gap: 2px; }
.gra-timepicker-wheel { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: stretch; }
.gra-timepicker-wheel .gra-timepicker-step { width: 100%; height: 28px; }
.gra-timepicker-wheel-frame { position: relative; }
/* Faixa fixa que marca a linha selecionada (por baixo dos números). */
.gra-timepicker-wheel-band { position: absolute; left: 0; right: 0; top: calc(var(--gra-tp-row) * 2); height: var(--gra-tp-row); border-radius: 4px; background-color: var(--gra-tp-hover-bg); pointer-events: none; }
.gra-timepicker-scroller {
  position: relative;
  box-sizing: border-box;
  height: calc(var(--gra-tp-row) * 5);
  padding: calc(var(--gra-tp-row) * 2) 0;   /* permite centrar a primeira e a última linha */
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;             /* o scroll aqui dentro não arrasta a página */
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28%, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 28%, #000 72%, transparent 100%);
}
.gra-timepicker-scroller::-webkit-scrollbar { display: none; }
.gra-timepicker-wheel-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--gra-tp-row);
  scroll-snap-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--gra-tp-fg);
  cursor: pointer;
  user-select: none;
}
.gra-timepicker-wheel-item.is-selected, .gra-timepicker-wheel-item.is-center { font-size: 18px; font-weight: 700; }
.gra-timepicker-wheel-item.is-disabled { color: var(--gra-tp-off); text-decoration: line-through; cursor: not-allowed; }

/* ---- Rodapé ---- */
.gra-timepicker-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--gra-tp-divider); }
/* "Agora": ligação como o "Hoje" do datepicker (cores equivalentes às de .gra-link; não usa a classe porque ela repõe padding:0). */
.gra-timepicker-now { background: none; border: 0; padding: 12px 0; font: inherit; color: var(--gra-tp-link); text-decoration: underline; cursor: pointer; }
.gra-timepicker-now:hover:not(:disabled) { color: var(--gra-tp-link-hover); }
.gra-timepicker-now:disabled { color: var(--gra-tp-off); text-decoration: none; cursor: not-allowed; }
.gra-timepicker-actions { display: flex; gap: 8px; }
.gra-timepicker-actions .gra-btn { min-width: 0; padding-left: 16px; padding-right: 16px; }

/* ---- Ecrãs pequenos / táteis ---- */
@media (max-width: 575.98px), (pointer: coarse) {
  .gra-timepicker-step { width: 56px; height: 36px; }
  .gra-timepicker-step[data-dir="-1"] { order: -1; }
  .gra-timepicker-step[data-dir="1"] { order: 1; }
  .gra-timepicker { --gra-tp-row: 44px; }
}
/* Folha inferior (como os popups e as notificações do DS). */
.gra-timepicker-mask { position: fixed; inset: 0; z-index: 3000; background: rgba(0, 0, 0, .5); display: none; }
@media (max-width: 575.98px) {
  .gra-timepicker-mask:not([hidden]) { display: block; }
  .gra-timepicker {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
  }
  .gra-timepicker-actions { flex: 1; }
  .gra-timepicker-actions .gra-btn { flex: 1 1 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .gra-timepicker:not([hidden]) { animation: gra-tp-in .12s ease-out; }
  @keyframes gra-tp-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
