* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body.mobile-app {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1a1a1a;
  background: #eef2ee;
}

.m-app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

.m-header {
  background: linear-gradient(160deg, #1a5f2a 0%, #2d8a42 100%);
  color: #fff;
  padding: max(16px, env(safe-area-inset-top)) 18px 20px;
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  border-radius: 0 0 20px 20px;
  box-shadow: 0 4px 16px rgba(26, 95, 42, 0.25);
}

.m-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.m-header h1 {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
}

.m-sub {
  font-size: 14px;
  opacity: 0.95;
}

.req { color: #ffd0d0; font-weight: 700; }
.m-sub .req { color: #ffe0e0; }

.confirm-preview {
  background: #f7faf7;
  border: 2px solid #d0d8d0;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.m-autofill-trap {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.m-form {
  position: relative;
  padding: 14px 14px 0;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

.m-card {
  background: #fff;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.m-card-title {
  font-size: 16px;
  font-weight: 800;
  color: #1a5f2a;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e8f0e8;
}

.m-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #1a5f2a;
  color: #fff;
  border-radius: 50%;
  font-size: 13px;
  margin-right: 8px;
  vertical-align: middle;
}

.m-hint {
  font-size: 13px;
  color: #666;
  margin-bottom: 10px;
  line-height: 1.35;
}

.m-hint-warn {
  color: #8a4b00;
  background: #fff8e6;
  border-left: 3px solid #e6a800;
  padding: 8px 10px;
  margin-top: 8px;
  margin-bottom: 0;
}

.m-field {
  margin-bottom: 14px;
}

.m-field:last-child {
  margin-bottom: 0;
}

.m-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #444;
  margin-bottom: 6px;
}

.m-input {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  min-height: 48px;
  padding: 12px 14px;
  border: 2px solid #d0d8d0;
  border-radius: 10px;
  background: #fff;
  color: #1a1a1a;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}

.m-input:focus {
  outline: none;
  border-color: #1a5f2a;
  box-shadow: 0 0 0 3px rgba(26, 95, 42, 0.15);
}

.m-input.highlight {
  background: #fffde7;
  font-weight: 600;
}

.m-input.masked {
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.m-input.readonly-auto {
  background: #f4f6f4;
  color: #666;
}

.m-row-2 {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.m-row-3 {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.8fr;
  gap: 8px;
}

.m-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.m-btn-secondary {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  min-height: 44px;
  padding: 10px 8px;
  border: none;
  border-radius: 10px;
  background: #e8f0e8;
  color: #1a5f2a;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.m-btn-secondary:active {
  background: #d4e4d4;
}

.m-btn-blue {
  background: #e3edf8;
  color: #1a4a7a;
}

.m-btn-blue:active {
  background: #cddff0;
}

.m-spacer {
  height: 8px;
}

.m-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid #dde5dd;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
}

.m-footer-meta {
  text-align: center;
  padding: 8px 14px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.m-save {
  width: 100%;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  min-height: 52px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(160deg, #1a5f2a 0%, #2d8a42 100%);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 12px rgba(26, 95, 42, 0.35);
}

.m-save:active {
  transform: scale(0.98);
}

.m-credit {
  font-size: 11px;
  color: #888;
  margin-top: 8px;
}

.m-link {
  font-family: inherit;
  font-size: 12px;
  color: #1a5f2a;
  background: none;
  border: none;
  text-decoration: underline;
  padding: 6px;
  margin-top: 2px;
  cursor: pointer;
  touch-action: manipulation;
}

/* Modali full-screen su smartphone */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.5);
  padding: 0;
  overflow: hidden;
}

.modal-overlay.show {
  display: flex;
  flex-direction: column;
}

.modal {
  background: #fff;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  overflow: hidden;
}

.modal-stati { max-width: 480px; }

.modal h2 {
  font-size: 18px;
  font-weight: 800;
  color: #1a5f2a;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.modal p {
  font-size: 14px;
  line-height: 1.45;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.modal-copyright {
  overflow-y: auto;
}

.modal-copyright h3 {
  font-size: 15px;
  margin: 12px 0 6px;
  color: #333;
}

.comuni-filter {
  width: 100%;
  font-size: 16px;
  min-height: 48px;
  padding: 12px 14px;
  border: 2px solid #d0d8d0;
  border-radius: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.stati-select,
.comuni-select {
  flex: 1;
  width: 100%;
  min-height: 0;
  font-size: 16px;
  font-family: inherit;
  border: 2px solid #d0d8d0;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
  -webkit-appearance: none;
  appearance: none;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  flex-shrink: 0;
}

.modal-actions button {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  min-height: 48px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #e8ece8;
  color: #333;
  cursor: pointer;
  touch-action: manipulation;
}

.modal-actions button.btn-primary {
  background: #1a5f2a;
  color: #fff;
}

.modal-actions button:active {
  opacity: 0.85;
}

@media (max-width: 360px) {
  .m-row-2,
  .m-row-3,
  .m-actions {
    grid-template-columns: 1fr;
  }
}

.exit-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #e8f7ec;
  color: #1a5f2a;
}
.exit-screen h1 {
  font-size: clamp(22px, 5vw, 28px);
  margin-bottom: 16px;
}
.exit-screen p {
  font-size: 17px;
  line-height: 1.5;
  max-width: 420px;
}
