:root {
  --navy: #0D3B66;
  --navy-dark: #092944;
  --orange: #EE6C4D;
  --orange-dark: #d4573a;
  --teal: #1B998B;
  --teal-dark: #147a6f;
  --bg: #F5F7F9;
  --text: #1C2B36;
  --white: #FFFFFF;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* iOS: esclude le barre di Safari dal calcolo */
}

/* HEADER */
.app-header {
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  box-shadow: 0 2px 8px rgba(9, 41, 68, 0.25);
  position: sticky;
  top: 0;
  z-index: 10;
  text-align: center;
}

.app-header center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.app-header img.logo {
  height: 42px;
  width: 42px;
  border-radius: 10px;
  background: var(--white);
  object-fit: contain;
  padding: 3px;
  flex-shrink: 0;
}

.app-header .title-block {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
}

.app-header .title-block strong {
  font-size: 1.05rem;
  letter-spacing: 0.2px;
}

.app-header .title-block span {
  font-size: 0.75rem;
  color: #B9CBDD;
}

/* HOME BUTTON GRID */
main {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 16px;
}

.grid {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: 14px;
  height: auto;
  margin: auto 0;
}

.tile-wide {
  grid-column: 1 / -1;
}

.tile {
  border: none;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  padding: 18px 10px;
  cursor: pointer;
  color: var(--white);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  min-height: 120px;
}

.tile:active {
  transform: scale(0.97);
}

.tile svg {
  width: 34px;
  height: 34px;
}

.tile-navy { background: linear-gradient(160deg, var(--navy), var(--navy-dark)); }
.tile-orange { background: linear-gradient(160deg, var(--orange), var(--orange-dark)); }
.tile-teal { background: linear-gradient(160deg, var(--teal), var(--teal-dark)); }

/* SUBPAGES */
.page {
  flex: 1;
  padding: 24px 20px 90px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* PAGINE CON CONTENUTO INCORNICIATO DAL SITO (iframe) */
.embed-bar {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid rgba(13, 59, 102, 0.08);
}

.embed-bar .back-link {
  margin-bottom: 0;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Pagine iframe: altezza bloccata allo schermo, scorre solo l'iframe (fix iOS) */
body.embed-body {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.embed-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--white);
}

.embed-frame {
  min-height: calc(100dvh - 120px);
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.embed-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 2;
  transition: opacity 0.25s ease;
}

.embed-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.embed-loader span {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 4px solid rgba(13, 59, 102, 0.15);
  border-top-color: var(--navy);
  animation: msp-spin 0.8s linear infinite;
}

.embed-error {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

.embed-error p {
  margin: 0 0 16px;
  color: var(--navy-dark);
  font-weight: 600;
  line-height: 1.4;
}

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

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--navy);
  text-decoration: none;
  font-weight: 600;
  margin-bottom: 18px;
  font-size: 0.95rem;
}

.page h1 {
  margin-top: 0;
  color: var(--navy-dark);
}

.placeholder-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  color: #45525c;
  line-height: 1.5;
  margin-bottom: 14px;
}

.placeholder-box strong {
  color: var(--navy-dark);
}

.cta-btn {
  display: block;
  text-align: center;
  background: linear-gradient(160deg, var(--orange), var(--orange-dark));
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  padding: 15px 20px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(238, 108, 77, 0.35);
  margin-bottom: 14px;
}

.cta-btn:active {
  transform: scale(0.98);
}

.text-link {
  display: block;
  text-align: center;
  color: var(--navy);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

/* BOTTONE INSTALLA APP (flottante, centro) */
#install-app-btn {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--orange);
  color: var(--white);
  border: none;
  padding: 13px 24px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  z-index: 50;
  cursor: pointer;
}

#install-app-btn:active {
  transform: translateX(-50%) scale(0.96);
}

/* BOTTONE FLOTTANTE WHATSAPP (FAB, angolo in basso a destra) */
#whatsapp-float-btn {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: #25D366;
  color: #06301A;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  z-index: 50;
}

#whatsapp-float-btn:active {
  transform: scale(0.94);
}

#whatsapp-float-btn svg {
  width: 26px;
  height: 26px;
}

/* BANNER ISTRUZIONI IOS */
#ios-install-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 41, 68, 0.55);
  z-index: 99;
}

#ios-install-banner {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 420px;
  background: var(--navy);
  color: var(--white);
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px 20px 0 0;
  padding: 22px 22px max(22px, env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
}

#ios-install-banner strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 14px;
}

#ios-install-banner .ios-step {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  line-height: 1.3;
}

#ios-install-banner .ios-note {
  font-size: 0.82rem;
  color: #B9CBDD;
  line-height: 1.35;
  margin-top: 4px;
}

#ios-install-banner .ios-step svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--orange);
}

#ios-install-banner b {
  color: var(--orange);
}

#ios-install-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

/* PANNELLO DIAGNOSI (?debug=1) */
#msp-debug {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 84px;
  max-height: 45vh;
  overflow: auto;
  background: rgba(0, 0, 0, 0.85);
  color: #9ef59e;
  border-radius: 10px;
  padding: 10px;
  z-index: 200;
  font: 11px/1.35 ui-monospace, Menlo, monospace;
}
#msp-debug pre { margin: 0; white-space: pre-wrap; word-break: break-all; }
#msp-debug-copy {
  float: right;
  background: var(--orange);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 700;
}

/* NEWS E COMUNICAZIONI (elenco articoli WordPress) */
.news-page {
  display: block;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 100px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.news-title {
  margin: 0 0 14px;
  font-size: 1.3rem;
  color: var(--navy-dark);
}
.news-list { display: flex; flex-direction: column; gap: 12px; }
.news-card {
  display: flex;
  gap: 12px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(13, 59, 102, 0.08);
  padding: 12px;
  text-decoration: none;
  color: var(--text);
  border-left: 4px solid var(--orange);
  transition: transform 0.12s ease;
}
.news-card:active { transform: scale(0.98); }
.news-thumb {
  width: 84px;
  height: 84px;
  flex: 0 0 84px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg);
}
.news-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.news-body time {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--orange-dark);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.news-body strong { color: var(--navy-dark); line-height: 1.3; font-size: 0.98rem; }
.news-body p { margin: 0; font-size: 0.85rem; line-height: 1.4; color: #4a5a66; }
.news-loading { display: flex; justify-content: center; padding: 40px 0; }
.news-loading span {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid rgba(13, 59, 102, 0.15);
  border-top-color: var(--navy);
  animation: msp-spin 0.8s linear infinite;
}
.news-empty { text-align: center; padding: 40px 12px; }
.news-empty p { margin: 0 0 16px; color: var(--navy-dark); font-weight: 600; line-height: 1.4; }
