/* ============================================================
   Design tokens
   Palette: inchiostro blu istituzionale + oro/ocra da timbro
   ============================================================ */
:root {
  --ink: #16324F;
  --ink-light: #24486E;
  --ink-dark: #0E2338;
  --gold: #C0872A;
  --gold-light: #E3B15C;
  --paper: #EEF0EA;
  --surface: #FFFFFF;
  --border: #DEDACD;
  --text: #1C1F22;
  --text-muted: #5B6169;
  --danger: #AE3B33;
  --danger-bg: #F7E7E4;
  --success: #3E7C5A;
  --success-bg: #E4F0E7;
  --warn: #C0872A;
  --warn-bg: #F7ECD9;
  --radius: 10px;
  --radius-sm: 6px;
  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  background: var(--ink);
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(14, 35, 56, 0.25);
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.seal {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--gold-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
  color: var(--gold-light);
  flex-shrink: 0;
}
.topbar-titles h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}
.topbar-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(255,255,255,0.65);
}

/* ============================================================
   App shell / layout
   ============================================================ */
.app {
  padding: 16px 16px 96px;
  max-width: 720px;
  margin: 0 auto;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.section-header h2 {
  font-family: var(--font-display);
  font-size: 21px;
  margin: 0;
  color: var(--ink);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-light); }
.btn-gold { background: var(--gold); color: #fff; }
.btn-outline { background: transparent; color: var(--ink); border: 1.5px solid var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-icon {
  width: 38px; height: 38px; padding: 0; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--border); color: var(--ink);
}
.btn-block { width: 100%; }
.fab {
  position: fixed;
  right: 18px;
  bottom: 86px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  border: none;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(192, 135, 42, 0.45);
  cursor: pointer;
  z-index: 15;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:hover { box-shadow: 0 3px 10px rgba(22,50,79,0.08); border-color: #C9C4B4; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title { font-weight: 600; font-size: 15.5px; color: var(--ink-dark); }
.card-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.card-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }

/* Stamp-style status badge — motivo distintivo dell'app */
.stamp {
  display: inline-flex;
  align-items: center;
  border: 1.5px dashed currentColor;
  border-radius: 20px;
  padding: 3px 10px 3px 9px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  transform: rotate(-2deg);
}
.stamp-aperta, .stamp-dafare { color: var(--ink); background: rgba(22,50,79,0.06); }
.stamp-lavorazione, .stamp-attesa { color: var(--warn); background: var(--warn-bg); }
.stamp-completata, .stamp-pagata { color: var(--success); background: var(--success-bg); }
.stamp-archiviata { color: var(--text-muted); background: rgba(91,97,105,0.08); }
.stamp-scaduta, .stamp-nonpagata { color: var(--danger); background: var(--danger-bg); }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(22,50,79,0.07);
  border-radius: 5px;
  padding: 3px 8px;
}

/* ============================================================
   Empty state
   ============================================================ */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty h3 { font-family: var(--font-display); color: var(--ink); margin-bottom: 6px; }

/* ============================================================
   Forms
   ============================================================ */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--ink);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field textarea { resize: vertical; min-height: 70px; }

/* Chip select — preferenza consolidata sugli input a scelta rapida */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s ease;
}
.chip.selected { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ============================================================
   Bottom nav
   ============================================================ */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 6px 2px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}
.nav-item svg { width: 22px; height: 22px; fill: currentColor; }
.nav-item.active { color: var(--ink); }
.nav-item.active svg { fill: var(--gold); }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(14,35,56,0.45);
  display: flex; align-items: flex-end;
  z-index: 50;
}
.modal-sheet {
  background: var(--paper);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h2 { font-family: var(--font-display); font-size: 19px; margin: 0; color: var(--ink); }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: rgba(22,50,79,0.08); color: var(--ink); font-size: 18px; cursor: pointer;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; justify-content: center; }
  .modal-sheet { max-width: 520px; border-radius: 16px; }
}

/* ============================================================
   Dashboard widgets
   ============================================================ */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--ink); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-card.gold { border-color: var(--gold-light); }
.stat-card.gold .stat-value { color: var(--gold); }

.subsection-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin: 22px 0 10px;
}

/* Calendar tabs (giorno) */
.day-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; }
.day-pill {
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  text-align: center;
  cursor: pointer;
  min-width: 52px;
}
.day-pill.today { border-color: var(--gold); }
.day-pill.selected { background: var(--ink); border-color: var(--ink); color: #fff; }
.day-pill .dow { font-size: 10px; text-transform: uppercase; opacity: 0.7; }
.day-pill .dnum { font-family: var(--font-display); font-size: 17px; font-weight: 700; }

.search-bar {
  display: flex; gap: 8px; margin-bottom: 14px;
}
.search-bar input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
}

.filter-row { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; }
.filter-row .chip { flex-shrink: 0; }

.detail-block { margin-bottom: 18px; }
.detail-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); font-weight: 600; }
.detail-value { font-size: 15px; color: var(--text); margin-top: 2px; }

.loading { text-align: center; padding: 40px; color: var(--text-muted); font-size: 14px; }
