/* ==========================================================================
   Janela flutuante para abrir as apps práticas (Contabilização / Salários)
   sem sair da página. Ficheiro independente do style.css principal.
   ========================================================================== */

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  font-family: 'Inter', system-ui, sans-serif;
}

.app-modal[data-open="true"] {
  display: block;
}

.app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 28, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: app-modal-fade 0.15s ease-out;
}

.app-modal-panel {
  position: relative;
  margin: 3vh auto;
  width: min(1240px, 94vw);
  height: 94vh;
  max-height: 94vh;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: app-modal-pop 0.18s ease-out;
}

@keyframes app-modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes app-modal-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.app-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid rgba(15, 20, 28, 0.08);
  background: #ffffff;
  flex: 0 0 auto;
}

.app-modal-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #1b1f27;
}

.app-modal-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.app-modal-openlink,
.app-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #1b1f27;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
}

.app-modal-openlink:hover,
.app-modal-close:hover {
  background: rgba(15, 20, 28, 0.07);
}

.app-modal-body {
  position: relative;
  flex: 1 1 auto;
  background: #f4f5f7;
}

.app-modal-body iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.app-modal-body iframe.is-loaded {
  opacity: 1;
}

.app-modal-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  font-size: 0.9rem;
  gap: 0.5rem;
}

.app-modal-loading::before {
  content: "";
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid rgba(107, 114, 128, 0.3);
  border-top-color: #6b7280;
  animation: app-modal-spin 0.7s linear infinite;
}

@keyframes app-modal-spin {
  to { transform: rotate(360deg); }
}

body.app-modal-open {
  overflow: hidden;
}

/* Tema escuro, seguindo a mesma convenção usada no resto do site
   (data-theme="dark" em <html>). */
[data-theme="dark"] .app-modal-panel {
  background: #171b22;
}

[data-theme="dark"] .app-modal-header {
  background: #171b22;
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .app-modal-header h2 {
  color: #f2f3f5;
}

[data-theme="dark"] .app-modal-openlink,
[data-theme="dark"] .app-modal-close {
  color: #f2f3f5;
}

[data-theme="dark"] .app-modal-openlink:hover,
[data-theme="dark"] .app-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .app-modal-body {
  background: #0e1116;
}

/* Tablets: painel um pouco maior em altura */
@media (max-width: 900px) {
  .app-modal-panel {
    width: 96vw;
    height: 92vh;
  }
}

/* Telemóveis: a janela ocupa o ecrã todo, para a app ter espaço útil */
@media (max-width: 640px) {
  .app-modal-panel {
    margin: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .app-modal-header {
    padding-top: max(0.85rem, env(safe-area-inset-top));
  }

  .app-modal-body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
