/* ============================================================
   Gestionale Disinfestazione — design system
   Palette: bianco dominante, accenti verdi, minimal.
   Mobile/tablet first, responsive verso desktop.
   ============================================================ */

:root {
  --green:        #1f9d55;
  --green-dark:   #18794a;
  --green-soft:   #e8f6ee;
  --bg:           #f3f6f8;   /* grigio-azzurro chiaro */
  --card:         #ffffff;
  --text:         #1f2933;
  --muted:        #6b7785;
  --border:       #e2e8f0;
  --danger:       #d64545;
  --danger-soft:  #fdecec;
  --warn:         #b7791f;
  --shadow:       0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-hover: 0 6px 18px rgba(16,24,40,.10);
  --radius:       12px;
  --radius-sm:    8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout app ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
}
.app-header .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.05rem;
}
.app-header .brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--green); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.app-header nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.app-header nav a {
  padding: 8px 14px; border-radius: 999px; color: var(--muted);
  font-weight: 600; font-size: .92rem;
}
.app-header nav a:hover { background: var(--bg); text-decoration: none; }
.app-header nav a.active { background: var(--green-soft); color: var(--green-dark); }
.app-header .user-box { display: flex; align-items: center; gap: 10px; }
.app-header .user-box .who { font-size: .85rem; color: var(--muted); text-align: right; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- Top header bar (gestionale) ---------- */
/* Header full-width in alto, con il logo accanto al titolo della pagina. */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 60px; z-index: 50;
  background: #fff; border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(16,24,40,.05);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
}
.topbar-logo {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  background: var(--green); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 1.15rem;
}
.topbar-title {
  font-weight: 700; color: var(--text); font-size: 1.05rem;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.topbar-date { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.user-chip {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  background: none; border: none; padding: 4px 6px; border-radius: 10px;
  transition: background .12s ease;
}
.user-chip:hover { background: var(--bg); }
.avatar-sm {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  background: var(--green-soft); color: var(--green-dark);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.user-chip-text { display: flex; flex-direction: column; line-height: 1.12; text-align: left; }
.user-chip-text strong { font-size: .85rem; }
.user-chip-text .muted { font-size: .72rem; }

/* ---------- Sidebar rail (gestionale) ---------- */
/* La rail parte sotto l'header full-width. */
.rail {
  position: fixed; top: 60px; left: 0; bottom: 0; width: 80px; z-index: 40;
  background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0;
}
.rail-nav { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; overflow-y: auto; }
.rail-item {
  position: relative; width: 64px; padding: 9px 2px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  color: var(--muted); font-size: .64rem; font-weight: 600; text-align: center;
  cursor: pointer; text-decoration: none; transition: background .12s ease, color .12s ease;
}
.rail-item:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.rail-item.active { background: var(--green-soft); color: var(--green-dark); }
.rail-item.active::before {
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 26px; border-radius: 0 4px 4px 0; background: var(--green);
}
.rail-item svg { width: 22px; height: 22px; }
.rail-label { line-height: 1.05; }
.badge-dot {
  position: absolute; top: 4px; right: 10px; min-width: 17px; height: 17px; padding: 0 4px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: .62rem; font-weight: 800; display: grid; place-items: center; line-height: 1;
  box-shadow: 0 0 0 2px #fff;
}
.rail-bottom { margin-top: auto; padding-top: 12px; }
.rail-avatar {
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  background: var(--green-soft); color: var(--green-dark);
  display: grid; place-items: center; font-weight: 700; border: 2px solid transparent;
  transition: border-color .12s ease;
}
.rail-avatar:hover { border-color: var(--green); }

.app-main { margin-left: 80px; margin-top: 60px; min-width: 0; }
/* Il contenuto del gestionale riempie tutta la larghezza disponibile
   accanto alla sidebar (niente centratura a 1200px che lascia spazio vuoto). */
.app-main .container { max-width: none; margin: 0; padding: 22px 28px 64px; }
body.has-rail { background: var(--bg); }

/* Hamburger menu button */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  margin-right: -4px;
}
.hamburger-btn:hover { background: var(--bg); }
.hamburger-btn svg { width: 24px; height: 24px; }

/* Header responsive: su schermi stretti riduci a logo + avatar */
@media (max-width: 600px) {
  .topbar-name { display: none; }
  .topbar-date { display: none; }
  .user-chip-text { display: none; }
}

/* Su mobile/tablet la rail diventa una bottom navigation bar fissa.
   Niente drawer/hamburger: navigazione sempre visibile in basso, touch-friendly. */
@media (max-width: 768px) {
  /* Niente hamburger ne' backdrop: la navigazione e' la barra in basso. */
  .hamburger-btn { display: none; }
  .rail-backdrop { display: none !important; }

  .rail {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    flex-direction: row;
    align-items: stretch;
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 14px rgba(0, 0, 0, 0.06);
    transform: none;
    z-index: 100;
  }

  .rail-nav {
    flex-direction: row;
    align-items: stretch;
    justify-content: space-around;
    gap: 0;
    overflow: visible;
    height: 100%;
  }

  .rail-item {
    flex: 1 1 0; width: auto; max-width: none;
    justify-content: center; gap: 3px;
    padding: 7px 2px; border-radius: 0;
    font-size: .6rem;
  }
  .rail-item:hover { background: transparent; }
  .rail-item.active { background: transparent; color: var(--green-dark); }
  /* Indicatore: barretta in alto invece che a sinistra. */
  .rail-item.active::before {
    left: 50%; top: 0; bottom: auto;
    transform: translateX(-50%);
    width: 24px; height: 3px;
    border-radius: 0 0 4px 4px;
  }
  .rail-item svg { width: 23px; height: 23px; }

  /* Badge interventi: ancorato vicino all'icona centrata. */
  .badge-dot { top: 4px; right: 50%; margin-right: -20px; }

  /* L'avatar in basso non serve: l'account resta nella topbar. */
  .rail-bottom { display: none; }

  /* Niente sidebar laterale: il contenuto va a tutta larghezza,
     con spazio in basso per non finire sotto la barra. */
  .app-main { margin-left: 0; }
  .app-main .container {
    padding: 18px 16px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* Elementi flottanti sopra la bottom nav. */
  #toasts { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); right: 16px; }
  .bulkbar { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }
}

/* Su desktop la rail resta una sidebar verticale (nessun residuo del drawer). */
@media (min-width: 769px) {
  .rail { transform: none !important; }
  .rail-backdrop { display: none !important; }
}

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; }

/* ---------- Toolbar (ricerca + filtri) ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .search { flex: 1; min-width: 200px; }

/* ---------- Card grid ---------- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.card .card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--green-soft); color: var(--green-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 1.1rem;
  flex: 0 0 auto;
}
.avatar.blue { background: #e6effb; color: #1c5fb0; }
.card .title { font-weight: 700; font-size: 1.02rem; }
.card .meta { color: var(--muted); font-size: .85rem; }
.card .row { display: flex; gap: 8px; font-size: .88rem; margin: 4px 0; }
.card .row .k { color: var(--muted); min-width: 92px; }
.card .card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .76rem; font-weight: 700;
  background: var(--bg); color: var(--muted);
}
.badge.green  { background: var(--green-soft); color: var(--green-dark); }
.badge.red    { background: var(--danger-soft); color: var(--danger); }
.badge.gray   { background: #eef1f4; color: var(--muted); }
.badge.warn   { background: #fdf3e1; color: var(--warn); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: #fff; color: var(--text);
  font-weight: 600; font-size: .92rem; cursor: pointer;
  min-height: 44px;  /* touch-friendly */
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--green-dark); }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 11px 12px; font-size: .95rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); min-height: 44px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}
.textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 560px;
  box-shadow: 0 20px 50px rgba(16,24,40,.25);
  animation: pop .15s ease;
}
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal .modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal .modal-head h3 { margin: 0; font-size: 1.15rem; }
.modal .modal-body { padding: 20px; }
.modal .modal-foot {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal .x { border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); }

/* ---------- Tables (per servizi/liste tabellari) ---------- */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { background: #fafbfc; color: var(--muted); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafdfb; }

/* ---------- States ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }
.loading { text-align: center; color: var(--muted); padding: 40px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--green);
  animation: spin .7s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #1f2933; color: #fff; padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover); font-size: .9rem; min-width: 220px;
  animation: pop .15s ease;
}
.toast.ok { background: var(--green-dark); }
.toast.err { background: var(--danger); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow-hover); padding: 36px 32px; width: 100%; max-width: 380px; }
.login-card .logo-lg { width: 56px; height: 56px; border-radius: 14px; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; margin: 0 auto 16px; }
.login-card h1 { text-align: center; font-size: 1.3rem; margin: 0 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 24px; }
.login-card .err { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 8px; font-size: .85rem; margin-bottom: 14px; display: none; }
.login-card .err.show { display: block; }

/* ---------- Pannello filtri collassabile ---------- */
.filter-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.filter-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; cursor: pointer; user-select: none;
}
.filter-head:hover { background: #fafbfc; }
.filter-title { font-weight: 700; font-size: 1rem; }
.filter-head .chevron { width: 20px; height: 20px; color: var(--muted); transition: transform .2s ease; }
.filter-card.expanded .filter-head .chevron { transform: rotate(180deg); }
.filter-body { display: none; flex-direction: column; gap: 12px; padding: 0 18px 18px; }
.filter-card.expanded .filter-body { display: flex; }

/* Select native con chevron personalizzato */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7785' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
.select option:checked, .select option:hover { background: var(--green); color: #fff; }

/* ---------- Chip di stato (segmented) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--green); background: #fff; color: var(--green-dark);
  border-radius: 999px; padding: 7px 16px; font-weight: 600; font-size: .88rem;
  cursor: pointer; transition: background .12s ease, color .12s ease;
}
.chip:hover { background: var(--green-soft); }
.chip.active { background: var(--green); color: #fff; }

.results-count { color: var(--muted); font-size: .85rem; margin-bottom: 14px; }

/* ---------- Griglia card clienti ---------- */
.client-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(4, 1fr);
  align-items: stretch;
}
@media (max-width: 1200px) { .client-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 880px)  { .client-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .client-grid { grid-template-columns: 1fr; } }

.client-card {
  display: flex; flex-direction: column; height: 100%;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 16px 12px;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.client-card:hover { box-shadow: var(--shadow-hover); }
.client-card.selected { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }

/* Header */
.cc-head { display: flex; align-items: flex-start; gap: 10px; }
.cc-check { width: 18px; height: 18px; margin-top: 4px; accent-color: var(--green); cursor: pointer; flex: 0 0 auto; }
.cc-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
  background: var(--green-soft); color: var(--green-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 1rem;
}
.cc-head-text { min-width: 0; flex: 1; }
.cc-name { font-weight: 700; font-size: 1rem; line-height: 1.25; word-break: break-word; }
.cc-status { margin-top: 6px; }

/* Body rows */
.cc-body { flex: 1; margin: 14px 0; display: flex; flex-direction: column; gap: 9px; }
.cc-row { display: flex; align-items: center; gap: 9px; font-size: .9rem; color: var(--text); }
.cc-ic { display: inline-flex; color: var(--muted); flex: 0 0 auto; }
.cc-ic .ic { width: 16px; height: 16px; }
.cc-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-link { color: var(--green-dark); font-weight: 600; }
.cc-link:hover { text-decoration: underline; }
.copy-btn {
  flex: 0 0 auto; width: 28px; height: 28px; border: none; background: transparent;
  border-radius: 7px; color: var(--muted); cursor: pointer; display: grid; place-items: center;
  transition: background .12s ease, color .12s ease;
}
.copy-btn .ic { width: 15px; height: 15px; }
.copy-btn:hover { background: var(--bg); color: var(--green-dark); }

/* Footer toolbar */
.cc-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.cc-count { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; font-weight: 600; }
.cc-count .ic { width: 16px; height: 16px; }
.cc-tools { display: flex; gap: 2px; }
.icon-btn {
  width: 34px; height: 34px; border: none; background: transparent; border-radius: 8px;
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
  transition: background .12s ease, color .12s ease;
}
.icon-btn .ic { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--bg); color: var(--green-dark); }
.icon-btn.js-arch:hover { background: var(--danger-soft); color: var(--danger); }

/* Barra azioni multiple (bulk) */
.bulkbar {
  position: fixed; bottom: 24px; left: calc(50% + 40px); transform: translate(-50%, 160%);
  display: flex; align-items: center; gap: 14px; z-index: 60;
  background: #1f2933; color: #fff; padding: 11px 14px 11px 18px;
  border-radius: 12px; box-shadow: var(--shadow-hover);
  transition: transform .22s cubic-bezier(.2,.8,.3,1);
}
.bulkbar.show { transform: translate(-50%, 0); }
.bulkbar-count { font-size: .9rem; }
.bulkbar-count strong { font-size: 1rem; }
@media (max-width: 560px) { .bulkbar { left: 50%; right: auto; width: calc(100% - 32px); justify-content: space-between; } }

/* ---------- Scheda cliente (profilo) ---------- */
.ic { width: 16px; height: 16px; flex: 0 0 auto; }
.ic.big { width: 40px; height: 40px; }

.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px 8px 12px; font-weight: 600; font-size: .9rem; color: var(--text);
  cursor: pointer; margin-bottom: 16px; transition: background .12s ease, border-color .12s ease;
}
.btn-back:hover { background: var(--bg); border-color: var(--green); color: var(--green-dark); }
.btn-back .ic { width: 18px; height: 18px; }

/* ---------- Form a pagina intera (nuovo/modifica) ---------- */
.form-page { max-width: 720px; margin: 0 auto; }
.form-page-title { font-size: 1.5rem; margin: 4px 0 18px; }
.form-page-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px;
}
.form-page-card .field { margin-bottom: 16px; }
.form-page-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border);
}
@media (max-width: 560px) {
  .form-page-actions { flex-direction: column-reverse; }
  .form-page-actions .btn { width: 100%; }
}

.profile-header {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 18px;
}
.ph-main { display: flex; align-items: flex-start; gap: 18px; }
.ph-avatar {
  width: 72px; height: 72px; border-radius: 50%; flex: 0 0 auto;
  background: var(--green-soft); color: var(--green-dark);
  display: grid; place-items: center; font-weight: 800; font-size: 1.6rem;
}
.ph-info { flex: 1; min-width: 0; }
.ph-name-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ph-name { margin: 0; font-size: 1.5rem; }
.ph-sub { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.ph-contacts { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 12px; }
.contact-row { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); }
.contact-row .ic { color: var(--muted); }
.ph-actions { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.ph-actions .btn { white-space: nowrap; }
.btn.ghost { border: 1px solid var(--border); background: #fff; color: var(--text); }
.btn.ghost:hover { background: var(--bg); border-color: var(--green); color: var(--green-dark); }

.note-box {
  margin-top: 18px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: .9rem;
}
.note-box .note-lbl { font-size: .68rem; font-weight: 800; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }

@media (max-width: 640px) { .ph-main { flex-wrap: wrap; } .ph-actions { flex-direction: row; width: 100%; } }

/* Tab navigation della scheda */
.ctabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.ctab {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 12px 16px; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer;
}
.ctab:hover { color: var(--text); }
.ctab.active { color: var(--green-dark); border-bottom-color: var(--green); }
.ctab .ic { color: currentColor; }

/* Intestazione lista asset */
.assets-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.assets-count { color: var(--muted); font-weight: 600; }

/* Asset (locali) — wide cards con foto in alto */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; }
.asset-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s ease, transform .15s ease;
}
.asset-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.asset-photo { height: 150px; background-size: cover; background-position: center; background-color: var(--green-soft); }
.asset-photo.placeholder { display: grid; place-items: center; color: var(--green); background: linear-gradient(135deg, var(--green-soft), #f4faf6); }
.asset-body { padding: 16px 18px; }
.asset-title { font-weight: 700; font-size: 1.1rem; }
.asset-addr { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .88rem; margin: 6px 0 14px; }
.asset-addr .ic { color: var(--muted); }
.asset-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }
.asset-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: .82rem; font-weight: 600; color: var(--text);
  background: var(--bg); padding: 4px 10px; border-radius: 999px;
}
.asset-chip .ic { width: 14px; height: 14px; color: var(--muted); }
.asset-chip.price { background: var(--green-soft); color: var(--green-dark); }
.asset-chip.price .ic { color: var(--green-dark); }
.asset-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .stat-val { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.stat .stat-lbl { color: var(--muted); font-size: .82rem; margin-top: 6px; }
.stat.danger { border-left: 4px solid var(--danger); }
.stat.danger .stat-val { color: var(--danger); }
.stat.warn { border-left: 4px solid var(--warn); }
.stat.warn .stat-val { color: var(--warn); }
.stat.ok { border-left: 4px solid var(--green); }

.dash-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .dash-2col { grid-template-columns: 1fr; } }

.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-row .bar-lbl { width: 38%; font-size: .88rem; }
.bar-row .bar-track { flex: 1; height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: var(--green); border-radius: 999px; }
.bar-row .bar-val { width: 36px; text-align: right; font-weight: 700; font-size: .88rem; }

.trend { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 10px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.trend-bar { width: 70%; background: var(--green); border-radius: 6px 6px 0 0; min-height: 3px; transition: height .2s ease; }
.trend-col:hover .trend-bar { background: var(--green-dark); }
.trend-x { font-size: .7rem; color: var(--muted); margin-top: 6px; }

.section-title { font-size: 1.05rem; font-weight: 700; margin: 26px 0 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ============================================================
   Rifiniture mobile (<=768px): tipografia compatta, bottoni
   d'azione piu' piccoli, griglie a 1 colonna, tabelle a card.
   ============================================================ */
@media (max-width: 768px) {
  /* Intestazione pagina: titolo compatto, azione piu' piccola. */
  .page-head { gap: 10px 12px; margin-bottom: 16px; align-items: center; }
  .page-head h1 { font-size: 1.2rem; }
  .page-head .sub { font-size: .82rem; }
  .page-head .btn,
  .page-head .btn.primary { min-height: 32px; padding: 5px 10px; font-size: .76rem; gap: 5px; border-radius: 7px; }
  .page-head .btn svg { width: 16px; height: 16px; }
  .section-title { font-size: .98rem; }
  .ph-name { font-size: 1.25rem; }

  /* Card cliente: testo piu' piccolo e allineato; tutta la card cliccabile. */
  .client-card { padding: 14px 14px 10px; cursor: pointer; }
  .cc-name { font-size: .92rem; }
  .cc-row { font-size: .82rem; gap: 8px; }
  .cc-avatar { width: 38px; height: 38px; font-size: .9rem; }
  .cc-count { font-size: .8rem; }
  .badge { font-size: .7rem; padding: 2px 8px; }

  /* Card generica (aree, asset): intestazione che va a capo. */
  .card { padding: 14px; }
  .card .card-top { flex-wrap: wrap; gap: 8px; }
  .card .title { font-size: .96rem; }
  .card-top-actions { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
  .card-top-actions .btn.small { flex: 1 1 auto; }
  .btn.small { padding: 6px 10px; min-height: 34px; font-size: .8rem; }

  /* Griglie a 1 colonna (evita overflow da minmax fisso). */
  .asset-grid, .grid { grid-template-columns: 1fr; }

  /* ---- Tabelle "stack": ogni riga diventa una card etichettata ---- */
  table.data.stack { font-size: .86rem; }
  table.data.stack thead { display: none; }
  table.data.stack, table.data.stack tbody { display: block; width: 100%; }
  table.data.stack tr {
    display: block; padding: 10px 12px; border-bottom: 1px solid var(--border);
  }
  table.data.stack tr:last-child { border-bottom: none; }
  table.data.stack tr:hover td { background: transparent; }
  table.data.stack td {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 5px 0; border: none; text-align: right;
  }
  table.data.stack td::before {
    content: attr(data-label);
    color: var(--muted); font-weight: 700; font-size: .72rem;
    text-transform: uppercase; letter-spacing: .02em; text-align: left;
    flex: 0 0 auto; white-space: nowrap;
  }
  /* Cella azioni a tutta larghezza, bottoni che riempiono la riga. */
  table.data.stack td.actions { flex-wrap: wrap; justify-content: flex-start; }
  table.data.stack td.actions::before { width: 100%; margin-bottom: 2px; }
  table.data.stack td.actions .btn { flex: 1 1 auto; margin: 0; }
}

/* ============================================================
   Interventi: griglia di schede (tile) scrollabile + paginazione.
   Le schede scorrono dentro al contenitore; se troppe -> pagine.
   ============================================================ */
.int-scroll {
  max-height: 62vh; overflow-y: auto;
  padding: 4px; margin: 0 -4px;
  -webkit-overflow-scrolling: touch;
}
.int-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  align-items: stretch;
}
.int-tile {
  display: flex; flex-direction: column; gap: 8px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.int-tile:hover { box-shadow: var(--shadow-hover); }
.int-tile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.int-date { font-weight: 700; font-size: .92rem; }
.int-cli { font-weight: 700; font-size: 1rem; line-height: 1.2; word-break: break-word; }
.int-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; }
.int-tile-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.int-tile-foot .btn { flex: 1 1 auto; }

.pager { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.pager .pg {
  min-width: 38px; height: 38px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  font-weight: 600; color: var(--text); cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.pager .pg:hover { background: var(--bg); }
.pager .pg.active { background: var(--green); border-color: var(--green); color: #fff; }
.pager .pg[disabled] { opacity: .45; cursor: not-allowed; }
.pager .pg-info { color: var(--muted); font-size: .9rem; padding: 0 4px; }

@media (max-width: 768px) {
  .int-grid { grid-template-columns: 1fr; }
  .int-scroll { max-height: none; padding: 0; margin: 0; overflow: visible; }
}
