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

:root {
  --gold:       #b8960c;
  --gold-light: #d4a820;
  --gold-pale:  #f5ecc8;
  --bg:         #faf9f5;
  --card:       #ffffff;
  --text:       #1c1409;
  --muted:      #6b5e43;
  --border:     #e2d9c0;
  --radius:     10px;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
  --green:      #2d7a50;
  --green-bg:   #e8f5ee;
  --red:        #c0392b;
  --red-bg:     #fdecea;
  --blue:       #1a5c8a;
  --blue-bg:    #e8f1fa;
  --orange:     #c06a12;
  --orange-bg:  #fef0e2;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Navbar ─────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--text);
  color: var(--gold-light);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.navbar-brand {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-decoration: none;
  color: var(--gold-light);
}
.navbar-brand span { color: #fff; font-weight: 300; }
.navbar-actions { display: flex; gap: .5rem; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
  overflow-x: hidden;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.1rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: filter .15s, transform .1s;
  min-height: 44px;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-gold    { background: var(--gold);      color: #fff; }
.btn-gold:hover { filter: brightness(1.12); }
.btn-outline { background: transparent; border: 2px solid var(--gold); color: var(--gold); }
.btn-outline:hover { background: var(--gold-pale); }
.btn-green   { background: var(--green);     color: #fff; }
.btn-green:hover { filter: brightness(1.12); }
.btn-red     { background: var(--red);       color: #fff; }
.btn-red:hover { filter: brightness(1.12); }
.btn-blue    { background: var(--blue);      color: #fff; }
.btn-blue:hover { filter: brightness(1.12); }
.btn-ghost   { background: #f0ece0; color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-sm      { padding: .35rem .75rem; font-size: .8rem; min-height: 36px; }
.btn-full    { width: 100%; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group  { margin-bottom: 1rem; }
.form-label  { display: block; font-size: .85rem; font-weight: 600;
               color: var(--muted); margin-bottom: .35rem; }
.form-control {
  width: 100%;
  padding: .65rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: #fdfcf8;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
}
.form-control:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184,150,12,.15);
  background: #fff;
}
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control    { appearance: none; cursor: pointer; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 540px) { .form-row { grid-template-columns: 1fr; } }

/* ── Badge stato ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-lavorazione { background: var(--orange-bg); color: var(--orange); }
.badge-preventivo  { background: #f0e6ff;          color: #7c3aed; }
.badge-pronta      { background: var(--green-bg);  color: var(--green); }
.badge-consegnata  { background: #ececec; color: #555; }
.badge-attesa      { background: var(--blue-bg);   color: var(--blue); }
.badge-annullata   { background: var(--red-bg);    color: var(--red); }
.badge-oreficeria  { background: var(--blue-bg);   color: var(--blue); }
.badge-avvisato    { background: var(--blue-bg);   color: var(--blue); font-size: .82rem; }

/* ── Dashboard contatori ────────────────────────────────────────────────── */
.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
  margin-bottom: .9rem;
}
.dash-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem .5rem;
  text-align: center;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  transition: box-shadow .15s, transform .1s;
}
.dash-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.1); transform: translateY(-1px); }
.dash-count { font-size: 1.75rem; font-weight: 900; line-height: 1; }
.dash-label { font-size: .68rem; font-weight: 600; text-transform: uppercase;
              letter-spacing: .04em; color: var(--muted); }
.dash-green  { border-top: 3px solid var(--green); }
.dash-green  .dash-count { color: var(--green); }
.dash-blue   { border-top: 3px solid var(--blue); }
.dash-blue   .dash-count { color: var(--blue); }
.dash-orange { border-top: 3px solid var(--orange); }
.dash-orange .dash-count { color: var(--orange); }
.dash-grey   { border-top: 3px solid #999; }
.dash-grey   .dash-count { color: #666; }
@media (max-width: 540px) { .dashboard { grid-template-columns: repeat(2, 1fr); } }

/* ── Ricerca rapida ─────────────────────────────────────────────────────── */
.quick-search { margin-bottom: .75rem; }

/* ── Lista riparazioni ──────────────────────────────────────────────────── */
.rep-grid { display: flex; flex-direction: column; gap: .6rem; }

.rep-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: box-shadow .15s, border-color .15s;
}
.rep-card:hover  { box-shadow: 0 4px 16px rgba(0,0,0,.12); border-color: var(--gold); }
.rep-card.overdue { border-color: var(--red); background: var(--red-bg); }
.rep-card.overdue:hover { border-color: var(--red); }
.rep-card.overdue .rep-num { color: var(--red); }
.rep-card-header { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.rep-num  { font-size: 1.1rem; font-weight: 800; color: var(--gold); min-width: 60px; }
.rep-nome { font-weight: 600; flex: 1; }
.rep-data { font-size: .82rem; color: var(--muted); }
.rep-desc { font-size: .85rem; color: var(--muted); margin-top: .3rem;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


/* ── Dettaglio ──────────────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1.5rem; }
@media (max-width: 540px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-item label { font-size: .8rem; font-weight: 700; color: var(--muted);
                     text-transform: uppercase; letter-spacing: .05em; }
.detail-item p     { font-size: .98rem; margin-top: .15rem; }
.detail-item.full  { grid-column: 1 / -1; }

/* ── Foto ────────────────────────────────────────────────────────────────── */
.foto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
             gap: .5rem; }
.foto-item { position: relative; aspect-ratio: 1; border-radius: 8px;
             overflow: hidden; border: 2px solid var(--border); }
.foto-item img { width: 100%; height: 100%; object-fit: cover; }
.foto-del { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.55);
            color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px;
            font-size: 14px; line-height: 1; cursor: pointer; display: flex;
            align-items: center; justify-content: center; }
.foto-del:hover { background: var(--red); }

/* ── Flash messages ─────────────────────────────────────────────────────── */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: .75rem;
         font-size: .9rem; font-weight: 500; }
.flash-success { background: var(--green-bg); color: var(--green); border: 1px solid #a8d5bb; }
.flash-warning { background: var(--orange-bg); color: var(--orange); border: 1px solid #f5c48a; }
.flash-error   { background: var(--red-bg); color: var(--red); border: 1px solid #f5a8a0; }

/* ── Header pagina ──────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between;
               flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.page-title  { font-size: 1.4rem; font-weight: 800; }
.page-title small { font-size: .85rem; font-weight: 400; color: var(--muted); }

/* ── Tab actions ─────────────────────────────────────────────────────────── */
.action-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }

/* ── Loader ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Textarea grande per testo libero ────────────────────────────────────── */
.testo-input { min-height: 160px; font-family: inherit; }

/* ── WhatsApp modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: var(--radius);
  padding: 1.5rem; max-width: 480px; width: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
}
.modal-box h3 { margin-bottom: .75rem; color: var(--green); }
.modal-body   { white-space: pre-wrap; font-size: .9rem; background: var(--green-bg);
                border: 1px solid #a8d5bb; border-radius: 8px; padding: .75rem;
                margin-bottom: 1rem; }
.modal-actions { display: flex; gap: .5rem; flex-wrap: wrap; }


/* ── No results ──────────────────────────────────────────────────────────── */
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .95rem; }

/* ── Estrazione in corso ─────────────────────────────────────────────────── */
#estrai-status { font-size: .85rem; color: var(--muted); margin-top: .4rem; min-height: 1.2em; }
#form-extracted { transition: opacity .3s; }
#form-extracted.hidden { display: none; }

/* ── Pulsante Home flottante ─────────────────────────────────────────────── */
.fab-home {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 300;
  transition: filter .15s, transform .1s, box-shadow .15s;
}
.fab-home:hover  { filter: brightness(1.15); box-shadow: 0 6px 22px rgba(0,0,0,.3); }
.fab-home:active { transform: scale(.93); }
@media (max-width: 540px) {
  .fab-home { bottom: 24px; right: 16px; width: 50px; height: 50px; font-size: 1.25rem; }
}

/* ── FAB Filtri ──────────────────────────────────────────────────────────── */
.fab-filter {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 300;
  transition: filter .15s, transform .1s, box-shadow .15s;
}
.fab-filter:hover  { filter: brightness(1.15); box-shadow: 0 6px 22px rgba(0,0,0,.3); }
.fab-filter:active { transform: scale(.93); }
.fab-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: var(--red);
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}
.fab-filter.has-filters .fab-dot { display: block; }

/* ── Filter Drawer ───────────────────────────────────────────────────────── */
.filter-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 310;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.filter-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.filter-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 380px;
  max-width: 100vw;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,.18);
  z-index: 311;
  padding: 1.25rem;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.filter-drawer.open { transform: translateY(0); }
.filter-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--border);
}
.filter-drawer-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}
.filter-drawer-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: .2rem .4rem;
  border-radius: 6px;
  transition: background .15s;
}
.filter-drawer-close:hover { background: var(--border); }
.filter-drawer-actions {
  display: flex;
  gap: .6rem;
  margin-top: 1rem;
}
@media (max-width: 540px) {
  .filter-drawer { width: 100%; }
  .fab-filter { bottom: 24px; left: 16px; width: 50px; height: 50px; font-size: 1.25rem; }
}

/* ── Avviso stampante ────────────────────────────────────────────────────── */
.printer-warn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .75rem;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 600;
  background: var(--orange-bg);
  color: var(--orange);
  border: 1px solid #f5c48a;
  cursor: default;
}
