/* =============================================
   MODAL OVERLAY & BOX — Stili condivisi
   ============================================= */

/* ---- SPINNER OVERLAY (sopra tutto) ---- */
.spinner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  justify-content: center;
  align-items: center;
  z-index: 9999;
}
.spinner-overlay.active {
  display: flex;
}
.spinner-overlay .spinner {
  background: white;
  padding: 32px 40px;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.spinner-overlay .spinner i {
  font-size: 40px;
  color: var(--blue);
}
.spinner-overlay .spinner span {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  z-index: 999;
}
.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: var(--modal-bg);
  max-width: 800px;
  width: 90%;
  padding: 40px 48px 44px 48px;
  border-radius: var(--modal-radius);
  box-shadow: var(--modal-shadow);
  max-height: 90vh;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
}

.modal-box h3 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.modal-box h3 i {
  font-size: 28px;
  margin-right: 10px;
}
.modal-box h3 .close-modal-btn {
  background: none;
  border: none;
  font-size: 32px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 8px;
  transition: 0.2s;
  line-height: 1;
}
.modal-box h3 .close-modal-btn:hover {
  color: var(--text-primary);
  transform: rotate(90deg);
}

/* ---- MODALE MODIFICA (compatto) ---- */
.modal-box.modifica {
  max-width: 440px;
  min-height: auto;
  padding: 18px 22px 20px;
}
.modal-box.modifica h3 {
  justify-content: flex-start;
  gap: 10px;
  font-size: 20px;
  margin-bottom: 14px;
}
.modal-box.modifica label {
  font-weight: 500;
  font-size: 12px;
  color: #334155;
  display: block;
  margin: 8px 0 3px;
}
.modal-box.modifica input,
.modal-box.modifica select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--input-border);
  font-size: 13px;
}

/* ---- SEZIONE NUOVO IMPORTO (per nuove spese) ---- */
#editNewImportoSection {
  margin: 4px 0;
}

/* ---- SEZIONE AGGIUNTA IMPORTI (per spese esistenti) ---- */
#editImportiSection {
  margin: 4px 0;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.importo-attuale-display {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  padding: 4px 0;
  text-align: center;
  background: white;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.importo-totale-display {
  font-size: 16px;
  font-weight: 700;
  color: var(--blue);
  padding: 4px 0;
  text-align: center;
  background: #eff6ff;
  border-radius: 10px;
  border: 1px solid #bfdbfe;
}

.modal-box.modifica #editAddImporto {
  border-color: #93c5fd;
  background: #fafcff;
  font-weight: 600;
  font-size: 14px;
}
.modal-box.modifica #editAddImporto:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--input-focus-shadow);
  background: white;
}

/* ---- SEZIONE RICORRENTE (modale modifica) ---- */
#editRicorrenteSection {
  margin: 2px 0;
}
.ricorrente-actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
}
.ricorrente-actions .ric-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.1s;
  flex: 1;
  text-align: center;
  white-space: nowrap;
}
.ricorrente-actions .ric-btn.ric-this {
  background: #fef3c7;
  color: #92400e;
  border-color: #fbbf24;
}
.ricorrente-actions .ric-btn.ric-this:hover {
  background: #fde68a;
}
.ricorrente-actions .ric-btn.ric-range {
  background: #dbeafe;
  color: #1e40af;
  border-color: #93c5fd;
}
.ricorrente-actions .ric-btn.ric-range:hover {
  background: #bfdbfe;
}
.ricorrente-actions .ric-btn.ric-all {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}
.ricorrente-actions .ric-btn.ric-all:hover {
  background: #fecaca;
}

/* ---- MINI MODALE RANGE ---- */
.ric-range-box {
  max-width: 400px !important;
  min-height: auto !important;
  padding: 28px 32px !important;
}
.ric-range-fields {
  display: flex;
  gap: 14px;
  margin: 8px 0 16px 0;
}
.ric-range-fields .field-group {
  flex: 1;
}
.ric-range-fields .field-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}
.ric-range-fields .field-group input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--input-border);
  font-size: 14px;
  background: var(--input-bg);
}
.ric-range-fields .field-group input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--input-focus-shadow);
  background: white;
}
.ric-range-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.ric-range-btns button {
  padding: 9px 22px;
  border-radius: 30px;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}
.ric-range-btns .cancel-btn {
  background: #e9edf2;
  color: var(--text-dark);
}
.ric-range-btns .cancel-btn:hover {
  background: #d1d9e6;
}
.ric-range-confirm {
  background: var(--green);
  color: white;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  padding: 9px 22px;
  border-radius: 30px;
  transition: 0.15s;
}
.ric-range-confirm:hover {
  background: var(--green-hover);
  transform: translateY(-1px);
}

.modal-box.modifica .btn-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
}
.modal-box.modifica .btn-row button {
  padding: 7px 16px;
  border-radius: 24px;
  border: none;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}
.modal-box.modifica .btn-row .save-btn {
  background: var(--blue);
  color: white;
}
.modal-box.modifica .btn-row .cancel-btn {
  background: #e9edf2;
  color: var(--text-dark);
}
.modal-box.modifica .btn-row .delete-modal-btn {
  background: #fee2e2;
  color: var(--red-dark);
}

/* ---- RESPONSIVE MODALI ---- */
@media (max-width: 1200px) {
  .modal-box {
    padding: 28px 30px 32px 30px;
    max-width: 680px;
  }
}
@media (max-width: 700px) {
  .modal-box {
    padding: 24px 20px 28px 20px;
    max-width: 95%;
  }
  .modal-box h3 {
    font-size: 22px;
  }
}
@media (max-width: 500px) {
  .modal-box {
    padding: 20px 16px 24px 16px;
  }
  .modal-box h3 {
    font-size: 20px;
    margin-bottom: 18px;
  }
}

/* ---- MODALE VOCI MOBILE ---- */
.mobile-modal {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: 85vh;
}
.mobile-modal-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px 0;
  flex-shrink: 0;
}
.mobile-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
}
.mobile-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}
.mobile-item:last-child {
  border-bottom: none;
}
.mobile-data {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
}
.mobile-tipo {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}
.mobile-tipo.entrata {
  background: #dcfce7;
  color: #16a34a;
}
.mobile-tipo.uscita {
  background: #fee2e2;
  color: #dc2626;
}
.mobile-desc {
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.mobile-importo {
  font-weight: 600;
  white-space: nowrap;
}
.mobile-totale {
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ---- MODALE GRUPPO SPESE (voci aggregate) ---- */
.gruppo-modal {
  max-width: 720px;
  width: 94vw;
}
.gruppo-cols {
  display: flex;
  gap: 14px;
  align-items: stretch;
}
.gruppo-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.gruppo-col-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding-left: 2px;
}
.gruppo-list {
  flex: 1;
  max-height: 54vh;
  overflow-y: auto;
  border: 1.5px solid #8b5cf6;
  border-radius: 10px;
  background: #fff;
}
.gruppo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #e9e5f5;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}
.gruppo-item:last-child {
  border-bottom: none;
}
/* Righe alternate con due colori sfumati */
.gruppo-item:nth-child(odd) {
  background: #faf9ff;
}
.gruppo-item:nth-child(even) {
  background: #efeafc;
}
.gruppo-item:hover {
  background: #e5ddfa;
}
/* Voce selezionata: bordo più scuro */
.gruppo-item.selected {
  background: #ddd1f7;
  box-shadow: inset 3px 0 0 #8b5cf6;
  outline: 1.5px solid #6d28d9;
  outline-offset: -1.5px;
}
.gruppo-data {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.gruppo-importo {
  font-weight: 600;
  white-space: nowrap;
}
.gruppo-editor {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1.5px solid #8b5cf6;
  border-radius: 10px;
  padding: 12px;
  overflow-y: auto;
  max-height: 54vh;
  background: #fff;
}
.gruppo-editor-empty {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 11px;
  text-align: left;
}
.gruppo-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.gruppo-field label {
  font-size: 10px;
  color: #6d28d9;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 700;
}
.gruppo-field select,
.gruppo-field input {
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid #8b5cf6;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text, #0f172a);
}
.gruppo-field select:focus,
.gruppo-field input:focus {
  outline: none;
  border-color: #8b5cf6;
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.12);
}
.gruppo-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}
.gruppo-save {
  flex: 0 0 auto;
  min-width: 130px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.gruppo-save:hover {
  filter: brightness(1.08);
}
.gruppo-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.gruppo-del-btn {
  flex: 0 0 auto;
  min-width: 130px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fee2e2;
  color: #b91c1c;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.gruppo-del-btn:hover {
  background: #fecaca;
}
.gruppo-del-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- FOOTER MODALE MOBILE (bottone OK in basso, centrato) ---- */
.mobile-modal-footer {
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 14px;
}
.mobile-ok-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 34px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
  transition: 0.15s;
}
.mobile-ok-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.45);
}
.mobile-ok-btn:active {
  transform: translateY(0);
}
