/* PALVION Web — CSS minimale scritta a mano, mobile-first.
   Niente libreria esterna vendorizzata (Pico.css) perché questa sessione
   non aveva accesso di rete per scaricarla: questo file la sostituisce
   con qualcosa di piccolo e su misura, senza dipendenze. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1e4ed8;
  --success-bg: #dcfce7;
  --success-text: #14532d;
  --danger-bg: #fee2e2;
  --danger-text: #7f1d1d;
  --warn-bg: #fef3c7;
  --warn-text: #78350f;
  --header-bg: #1f2933;
  --header-text: #f4f6f8;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111417;
    --surface: #1b1f24;
    --text: #e5e7eb;
    --text-muted: #9aa3ae;
    --border: #2c333b;
    --success-bg: #123a24;
    --success-text: #86efac;
    --danger-bg: #3a1414;
    --danger-text: #fca5a5;
    --warn-bg: #3a2e0f;
    --warn-text: #fde68a;
    --header-bg: #0d1013;
  }
}

* { box-sizing: border-box; }

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.4;
  padding-bottom: 76px; /* spazio per la bottom nav */
}

a { color: var(--primary); text-decoration: none; }

/* Logo aziendale come sfondo leggero, solo nelle pagine dopo il login.
   Un pseudo-elemento fisso e semi-trasparente dietro tutto il resto,
   cosi' non interferisce con la leggibilita' del contenuto (che sta
   sempre su .card/.surface con sfondo pieno). */
body.authenticated { position: relative; }
body.authenticated::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("/static/img/logo.png");
  background-repeat: no-repeat;
  background-position: center 42%;
  background-size: min(75vw, 420px);
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header-bg);
  color: var(--header-text);
  padding: 14px 16px;
}
.topbar-title { font-weight: 600; font-size: 1.1rem; }

/* Striscia di saluto sopra l'intestazione della pagina: nome di chi ha
   fatto login a sinistra, nome azienda a destra. Non "sticky" come
   .topbar (altrimenti si sovrapporrebbero restando entrambe in cima):
   scorre via col contenuto, resta la barra col titolo pagina/Esci fissa. */
.topbar-greeting {
  position: static;
  padding: 8px 16px;
  font-size: 0.78rem;
  background: var(--surface);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.topbar-hello { font-weight: 600; }
.topbar-company { font-weight: 500; letter-spacing: 0.02em; }

.content {
  position: relative;
  z-index: 1;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 20;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 10px;
  color: var(--text-muted);
  font-size: 0.72rem;
}
.bottom-nav a.active { color: var(--primary); }
.nav-icon { font-size: 1.3rem; }

/* ===== Tile grid (home) ===== */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  color: var(--text);
}
.tile-icon { font-size: 1.6rem; }
.tile-title { font-size: 0.85rem; font-weight: 500; }
.tile-live { border-color: var(--primary); }
.tile-disabled { opacity: 0.5; }
.tile-grid-muted { margin-top: 4px; }
.tile-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--border);
  color: var(--text);
  font-size: 0.7rem;
  border-radius: 999px;
  padding: 1px 7px;
}
.tile-badge-alert { background: var(--danger-bg); color: var(--danger-text); }

.section-title { margin: 20px 0 4px; font-size: 1rem; }
.muted { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 10px; }
.muted-sm { color: var(--text-muted); font-size: 0.8rem; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card-link { display: block; color: var(--text); }
.card-link-inner { display: block; color: var(--text); }
.card-list { display: flex; flex-direction: column; }
.compact-card { padding: 10px 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { margin: 4px 0 2px; font-size: 1.05rem; }
.card-title-sm { font-weight: 600; font-size: 0.92rem; }
.card-sub { margin: 2px 0; color: var(--text-muted); font-size: 0.9rem; }
.card-meta { margin: 2px 0 0; color: var(--text-muted); font-size: 0.82rem; }

.text-negative { color: var(--danger-text); }
.text-positive { color: var(--success-text); }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  white-space: nowrap;
}
.badge-attivo { background: var(--success-bg); color: var(--success-text); }
.badge-chiuso { background: var(--warn-bg); color: var(--warn-text); }
.badge-cliente-riga { background: var(--warn-bg); color: var(--warn-text); margin-top: 6px; }
.badge-priority-alta { background: var(--danger-bg); color: var(--danger-text); }
.badge-priority-media { background: var(--warn-bg); color: var(--warn-text); }
.badge-priority-bassa { background: var(--border); color: var(--text-muted); }

.alert-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.alert-source { font-size: 0.75rem; color: var(--text-muted); text-transform: capitalize; }
.priority-alta { border-left: 4px solid var(--danger-text); }
.priority-media { border-left: 4px solid var(--warn-text); }
.priority-bassa { border-left: 4px solid var(--border); }

/* ===== Forms ===== */
.form-card label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.form-card input,
.form-card select,
.form-card textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.form-card textarea { resize: vertical; }
.form-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-row input[type="date"] { flex: 1; min-width: 140px; }

.search-form { display: flex; gap: 8px; margin-bottom: 12px; }
.search-form input[type="search"] {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.search-form-multi { flex-wrap: wrap; }
.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.checkbox-row input { width: auto; }

.inline-form { display: inline; }
.inline-edit { margin-top: 8px; }
.inline-edit summary { font-size: 0.82rem; color: var(--primary); cursor: pointer; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-new { margin-bottom: 14px; }
.btn-toggle { margin-top: 8px; }
.link-btn { background: none; border: none; color: var(--header-text); font-size: 0.85rem; cursor: pointer; padding: 4px; }

.detail-head { margin-bottom: 14px; }
.detail-title { margin: 4px 0 2px; font-size: 1.25rem; }
.detail-actions { display: flex; gap: 8px; margin-top: 12px; }

.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  padding: 10px 14px;
}
.section-block summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.section-block .card-list { margin-top: 10px; }

.empty-state { text-align: center; color: var(--text-muted); padding: 30px 10px; }

.notice { padding: 10px 14px; border-radius: 8px; font-size: 0.85rem; margin-bottom: 12px; }
.notice-error { background: var(--danger-bg); color: var(--danger-text); }
.notice-warn { background: var(--warn-bg); color: var(--warn-text); }
.notice-info { background: var(--border); color: var(--text-muted); }

.login-wrap { max-width: 360px; margin: 56px auto 0; text-align: center; }
.login-logo { width: 100%; max-width: 240px; height: auto; margin: 0 auto 28px; display: block; }

/* ===== Ricerca cliente/cantiere scrivendo il nome (come sul desktop) ===== */
.combo { position: relative; }
.combo-results {
  position: absolute;
  z-index: 20;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}
.combo-result-item {
  padding: 10px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.combo-result-item:last-child { border-bottom: none; }
.combo-result-item:hover,
.combo-result-item:active { background: var(--border); }

/* ===== Righe ripetibili (materiali / collaboratori secondari) ===== */
.repeater-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.repeater-row label { flex: 1; min-width: 110px; margin-bottom: 0 !important; }
.repeater-row .btn-repeater-remove { flex: 0 0 auto; }
.repeater-add { margin: 4px 0 18px; }
.login-title { margin: 0 0 20px; }

/* ===== Allegati (upload inline dentro le sezioni <details>) ===== */
.upload-inline { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.upload-inline .form-row { align-items: flex-end; }
.upload-inline .btn { margin-top: 8px; }

/* ===== Navigazione mese per mese (rapportini) ===== */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.month-nav-label { font-weight: 700; }
.month-nav-arrows { display: flex; gap: 6px; }

/* ===== Azioni multiple su una card in elenco (es. spese: PDF + pagamento) ===== */
.card-actions-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.card-actions-row .inline-form { display: inline-flex; }
