:root {
  --app-primary: #4f46e5;
  --app-primary-dark: #4338ca;
  --app-bg: #f8fafc;
  --app-border: rgba(15, 23, 42, 0.08);
}

html { -webkit-text-size-adjust: 100%; }

body {
  background-color: var(--app-bg);
  color: #0f172a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Evita lo zoom automatico di iOS Safari quando si focalizza un input. */
input, select, textarea {
  font-size: 16px;
}

.bg-app-primary {
  background-color: var(--app-primary) !important;
}

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary-dark);
  --bs-btn-hover-border-color: var(--app-primary-dark);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
}

/* Touch target minimo 44x44px sui bottoni icona */
.btn-icon {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.navbar .nav-link {
  position: relative;
  font-weight: 500;
  opacity: 0.85;
}
.navbar .nav-link.active,
.navbar .nav-link:hover {
  opacity: 1;
}
.navbar .nav-link.active::after {
  content: "";
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: -2px;
  height: 2px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 2px;
}

.stat-card {
  border-left: 4px solid var(--app-primary);
}
.stat-card.border-success {
  border-left-color: #16a34a;
}
.stat-card.border-danger {
  border-left-color: #dc2626;
}

.avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--app-primary), #6366f1);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.card {
  border: 1px solid var(--app-border);
}

.table > :not(caption) > * > * {
  padding: 0.65rem 0.75rem;
}

/* ============================================================
   RESPONSIVE TABLE -> CARD STACK SU MOBILE
   Uso: <div class="table-card-mobile"><table>...
        <td data-label="Etichetta">...</td>
   ============================================================ */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 240px;
}

@media (max-width: 767.98px) {
  .table-card-mobile thead { display: none; }
  .table-card-mobile tbody { display: block; }
  .table-card-mobile tbody tr {
    display: block;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 0.625rem;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.55rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }
  .table-card-mobile tbody tr:last-child { margin-bottom: 0; }
  .table-card-mobile tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border: 0;
    text-align: left !important;
    white-space: normal !important;
  }
  .table-card-mobile tbody td + td { border-top: 1px dashed var(--app-border); }
  .table-card-mobile tbody td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    font-weight: 600;
    flex-shrink: 0;
  }
  .table-card-mobile tbody td[data-label=""]::before { content: none; }
  .table-card-mobile tbody td[data-label=""] {
    justify-content: flex-end;
    padding-top: 0.6rem;
    margin-top: 0.25rem;
    border-top: 1px solid var(--app-border) !important;
  }
  .table-card-mobile tbody td[data-label=""] .btn { min-height: 44px; }
  .table-card-mobile .table-responsive { overflow-x: visible !important; }
  .table-card-mobile,
  .table-card-mobile > .table-responsive {
    overflow-x: visible !important;
  }
  .table-card-mobile table { margin-bottom: 0; }

  /* Bottoni form full-width nelle pagine form (a/btn dentro .form-actions) */
  .form-actions {
    flex-direction: column-reverse !important;
    gap: 0.5rem !important;
  }
  .form-actions > .btn { width: 100%; }

  /* Riduci padding container su schermi piccoli */
  main.container-fluid { padding-left: 0.75rem; padding-right: 0.75rem; }

  /* Heading pagina e bottoni: il bottone "+ Nuovo" full-width sotto il titolo */
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .page-header > .btn { width: 100%; }

  /* Pagination compatta */
  .pagination .page-link { padding: 0.5rem 0.75rem; }

  /* Dashboard suggerimenti pagamento: bottone full-width sotto */
  .settlement-suggestion {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .settlement-suggestion > .btn { width: 100%; }

  /* Form filtri pi\u00f9 stretti: il bottone reset full-width */
  .filters-row .btn { width: 100%; }

  body { font-size: 0.95rem; }
}

/* Scroll-shadow per le poche tabelle che restano scrollabili anche su mobile */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Utility extra: bottoni full-width sotto md, auto da md in su */
@media (max-width: 767.98px) {
  .w-md-auto { width: 100% !important; }
}

/* Menu utente: full-width su navbar collassata (mobile), compatto su desktop. */
.user-menu .user-menu-toggle { white-space: normal; }
@media (max-width: 991.98px) {
  .user-menu { width: 100%; }
  .user-menu .user-menu-toggle { width: 100%; }
  .user-menu .dropdown-menu { width: 100%; }
}

/* ============================================================
   LISTA SPESE COMPATTA SU MOBILE
   Una riga per spesa, ~52px di altezza, per stare 5-6 spese
   in una schermata da telefono.
   ============================================================ */
.expense-mobile-list {
  border-radius: 0.625rem;
  overflow: hidden;
}
.expense-mobile-item {
  padding: 0.45rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.expense-mobile-link {
  flex: 1 1 auto;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  display: block;
}
.expense-mobile-link:hover { color: inherit; }
.expense-mobile-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.expense-mobile-date {
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  flex: 0 0 auto;
  min-width: 2.6rem;
  text-align: center;
  background: #f1f5f9;
  border-radius: 0.4rem;
  padding: 0.25rem 0.4rem;
  line-height: 1.1;
}
.expense-mobile-desc {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.2;
}
.expense-mobile-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}
.expense-mobile-meta {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 0.05rem;
}
.expense-mobile-amount {
  flex: 0 0 auto;
  font-size: 0.95rem;
  white-space: nowrap;
  margin-left: auto;
  padding-left: 0.5rem;
}
.expense-mobile-delete {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  margin-left: 0.25rem;
}
.expense-mobile-delete .btn {
  min-width: 28px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Badge cliccabile pagato/non-pagato per il saldo del mese. */
.month-paid-badge {
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  letter-spacing: 0.01em;
  transition: filter 120ms ease, transform 80ms ease;
}
.month-paid-badge:hover {
  filter: brightness(0.96);
}
.month-paid-badge:active {
  transform: scale(0.98);
}
.month-paid-badge:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
