*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f3ee;
  --bg-card: #ffffff;
  --ink: #1a1714;
  --ink-soft: #5c5650;
  --ink-muted: #9b948c;
  --accent: #c8410a;
  --accent-light: #f4e8e1;
  --border: #e2ddd7;
  --sidebar-bg: #1a1714;
  --sidebar-ink: #f5f3ee;
  --sidebar-muted: #9b8f87;
  --tag-bg: #eeeae4;
  --shadow: 0 2px 12px rgba(26,23,20,0.08);
  --shadow-hover: 0 8px 32px rgba(26,23,20,0.14);
  --radius: 10px;
}

html { scroll-behavior: smooth; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ── */
header {
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  padding: 28px 40px 24px;
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}
.header-title { flex: 1; min-width: 220px; }
.header-title h1 {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.header-title p {
  color: var(--sidebar-muted);
  font-size: 0.85rem;
  margin-top: 6px;
  font-weight: 300;
}
.header-count {
  font-size: 0.8rem;
  color: var(--sidebar-muted);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 4px 14px;
  white-space: nowrap;
  align-self: center;
}
#count-num { color: var(--sidebar-ink); font-weight: 600; }

/* ── SEARCH BAR ── */
.search-wrap {
  background: var(--sidebar-bg);
  padding: 0 40px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.search-inner {
  position: relative;
  max-width: 680px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sidebar-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: var(--sidebar-ink);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 11px 14px 11px 42px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#search::placeholder { color: var(--sidebar-muted); }
#search:focus { border-color: var(--accent); background: rgba(255,255,255,0.12); }

/* ── LAYOUT ── */
.layout {
  display: flex;
  flex: 1;
  align-items: flex-start;
}

/* ── SIDEBAR ── */
aside {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  min-height: 100%;
  padding: 28px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.filter-group { margin-bottom: 28px; }
.filter-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-options { display: flex; flex-direction: column; gap: 4px; }
.filter-btn {
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  color: rgba(245,243,238,0.7);
  font-family: inherit;
  font-size: 0.83rem;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.filter-btn:hover { background: rgba(255,255,255,0.07); color: var(--sidebar-ink); }
.filter-btn.active { background: var(--accent); color: #fff; font-weight: 500; }
.filter-btn .badge {
  font-size: 0.7rem;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 26px;
  text-align: center;
}
.filter-btn.active .badge { background: rgba(255,255,255,0.25); }
.reset-btn {
  display: block;
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--sidebar-muted);
  font-family: inherit;
  font-size: 0.78rem;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 24px;
  transition: background 0.15s, color 0.15s;
}
.reset-btn:hover { background: rgba(255,255,255,0.12); color: var(--sidebar-ink); }

/* ── MAIN ── */
main {
  flex: 1;
  padding: 30px 36px;
  min-width: 0;
}
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 10px;
}
.results-text {
  font-size: 0.82rem;
  color: var(--ink-muted);
}
.sort-select {
  font-family: inherit;
  font-size: 0.82rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}

/* ── ACTIVE FILTERS CHIPS ── */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  padding: 4px 10px 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
}
.chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  opacity: 0.7;
}
.chip button:hover { opacity: 1; }

/* ── GRID ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px;
}

/* ── CARD ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  animation: fadeIn 0.25s ease both;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
  border-color: #ccc7c0;
}
.card-header { display: flex; flex-direction: column; gap: 6px; }
.card-id { font-size: 0.68rem; color: var(--ink-muted); letter-spacing: 0.06em; }
.card-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.08rem;
  line-height: 1.3;
  color: var(--ink);
}
.card-operatore {
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 500;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}
.tag-provincia { background: #e8f0fe; color: #1a56db; }
.tag-orario { background: #fef3c7; color: #92400e; }
.tag-cert { background: #d1fae5; color: #065f46; }
.tag-esenzione { background: #ede9fe; color: #5b21b6; }

.card-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.card-info-row { display: flex; gap: 14px; flex-wrap: wrap; }
.card-stat { font-size: 0.78rem; color: var(--ink-soft); display: flex; align-items: center; gap: 4px; }
.card-stat svg { color: var(--ink-muted); }
.card-cost {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.cost-private {
  font-family: 'DM Serif Display', serif;
  font-size: 1.25rem;
  color: var(--accent);
  line-height: 1.1;
}
.cost-sub {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.62rem;
  color: var(--ink-muted);
  text-align: right;
  line-height: 1.4;
}

.filter-options.scrollable {
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.filter-options.scrollable::-webkit-scrollbar { width: 4px; }
.filter-options.scrollable::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* ── MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,23,20,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 14px;
  max-width: 680px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(26,23,20,0.25);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
.modal-head {
  padding: 28px 28px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.modal-head-text { flex: 1; }
.modal-head-text small { font-size: 0.72rem; color: var(--ink-muted); }
.modal-head-text h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem;
  font-weight: 400;
  margin: 4px 0 8px;
  line-height: 1.25;
}
.modal-close {
  background: var(--tag-bg);
  border: none;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--border); }
.modal-body { padding: 24px 28px 32px; }
.modal-section { margin-bottom: 22px; }
.modal-section h3 {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
}
.modal-section p {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--ink-soft);
}
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-stat {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
}
.modal-stat .label { font-size: 0.68rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.modal-stat .value { font-size: 0.95rem; font-weight: 500; color: var(--ink); }
.modal-contact a { color: var(--accent); text-decoration: none; font-size: 0.88rem; }
.modal-contact a:hover { text-decoration: underline; }

/* ── EMPTY ── */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-muted);
}
.empty svg { margin-bottom: 16px; opacity: 0.4; }
.empty h3 { font-family: 'DM Serif Display', serif; font-size: 1.4rem; font-weight: 400; margin-bottom: 6px; color: var(--ink-soft); }
.empty p { font-size: 0.85rem; }

/* ── LOADING ── */
.loading { text-align: center; padding: 100px 20px; color: var(--ink-muted); font-size: 0.9rem; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PAGINATION ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 36px;
  flex-wrap: wrap;
}
.page-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.page-btn:hover { background: var(--accent-light); border-color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-ellipsis { color: var(--ink-muted); padding: 0 4px; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  header { padding: 20px 20px 16px; }
  .search-wrap { padding: 0 20px 16px; }
  aside { display: none; }
  main { padding: 20px 16px; }
  .grid { grid-template-columns: 1fr; }
  .modal { max-height: 95vh; }
  .modal-grid { grid-template-columns: 1fr; }
}
