/* ==========================================================================
   Payper Spese - Design System & Stylesheet
   Stile Payper: pulito, moderno, corporate navy con accento rosso, ultra-leggero.
   ========================================================================== */

:root {
  --primary: #1e3a8a;          /* Navy Payper */
  --primary-dark: #0f172a;
  --primary-light: #3b82f6;
  --accent: #e11d48;           /* Payper Red */
  --accent-hover: #be123c;
  
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Utility Hidden */
.hidden {
  display: none !important;
}

/* App Container */
.app-container {
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem 1.5rem;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo-badge {
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  color: #fff;
  font-weight: 900;
  font-size: 1.35rem;
  letter-spacing: -0.5px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.25);
  position: relative;
}

.brand-logo-badge::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background-color: var(--accent);
  border-radius: 50%;
}

.brand-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.2;
}

.brand-title .accent-text {
  color: var(--accent);
}

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(225, 29, 72, 0.3);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: #ffffff;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: #f1f5f9;
  border-color: var(--border-hover);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  background-color: #ffffff;
  color: var(--text-main);
  border-color: var(--primary-light);
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background-color: #f1f5f9;
  transform: scale(1.1);
}

.btn-icon-close {
  background: #f1f5f9;
  border: none;
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: var(--transition);
}

.btn-icon-close:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

/* Floating Action Button (Mobile) */
.btn-floating-add {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #be123c 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 15px rgba(225, 29, 72, 0.45);
  cursor: pointer;
  display: none; /* Attivo su mobile via media query */
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: var(--transition);
}

.btn-floating-add:hover {
  transform: scale(1.08);
}

/* ==========================================================================
   BUDGET BANNER
   ========================================================================== */
.budget-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.budget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}

.budget-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.budget-progress-bar-bg {
  width: 100%;
  height: 12px;
  background-color: #f1f5f9;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 0.85rem;
}

.budget-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-full);
  transition: width 0.6s ease, background 0.3s ease;
}

.budget-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.budget-stat strong {
  font-weight: 700;
  color: var(--text-main);
}

.budget-remaining-text.ok {
  color: var(--success);
  font-weight: 700;
}

.budget-remaining-text.alert {
  color: var(--danger);
  font-weight: 800;
}

/* Badges */
.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }

/* ==========================================================================
   KPI SUMMARY CARDS
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

.kpi-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.kpi-icon-box.total { background: #eff6ff; color: #2563eb; }
.kpi-icon-box.count { background: #f0fdf4; color: #16a34a; }
.kpi-icon-box.avg { background: #fefce8; color: #ca8a04; }
.kpi-icon-box.max { background: #fff1f2; color: #e11d48; }

.kpi-label {
  font-size: 0.785rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.2rem;
}

.kpi-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-dark);
}

/* ==========================================================================
   CHARTS SECTION
   ========================================================================== */
.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  overflow: hidden;
}

.chart-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Donut Chart Layout */
.chart-flex-wrapper {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.donut-box {
  width: 220px;
  height: 220px;
  flex-shrink: 0;
  position: relative;
}

.donut-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.05));
}

.donut-slice {
  transition: stroke-width 0.2s ease, opacity 0.2s ease;
  cursor: pointer;
}

.donut-slice:hover {
  stroke-width: 44px;
  opacity: 0.9;
}

.center-label {
  font-size: 11px;
  font-weight: 700;
  fill: var(--text-muted);
  letter-spacing: 1px;
}

.center-value {
  font-size: 16px;
  font-weight: 800;
  fill: var(--primary-dark);
}

.donut-legend {
  flex: 1;
  min-width: 200px;
  max-height: 210px;
  overflow-y: auto;
  padding-right: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.legend-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.25rem 0;
  border-bottom: 1px dashed #f1f5f9;
}

.legend-info {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  color: var(--text-main);
  font-weight: 500;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-numbers {
  text-align: right;
  flex-shrink: 0;
}

.legend-val {
  font-weight: 700;
  color: var(--primary-dark);
  margin-right: 0.35rem;
}

.legend-pct {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Bar Chart Layout */
.bar-scroll-wrapper {
  width: 100%;
  overflow-x: hidden;
  padding-bottom: 0.25rem;
}

.bar-chart-svg {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 220px;
}

.axis-label {
  font-size: 11px;
  fill: var(--text-muted);
  font-family: inherit;
}

.axis-label.x-axis {
  font-weight: 600;
  fill: var(--text-main);
}

.bar-top-val {
  font-size: 11px;
  font-weight: 700;
  fill: var(--primary);
}

.chart-bar {
  transition: transform 0.2s ease, opacity 0.2s ease;
  cursor: pointer;
}

.chart-bar:hover {
  opacity: 0.85;
}

.empty-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.empty-icon {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
  opacity: 0.6;
}

/* ==========================================================================
   FILTER BAR
   ========================================================================== */
.filters-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.filters-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-box {
  flex: 2;
  min-width: 220px;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 0.6rem 0.85rem 0.6rem 2.25rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  background-color: var(--bg-input);
  outline: none;
  transition: var(--transition);
}

.search-box input:focus {
  border-color: var(--primary-light);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.95rem;
}

.filter-item {
  flex: 1;
  min-width: 150px;
}

.filter-select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  background-color: var(--bg-input);
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-main);
}

.filter-select:focus {
  border-color: var(--primary-light);
  background: #fff;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.custom-date-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #f1f5f9;
}

.custom-date-row input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* ==========================================================================
   EXPENSES TABLE & LIST
   ========================================================================== */
.expenses-section {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.period-badge {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 0.5rem;
}

/* Table Style */
.table-responsive {
  width: 100%;
  overflow-x: hidden;
}

.expenses-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.expenses-table th {
  background-color: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.expenses-table td {
  padding: 0.9rem 0.9rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.expenses-table tr:last-child td {
  border-bottom: none;
}

.expenses-table tr:hover {
  background-color: #f8fafc;
}

.td-date {
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}

.td-merchant {
  word-break: break-word;
}

.td-merchant strong {
  display: block;
  font-weight: 700;
  color: var(--primary-dark);
}

.td-merchant .sub-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.td-amount {
  white-space: nowrap;
}

.amount-val {
  display: block;
  font-weight: 800;
  font-size: 1rem;
  color: var(--primary-dark);
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background-color: color-mix(in srgb, var(--cat-color) 12%, transparent);
  color: var(--cat-color);
  white-space: nowrap;
}

.category-pill.mini {
  font-size: 0.725rem;
  padding: 0.2rem 0.5rem;
}

.payment-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  white-space: nowrap;
}

.payment-badge.mini {
  font-size: 0.7rem;
}

.btn-receipt-view {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-receipt-view:hover {
  background: #dbeafe;
}

.td-actions {
  white-space: nowrap;
  text-align: right;
}

/* Empty State */
.empty-state {
  padding: 4rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 0.85rem;
}

.empty-state h3 {
  font-size: 1.15rem;
  color: var(--primary-dark);
  margin-bottom: 0.35rem;
}

/* Mobile Cards Container (Nascosto su Desktop, attivo su mobile) */
.expenses-cards-container {
  display: none;
  padding: 1rem;
  flex-direction: column;
  gap: 0.85rem;
}

.expense-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.card-merchant {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.card-amount {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent);
}

.card-desc {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #f1f5f9;
  padding-top: 0.65rem;
}

.card-tags {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-receipt-badge {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  font-size: 0.85rem;
}

/* ==========================================================================
   MODALS & OVERLAYS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 660px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

.modal-content.large {
  max-width: 720px;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background-color: #fafafa;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background-color: #fafafa;
}

/* Form Styling */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 1rem;
}

.form-group.full {
  grid-column: 1 / -1;
}

.form-label {
  display: block;
  font-size: 0.825rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.input-currency-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.currency-symbol {
  position: absolute;
  left: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 1rem;
}

.input-currency-wrapper input {
  padding-left: 2rem !important;
  font-weight: 700;
  font-size: 1.15rem !important;
  color: var(--accent) !important;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  background-color: var(--bg-input);
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary-light);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 70px;
}

/* Receipt Upload Box */
.receipt-upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  background-color: #f8fafc;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.receipt-upload-zone:hover {
  border-color: var(--primary-light);
  background-color: #eff6ff;
}

.upload-icon {
  font-size: 1.8rem;
  margin-bottom: 0.35rem;
}

.upload-prompt strong {
  color: var(--primary);
  font-weight: 700;
}

.upload-prompt p {
  font-size: 0.775rem;
  color: var(--text-muted);
}

.receipt-preview-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: #f1f5f9;
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
}

.receipt-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.receipt-meta {
  flex: 1;
  overflow: hidden;
}

.receipt-name {
  font-size: 0.825rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

/* Settings Manager */
.settings-section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin: 1.25rem 0 0.75rem 0;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 0.35rem;
}

.categories-manager-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.cat-manager-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.cat-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cat-icon-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.cat-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.add-cat-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Lightbox Scontrino */
.receipt-lightbox-content {
  text-align: center;
}

.receipt-lightbox-img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   PRINT LAYOUT (Stampa Ufficiale Nota Spese)
   ========================================================================== */
#printReportArea {
  display: none;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  .app-container, .modal-overlay, .btn-floating-add {
    display: none !important;
  }

  #printReportArea {
    display: block !important;
    padding: 2cm 1.5cm;
  }

  .print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
  }

  .print-title {
    font-size: 20pt;
    font-weight: 900;
    color: #0f172a;
    text-transform: uppercase;
  }

  .print-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
    font-size: 10pt;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
  }

  .print-table th, .print-table td {
    border: 1px solid #cbd5e1;
    padding: 6pt 8pt;
    font-size: 9.5pt;
  }

  .print-table th {
    background-color: #f1f5f9 !important;
    font-weight: bold;
    text-transform: uppercase;
  }

  .print-summary-box {
    margin-left: auto;
    width: 250px;
    border: 1px solid #0f172a;
    padding: 8pt;
    margin-bottom: 3rem;
  }

  .print-signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 4rem;
    page-break-inside: avoid;
  }

  .signature-box {
    width: 200px;
    border-top: 1px solid #000;
    text-align: center;
    padding-top: 6pt;
    font-size: 9pt;
  }
}

/* ==========================================================================
   RESPONSIVE DESIGN (Smartphone & Tablet)
   ========================================================================== */
@media (max-width: 768px) {
  .app-container {
    padding: 1rem 0.75rem 5rem 0.75rem;
  }

  .table-responsive {
    display: none; /* Usa le card su mobile */
  }

  .expenses-cards-container {
    display: flex;
  }

  .btn-floating-add {
    display: flex;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-card {
    padding: 0.85rem;
  }

  .kpi-value {
    font-size: 1.1rem;
  }

  .header-actions .btn-text-hide {
    display: none;
  }
}

/* ==========================================================================
   SPESE CONDIVISE COINQUILINI
   ========================================================================== */
.shared-toggle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.shared-switch-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.shared-switch-pill:hover {
  background-color: #dbeafe;
}

.shared-switch-pill input {
  width: 15px;
  height: 15px;
  accent-color: #2563eb;
  cursor: pointer;
}

.shared-bill-panel {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 0.85rem;
  animation: fadeIn 0.2s ease;
}

.shared-shortcuts-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.65rem;
  margin-bottom: 0.5rem;
}

.shortcuts-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.btn-calc-chip {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-calc-chip:hover {
  background: #f1f5f9;
  border-color: var(--primary-light);
  color: var(--primary);
}

.shared-summary-note {
  font-size: 0.8rem;
  color: #0369a1;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  line-height: 1.4;
}

.shared-sub-pill {
  font-size: 0.72rem;
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.45rem;
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.25rem;
  font-weight: 600;
}

.formula-sub-badge {
  font-size: 0.72rem;
  color: #0f766e;
  background: #f0fdfa;
  border: 1px solid #ccfbf1;
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.45rem;
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.25rem;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.transfer-sync-banner {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
  flex-wrap: wrap;
}

.transfer-sync-info {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.transfer-sync-icon {
  font-size: 1.75rem;
  background: rgba(255, 255, 255, 0.2);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.transfer-title {
  font-size: 1rem;
  display: block;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.transfer-desc {
  font-size: 0.825rem;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
}

.transfer-sync-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.transfer-sync-actions .btn {
  padding: 0.5rem 0.85rem;
  font-size: 0.825rem;
  font-weight: 600;
}

.transfer-sync-actions .btn-primary {
  background: #ffffff;
  color: #1e3a8a;
  border: 1px solid #ffffff;
}

.transfer-sync-actions .btn-primary:hover {
  background: #f1f5f9;
}

.transfer-sync-actions .btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.transfer-sync-actions .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.25);
}

.shared-card-banner {
  font-size: 0.76rem;
  color: #1e3a8a;
  background: #f0f9ff;
  border-left: 3px solid #3b82f6;
  padding: 0.35rem 0.65rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

/* Status Pill Auto-Backup */
.storage-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.725rem;
  font-weight: 700;
  padding: 0.15rem 0.65rem;
  border-radius: var(--radius-full);
  transition: var(--transition);
  user-select: none;
}

.storage-status-pill.online {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.storage-status-pill.local {
  background: #fefce8;
  color: #a16207;
  border: 1px solid #fef08a;
}

.storage-status-pill .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Math Calculation Live Badge */
.math-calc-pill {
  font-size: 0.775rem;
  font-weight: 800;
  color: #1e3a8a;
  background: #e0f2fe;
  border: 1px solid #7dd3fc;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  animation: fadeIn 0.15s ease;
}

/* ==========================================================================
   PULSANTI A VISTA (CATEGORIE & METODI DI PAGAMENTO)
   ========================================================================== */
.selector-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.45rem;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.smart-autofill-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: #0f766e;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  animation: fadeIn 0.2s ease;
}

.choice-buttons-grid {
  display: grid;
  gap: 0.45rem;
}

.category-buttons-grid {
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
}

.payment-buttons-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.choice-pill-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.65rem;
  background: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  user-select: none;
}

.choice-pill-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.choice-pill-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.choice-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-choice-btn.active {
  background-color: color-mix(in srgb, var(--cat-color, #3b82f6) 14%, #ffffff);
  border-color: var(--cat-color, #3b82f6);
  color: var(--primary-dark);
  font-weight: 700;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--cat-color, #3b82f6) 22%, transparent);
}

.payment-choice-btn.active {
  background-color: #eff6ff;
  border-color: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

@keyframes pulseHighlight {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.choice-pill-btn.auto-filled-pulse {
  animation: pulseHighlight 0.3s ease;
}

/* ==========================================================================
   AUTOCOMPLETAMENTO INTELLIGENTE FORNITORI
   ========================================================================== */
.merchant-autocomplete-wrapper {
  position: relative;
}

.merchant-autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  max-height: 220px;
  overflow-y: auto;
}

.merchant-suggestion-item {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: background-color 0.12s ease;
}

.merchant-suggestion-item:last-child {
  border-bottom: none;
}

.merchant-suggestion-item:hover,
.merchant-suggestion-item.highlighted {
  background-color: #eff6ff;
}

.merchant-suggestion-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--primary-dark);
}

.merchant-suggestion-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 0.08rem 0.4rem;
  border-radius: var(--radius-full);
}

.merchant-suggestion-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.72rem;
}

.merchant-meta-cat {
  color: var(--cat-color, var(--primary));
  font-weight: 600;
}

.merchant-meta-pay {
  color: var(--text-muted);
  font-weight: 500;
}

.cloud-sync-settings-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 0.9rem;
  margin-bottom: 1rem;
}

/* ==========================================================================
   STILE APPLE iOS / WALLET & MOBILE BOTTOM SHEET
   ========================================================================== */
.ios-sheet-handle {
  width: 38px;
  height: 5px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 9999px;
  margin: 0 auto 0.75rem auto;
  display: block;
}

.ios-wallet-row {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ios-wallet-row:active {
  transform: scale(0.99);
}

.ios-row-main {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
}

.ios-cat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.ios-row-info {
  flex: 1;
  min-width: 0;
}

.ios-merchant-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.ios-meta-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ios-row-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.3;
}

.ios-row-right {
  text-align: right;
  flex-shrink: 0;
}

.ios-row-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.45rem;
  border-top: 1px solid #f1f5f9;
}

.section-icon-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

/* Mobile Apple Summary Card & Segmented Switcher (Nascosti su Desktop, attivi su Mobile) */
.mobile-summary-card {
  display: none;
}

.mobile-ios-segmented {
  display: none;
}

@media (max-width: 768px) {
  .app-container {
    padding: 0.75rem 0.75rem calc(5.5rem + env(safe-area-inset-bottom, 0px)) 0.75rem;
    max-width: 100%;
  }

  /* Header Apple Mobile */
  .app-header {
    padding-bottom: 0.85rem;
    margin-bottom: 0.85rem;
  }

  .brand-logo-badge {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    border-radius: 10px;
  }

  .brand-title {
    font-size: 1.15rem;
  }

  .brand-subtitle {
    display: none;
  }

  /* Su mobile nascondi pulsanti desktop ingombranti per tenere solo le 3 icone circolari come nell'anteprima */
  #btnNewExpense, #btnExportCSV, #btnPrintReport, #btnDownloadBackup, #btnRestoreBackup, #btnPasteData {
    display: none !important;
  }

  .header-actions {
    gap: 0.4rem;
  }

  .header-actions .btn-outline {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  }

  /* Mobile Apple Summary Card (Esatta replica anteprima) */
  .mobile-summary-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  }

  .mobile-summary-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .mobile-summary-val {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
    margin: 0.1rem 0;
  }

  .mobile-summary-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
  }

  .btn-apple-add {
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 12px;
    padding: 0.55rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
    transition: transform 0.15s ease;
  }

  .btn-apple-add:active {
    transform: scale(0.96);
  }

  /* Segmented Control iOS */
  .mobile-ios-segmented {
    display: flex;
    background: #e2e8f0;
    padding: 3px;
    border-radius: 11px;
    margin-bottom: 0.85rem;
  }

  .ios-seg-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.45rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: 9px;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .ios-seg-btn.active {
    background: #ffffff;
    color: var(--text-main);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  /* Scheda nascosta su mobile */
  .mobile-hidden-pane {
    display: none !important;
  }

  /* Lista spese su mobile: stile card Apple Wallet senza bordi pesanti */
  .expenses-section {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .section-header {
    margin-bottom: 0.5rem;
    padding: 0 0.25rem;
  }

  .expenses-cards-container {
    padding: 0;
    gap: 0.6rem;
  }

  .category-buttons-grid,
  .payment-buttons-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-pill-btn {
    padding: 0.55rem 0.55rem;
    font-size: 0.78rem;
    border-radius: 12px;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .modal-content {
    max-height: 92vh;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding-bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px));
    animation: iosSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes iosSlideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }
}
