:root {
  --app-w: 480px; /* Larghezza leggermente maggiore per comodità */

  /* Palette Premium (Indigo & Slate) */
  --bg-body: #F5F7FA;       /* Sfondo pagina */
  --bg-card: #FFFFFF;       /* Sfondo card */
  --bg-input: #F3F4F6;      /* Sfondo input/bottoni secondari */
  
  --primary: #4F46E5;       /* Indaco vibrante */
  --primary-light: #EEF2FF; /* Tint per sfondi attivi */
  
  --text-main: #111827;     /* Testo principale (quasi nero) */
  --text-muted: #6B7280;    /* Testo secondario (grigio) */
  
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;

  /* Ombre moderne (Layered Shadows) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-floating: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);

  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

/* RESET & BASE */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%; margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  /* Texture di sfondo sottile */
  background-image: radial-gradient(#E5E7EB 1px, transparent 1px);
  background-size: 20px 20px;
}

[hidden], .hidden { display: none !important; }

/* APP SHELL */
.app {
  min-height: 100vh;
  max-width: var(--app-w);
  margin: 0 auto;
  padding: calc(130px + env(safe-area-inset-top)) 16px calc(140px + env(safe-area-inset-bottom));
  position: relative;
}

/* TOPBAR: Glassmorphism */
.topbar {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  z-index: 100;
  width: 100%; max-width: var(--app-w);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  box-shadow: var(--shadow-sm);
}

.topbar-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}

.content { display: flex; flex-direction: column; gap: 12px; }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* FIX APPLICATO QUI: Aggiunto background-clip standard */
.brand {
  font-weight: 800; font-size: 22px; letter-spacing: -0.03em; flex: 1;
  background: linear-gradient(135deg, var(--text-main) 0%, var(--primary) 100%);
  -webkit-background-clip: text;
  background-clip: text;            /* <--- Proprietà standard aggiunta */
  -webkit-text-fill-color: transparent;
}

/* SEGMENTED CONTROL (TABS) */
.segmented {
  display: flex; padding: 4px;
  background: var(--bg-input);
  border-radius: 999px;
  position: relative;
}
.seg {
  flex: 1; padding: 8px 12px;
  border: none; border-radius: 999px;
  background: transparent; color: var(--text-muted);
  font-weight: 600; font-size: 14px;
  cursor: pointer; transition: all 0.2s ease;
}
.seg.active {
  background: #fff;
  color: var(--text-main);
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

/* CARDS GENERALE */
.card {
  background: var(--bg-card);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 20px; margin: 16px 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* ITEM CARD (Lista Immobili) */
.item-card {
  border: none;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
/* Barrette laterali per stato */
.item-card.verde { border-left: 6px solid var(--success); }
.item-card.giallo { border-left: 6px solid var(--warning); }
.item-card.rosso { border-left: 6px solid var(--danger); }

.item-card h3 {
  margin: 0 0 8px 0; font-size: 18px; font-weight: 700; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 8px;
}
/* Nascondo la vecchia pillola se c'è ancora nell'HTML, visto che usiamo il bordo colorato */
.item-card h3 .pill { display: none; }

/* INPUTS */
.input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 15px;
  transition: all 0.2s;
}
.input:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  outline: none;
}
textarea.input { resize: vertical; min-height: 80px; font-family: inherit; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 20px; border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-weight: 600; font-size: 14px;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }

.btn.primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.outline {
  background: transparent; border: 1px solid var(--primary); color: var(--primary);
}
.btn-compact { padding: 8px 16px; font-size: 13px; }

/* FAB (Floating Action Button) nella topbar */
#fab-top {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
}

/* ACTIONS ROW */
.actions-right, .actions-left { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.actions-right { justify-content: flex-end; }
.actions-left { justify-content: flex-start; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--text-muted); }

/* CHIPS & RADIO */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 999px;
  background: var(--bg-input); border: 1px solid transparent;
  font-size: 14px; font-weight: 500; color: var(--text-muted);
  transition: all 0.2s; cursor: pointer;
}
.chip input { display: none; margin: 0; }
.chip:has(input:checked) {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}
.chip:has(input:checked) span::before {
  content: "✓";
  display: inline-block;
  margin-right: 6px;
  font-size: 0.9em;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* MODAL */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.backdrop.hidden { display: none !important; }
.modal {
  width: min(90vw, 380px);
  background: #fff; border: none;
  box-shadow: var(--shadow-floating);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.modal-title { font-size: 20px; margin: 0 0 16px 0; font-weight: 700; }
.actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 10px; }

/* FOOTER SAVE */
.save-footer {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: var(--app-w);
  z-index: 90; pointer-events: none;
}
.save-footer-inner {
  pointer-events: auto;
  display: flex; justify-content: flex-end; gap: 10px;
  background: var(--text-main); color: #fff;
  border-radius: 999px; padding: 8px 10px 8px 20px;
  box-shadow: var(--shadow-floating);
  backdrop-filter: blur(8px);
}
.save-footer .btn.primary {
  background: #fff; color: var(--text-main); box-shadow: none; min-width: 120px;
}

/* TABELLE PREZZIARIO */
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow: auto; border-radius: var(--radius-sm); border: 1px solid var(--bg-input); }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 12px; text-align: left; }
th {
  background: var(--bg-input);
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em;
  color: var(--text-muted);
}
td { border-bottom: 1px solid var(--bg-input); }
.title-row .pz-title {
  background: var(--primary-light); color: var(--primary);
  border-radius: 8px; padding: 8px 12px; font-weight: 700;
}

/* UTILS */
.badge {
  display: inline-block; padding: 4px 8px; border-radius: 6px;
  background: var(--bg-input); color: var(--text-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.badge.warn { background: #FEF3C7; color: #92400E; }
.muted { color: var(--text-muted); font-size: 0.9em; }
.stack { display: flex; flex-direction: column; }
.foot { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 12px; }

/* TOOLBAR & SEARCH FIXES */
.card.toolbar { display: flex; gap: 10px; padding: 16px; }
.card.toolbar.two { flex-wrap: wrap; justify-content: space-between; align-items: center; }
.search-wrap { flex: 1; min-width: 200px; }
#tab-immobili .card.toolbar { display: block !important; }

/* SPINNER & TOAST */
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid rgba(0,0,0,0.1); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--text-main); color: #fff;
  padding: 12px 20px; border-radius: 999px;
  box-shadow: var(--shadow-floating); z-index: 200;
  font-size: 14px; font-weight: 500;
}

/* ANIMAZIONI */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in, .item-card, .card {
  animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* FORM LAYOUT */
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media(max-width: 500px) { .grid.two { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }

/* SPLASH SCREEN */
.splash {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg-body); z-index: 2000;
}
.splash .box {
  width: min(90vw, 400px); background: #fff;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-floating);
  padding: 30px; text-align: center;
}

/* LOADER */
.loading, #page-loader {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.6); backdrop-filter: blur(4px); z-index: 120;
}
#page-loader.active { display: flex; }
