/* ==========================================================================
   App instalável (PWA): transições, instalação, atualização e conexão
   ========================================================================== */

/* Navegação entre páginas com transição suave, como num app nativo. */
@view-transition { navigation: auto; }

.mobile-nav { view-transition-name: chamix-mobile-nav; }
.sidebar { view-transition-name: chamix-sidebar; }

::view-transition-old(root) { animation: 120ms ease-out both pwa-page-out; }
::view-transition-new(root) { animation: 220ms cubic-bezier(.2, .8, .2, 1) both pwa-page-in; }

@keyframes pwa-page-out { to { opacity: 0; } }
@keyframes pwa-page-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

/* Barra de navegação e toques sem o realce cinza do navegador. */
.mobile-nav, .mobile-nav-item, .sidebar .nav-link { -webkit-tap-highlight-color: transparent; }

@media (display-mode: standalone) {
  .mobile-nav, .sidebar-head, .topbar-main, .nav-label {
    -webkit-user-select: none;
    user-select: none;
  }
}

/* ---------- Contador de pendências na barra inferior ---------- */
.mobile-nav-item[data-pwa-count] { position: relative; }

.mobile-nav-item[data-count]::after {
  content: attr(data-count);
  position: absolute;
  top: .15rem;
  left: calc(50% + 4px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .62rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  animation: pwa-pop 260ms cubic-bezier(.3, 1.5, .5, 1) both;
}

@keyframes pwa-pop { from { transform: scale(.4); opacity: 0; } }

/* ---------- Item "Instalar" no menu lateral ---------- */
.pwa-nav-install {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* ---------- Sem conexão ---------- */
.pwa-offline {
  position: fixed;
  top: calc(env(safe-area-inset-top) + .6rem);
  left: 50%;
  z-index: 190;
  display: flex;
  align-items: center;
  gap: .45rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  padding: .5rem .9rem;
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-size: .78rem;
  font-weight: 650;
  transform: translateX(-50%);
  animation: pwa-drop 240ms ease-out both;
}

.pwa-offline .icon { flex: none; color: var(--warning); }

@keyframes pwa-drop { from { opacity: 0; transform: translate(-50%, -10px); } }

/* ---------- Nova versão ---------- */
.pwa-update {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  width: min(360px, calc(100vw - 1.4rem));
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem .8rem .75rem .85rem;
  border: 1px solid var(--primary-border-soft);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: pwa-rise 260ms cubic-bezier(.2, .8, .2, 1) both;
}

.pwa-update-icon {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
}

.pwa-update-copy { min-width: 0; flex: 1; display: grid; line-height: 1.3; }
.pwa-update-copy strong { color: var(--text); font-size: .84rem; }
.pwa-update-copy span { color: var(--text-soft); font-size: .74rem; }

@keyframes pwa-rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Convite para instalar ---------- */
.pwa-sheet {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  width: min(400px, calc(100vw - 1.4rem));
  padding: 1rem;
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 220ms ease, transform 220ms cubic-bezier(.2, .8, .2, 1);
}

.pwa-sheet.is-open { opacity: 1; transform: none; }

.pwa-sheet-head {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: .8rem;
  align-items: start;
}

.pwa-sheet-icon {
  width: 52px;
  height: 52px;
  padding: 6px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.pwa-sheet-copy { display: grid; gap: .2rem; padding-top: .1rem; }
.pwa-sheet-copy strong { color: var(--text); font-size: .98rem; letter-spacing: -.01em; }
.pwa-sheet-copy span { color: var(--text-soft); font-size: .8rem; line-height: 1.45; }

.pwa-sheet-close { width: 34px; height: 34px; margin: -.25rem -.25rem 0 0; }

.pwa-ios-steps {
  display: grid;
  gap: .55rem;
  margin: .95rem 0 0;
  padding: .8rem;
  border-radius: 12px;
  background: var(--surface-2);
  list-style: none;
  color: var(--text-soft);
  font-size: .8rem;
}

.pwa-ios-steps li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }

.pwa-step-num {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: .68rem;
  font-weight: 800;
}

.pwa-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .15rem .5rem;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.pwa-chip .icon { color: var(--primary); }

.pwa-sheet-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: .55rem;
  margin-top: 1rem;
}

.pwa-sheet-actions .btn { min-height: 46px; justify-content: center; }

.pwa-sheet-icon--bell {
  display: grid;
  place-items: center;
  border-color: var(--primary-border-soft);
  background: var(--primary-soft);
  color: var(--primary);
  animation: pwa-bell 1.2s ease-in-out 400ms 2 both;
}

@keyframes pwa-bell {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(3deg); }
}

/* ---------- Card "Notificações" do perfil ---------- */
.push-state {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .75rem .85rem;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface-2);
}

.push-state > div { min-width: 0; display: grid; gap: .1rem; }
.push-state strong { color: var(--text); font-size: .86rem; }
.push-state small { color: var(--text-soft); font-size: .76rem; line-height: 1.4; }
.push-state small:empty { display: none; }

.push-state-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--border-strong);
}

[data-push-state="on"] .push-state-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 18%, transparent);
}
[data-push-state="denied"] .push-state-dot,
[data-push-state="unsupported"] .push-state-dot { background: var(--danger); }
[data-push-state="needs-install"] .push-state-dot { background: var(--warning); }

.push-eventos {
  display: grid;
  gap: .45rem;
  margin: .9rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--text-soft);
  font-size: .8rem;
}

.push-eventos li { display: flex; align-items: center; gap: .5rem; }
.push-eventos .icon { flex: none; color: var(--primary); }

.push-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .55rem;
  margin-top: 1rem;
}

@media (max-width: 900px) {
  .push-actions .btn { flex: 1 1 140px; min-height: 46px; justify-content: center; }
}

/* ---------- Preferências de notificação (perfil) ---------- */
.push-prefs {
  display: grid;
  gap: .6rem;
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
}

.push-prefs-title,
.push-prefs-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: 0;
  color: var(--text);
  font-size: .8rem;
  font-weight: 800;
}

.push-prefs-title .icon,
.push-prefs-label .icon,
.push-prefs-hint .icon { flex: none; color: var(--primary); }

/* Fora do horário de trabalho o bloco fica esmaecido, mas segue editável. */
.push-expediente {
  display: grid;
  gap: .75rem;
  padding: .8rem .85rem;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface-2);
  transition: opacity 160ms ease;
}

.push-prefs:has(input[name="expediente_ativo"]:not(:checked)) .push-expediente { opacity: .5; }

.push-dias-field {
  display: grid;
  gap: .5rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.push-dias-field legend { padding: 0; margin-bottom: .5rem; }

.push-dias {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.push-dia {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 40px;
  padding: 0 .7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

/* Checkbox nativo escondido só visualmente: continua focável e lido por leitores de tela. */
.push-dia input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.push-dia:hover { border-color: var(--primary-border-soft); color: var(--text); }

.push-dia:has(input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.push-dia:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: var(--shadow-sm);
}

.push-horario {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .6rem;
}

.push-horario .form-field { min-width: 0; }
.push-horario input { min-height: 40px; }

.push-prefs-hint {
  display: flex;
  align-items: flex-start;
  gap: .4rem;
  margin: 0;
  color: var(--text-soft);
  font-size: .74rem;
  line-height: 1.4;
}

.push-prefs-hint .icon { margin-top: .08rem; }

.push-prefs-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: .25rem;
}

@media (max-width: 900px) {
  .push-prefs-actions .btn { flex: 1 1 auto; min-height: 46px; justify-content: center; }
}

/* ---------- Chamado: aviso de notificação silenciosa e opção de notificar ---------- */
.chamado-silenciado {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin: .25rem 0 .75rem;
  padding: .55rem .7rem;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--text-soft);
  font-size: .78rem;
}

.chamado-silenciado .icon { flex: none; color: var(--primary); }

.chamado-notificar-switch { margin-top: .75rem; }

/* No celular, as camadas ficam acima da barra inferior. */
@media (max-width: 900px) {
  .pwa-update,
  .pwa-sheet {
    right: .7rem;
    left: .7rem;
    bottom: calc(64px + 1.1rem + env(safe-area-inset-bottom));
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pwa-sheet, .pwa-update, .pwa-offline, .pwa-sheet-icon--bell, .mobile-nav-item[data-count]::after {
    animation: none;
    transition: none;
  }
}

/* Situação da entrega dos avisos (card "Notificações") */
.push-entrega {
  margin: .55rem 0 0;
  padding: 0 .15rem;
  color: var(--text-soft);
  font-size: .76rem;
  line-height: 1.4;
}

.push-entrega.is-warning { color: var(--warning); font-weight: 600; }
