/* ══════════════════════════════════════════════════════════════
   APL Calabria 2026 — Vista tabellare — Tema chiaro
   ══════════════════════════════════════════════════════════════ */

:root {
  /* Palette base */
  --navy:        #1c2e4a;
  --navy-mid:    #243a5e;
  --cream:       #f5f1ea;
  --gold:        #9a6b0e;
  --gold-light:  #c48f20;
  --gold-dim:    rgba(154,107,14,0.12);
  --terra:       #c03318;

  /* Toni superficie */
  --bg-page:     #edeae3;
  --bg-surface:  #f8f5f0;
  --bg-card:     #ffffff;
  --bg-stripe:   rgba(28,46,74,0.022);

  /* Testo */
  --txt-h:       #1c2e4a;
  --txt-body:    rgba(28,46,74,0.88);
  --txt-muted:   rgba(28,46,74,0.58);
  --txt-faint:   rgba(28,46,74,0.38);

  /* Bordi */
  --bd:          rgba(28,46,74,0.12);
  --bd-mid:      rgba(28,46,74,0.20);
  --bd-strong:   rgba(28,46,74,0.30);

  /* Province (invariate) */
  --c-cs: #e05a3a;
  --c-cz: #c49020;
  --c-rc: #3a9a72;
  --c-kr: #4a8fc4;
  --c-vv: #9a5aa8;

  /* Layout */
  --top-h:    58px;
  --filter-h: 58px;
  --stats-h:  40px;
  --pag-h:    52px;
}

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html, body {
  height: 100%;
  background: var(--bg-page);
  font-family: 'Outfit', system-ui, sans-serif;
  color: var(--txt-body);
}

/* ─── Accessibilità ──────────────────────────────────────────── */
.sr-only {
  position:absolute; width:1px; height:1px;
  padding:0; margin:-1px; overflow:hidden;
  clip:rect(0,0,0,0); white-space:nowrap; border:0;
}
.skip-link {
  position:absolute; top:-100%; left:12px; z-index:9999;
  background:var(--navy); color:var(--cream);
  border:2px solid var(--gold); border-radius:4px;
  padding:8px 18px; font-size:14px; font-weight:500;
  text-decoration:none; transition:top 0.18s;
}
.skip-link:focus { top:12px; }
:focus-visible   { outline:2px solid var(--gold); outline-offset:2px; border-radius:2px; }
:focus:not(:focus-visible) { outline:none; }

/* ══════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════ */
.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ─── Top bar — scuro per identità istituzionale ─────────────── */
.top-bar {
  height: var(--top-h);
  background: var(--navy);
  border-bottom: 3px solid var(--gold);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 16px rgba(0,0,0,0.18);
  z-index: 10;
  position: relative;
}

.top-brand { display:flex; align-items:baseline; gap:14px; flex:1; }

.top-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  color: #f5f1ea;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.top-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--gold-light);
  background: rgba(154,107,14,0.20);
  border: 1px solid rgba(154,107,14,0.40);
  padding: 3px 10px;
  border-radius: 2px;
  text-transform: uppercase;
  white-space: nowrap;
}

.top-actions { display:flex; align-items:center; gap:10px; }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #1c2e4a;
  text-decoration: none;
  border: none;
  padding: 9px 18px;
  border-radius: 5px;
  transition: all 0.18s;
  background: #f5f1ea;
  box-shadow: 0 2px 8px rgba(0,0,0,0.20);
}
.btn-back:hover {
  background: #ffffff;
  box-shadow: 0 3px 14px rgba(0,0,0,0.28);
  transform: translateY(-1px);
}

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--gold-light);
  background: rgba(154,107,14,0.18);
  border: 1px solid rgba(154,107,14,0.40);
  padding: 7px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.18s;
}
.btn-export:hover { background:rgba(154,107,14,0.30); border-color:rgba(154,107,14,0.65); color:#f5f1ea; }

/* ─── Barra filtri — sfondo chiaro ───────────────────────────── */
.filter-bar {
  height: var(--filter-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bd);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.filter-bar input[type="text"],
.filter-bar select {
  background: var(--bg-card);
  border: 1px solid var(--bd-mid);
  border-radius: 5px;
  padding: 8px 13px;
  font-size: 14.5px;
  font-family: 'Outfit', sans-serif;
  color: var(--txt-body);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.filter-bar input[type="text"] { min-width: 220px; }
.filter-bar input[type="text"]::placeholder { color: var(--txt-faint); }
.filter-bar input[type="text"]:focus-visible,
.filter-bar select:focus-visible {
  border-color: var(--gold);
  outline: 2px solid rgba(154,107,14,0.30);
  outline-offset: 0;
  box-shadow: 0 0 0 3px rgba(154,107,14,0.12);
}
.filter-bar select {
  min-width: 160px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(28%2C46%2C74%2C0.45)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.filter-bar select option { background: white; color: var(--txt-body); }

.filter-sep { width:1px; height:24px; background:var(--bd-mid); flex-shrink:0; }

.btn-reset-bar {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--terra);
  background: rgba(192,51,24,0.06);
  border: 1px solid rgba(192,51,24,0.28);
  padding: 8px 14px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s;
}
.btn-reset-bar:hover { background:rgba(192,51,24,0.14); border-color:var(--terra); }

/* ─── Barra statistiche ──────────────────────────────────────── */
.stats-bar {
  height: var(--stats-h);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 20px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--bd);
  background: var(--bg-surface);
}

.stats-bar-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--txt-muted);
}
.stats-bar-count strong { color: var(--txt-h); font-size: 15px; font-weight: 700; }

.stats-prov-pills { display:flex; gap:6px; flex-wrap:wrap; }

.prov-pill {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s, box-shadow 0.15s;
  user-select: none;
}
.prov-pill:hover   { opacity:0.80; transform:translateY(-1px); box-shadow:0 2px 6px rgba(0,0,0,0.12); }
.prov-pill:focus-visible { outline:2px solid var(--gold); outline-offset:2px; }
.prov-pill.inactive { opacity:0.28; }

/* ══════════════════════════════════════════════════════════════
   AREA TABELLA — sfondo bianco, massima leggibilità
   ══════════════════════════════════════════════════════════════ */
.table-region {
  flex: 1;
  overflow: auto;
  background: var(--bg-card);
  scrollbar-width: thin;
  scrollbar-color: var(--bd-strong) transparent;
}
.table-region::-webkit-scrollbar       { width:6px; height:6px; }
.table-region::-webkit-scrollbar-track { background:var(--bg-surface); }
.table-region::-webkit-scrollbar-thumb { background:var(--bd-strong); border-radius:3px; }

.main-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  min-width: 820px;
}

/* Intestazioni sticky su sfondo quasi-bianco */
.main-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-surface);
  border-bottom: 2px solid var(--bd-mid);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--txt-muted);
  font-weight: 600;
  padding: 13px 18px 11px;
  text-align: left;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.main-table thead th.sortable:hover { color: var(--txt-h); background: #edeae3; }
.main-table thead th:focus-visible  { outline:2px solid var(--gold); outline-offset:-2px; color:var(--txt-h); }

.th-sort-icon { display:inline-block; margin-left:5px; opacity:0.28; font-style:normal; font-size:10px; }
th.asc  .th-sort-icon::after { content:"↑"; opacity:1; color:var(--gold); }
th.desc .th-sort-icon::after { content:"↓"; opacity:1; color:var(--gold); }

/* Colonne */
.col-num  { width:50px;     text-align:center; cursor:default !important; }
.col-ente { min-width:320px; }
.col-prov { width:88px; }
.col-com  { min-width:140px; }
.col-sedi { min-width:220px; }   /* più larga per ridurre i ritorni a capo */
.col-email{ min-width:200px; }
.col-tel  { min-width:130px; }

/* Righe */
.main-table tbody tr {
  border-bottom: 1px solid var(--bd);
  cursor: pointer;
  transition: background 0.09s;
}
.main-table tbody tr:nth-child(even) { background: var(--bg-stripe); }
.main-table tbody tr:hover    { background: rgba(154,107,14,0.07) !important; }
.main-table tbody tr.selected {
  background: rgba(154,107,14,0.13) !important;
  box-shadow: inset 3px 0 0 var(--gold);
}
.main-table tbody tr:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
  background: rgba(154,107,14,0.08) !important;
}

/* Celle */
.main-table tbody td {
  padding: 11px 18px;
  font-size: 14.5px;
  color: var(--txt-body);
  line-height: 1.4;
  vertical-align: middle;
}
.td-num  { font-family:'IBM Plex Mono',monospace; font-size:12px; color:var(--txt-faint); text-align:center; }
.td-ente { font-weight:600; color:var(--txt-h); }

.prov-badge {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  border: 1.5px solid transparent;
}

.td-sedi {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: var(--txt-muted);
}

.td-email a, .td-tel a {
  color: var(--txt-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-family: 'IBM Plex Mono', monospace;
  transition: color 0.15s;
}
.td-email a:hover, .td-tel a:hover { color: var(--gold); text-decoration: underline; }

.empty-row td {
  text-align: center;
  padding: 64px 20px;
  color: var(--txt-faint);
  font-size: 15px;
  font-style: italic;
  cursor: default;
  background: var(--bg-card) !important;
}

/* ══════════════════════════════════════════════════════════════
   PAGINAZIONE — sfondo chiaro
   ══════════════════════════════════════════════════════════════ */
.pag-bar {
  height: var(--pag-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-top: 1px solid var(--bd-mid);
  background: var(--bg-surface);
  flex-shrink: 0;
  gap: 16px;
  box-shadow: 0 -1px 4px rgba(0,0,0,0.05);
}

.pag-left { display:flex; align-items:center; gap:14px; }

.pag-info {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--txt-muted);
}

.pag-size-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--txt-faint);
}

.pag-size {
  background: var(--bg-card);
  border: 1px solid var(--bd-mid);
  border-radius: 4px;
  color: var(--txt-body);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  padding: 4px 9px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.pag-size:focus-visible { outline:2px solid var(--gold); outline-offset:1px; }
.pag-size option { background:white; }

.pag-right { display:flex; align-items:center; gap:4px; }

.pag-btn-t, .pag-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--bd-mid);
  color: var(--txt-muted);
  padding: 6px 11px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 34px;
  text-align: center;
  transition: all 0.12s;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.pag-btn-t:hover:not(:disabled),
.pag-num:hover {
  color: var(--txt-h);
  border-color: var(--bd-strong);
  background: #edeae3;
}
.pag-btn-t:disabled { opacity:0.25; cursor:not-allowed; box-shadow:none; }
.pag-num.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #f5f1ea;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(28,46,74,0.30);
}
.pag-nums { display:flex; gap:3px; }

/* ─── Animazioni ─────────────────────────────────────────────── */
@keyframes fade-in {
  from { opacity:0; transform:translateY(4px); }
  to   { opacity:1; transform:translateY(0); }
}
.top-bar      { animation:fade-in 0.3s ease both; }
.filter-bar   { animation:fade-in 0.3s 0.05s ease both; }
.stats-bar    { animation:fade-in 0.3s 0.10s ease both; }
.table-region { animation:fade-in 0.35s 0.14s ease both; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .top-badge  { display:none; }
  .filter-bar { height:auto; flex-wrap:wrap; padding:10px 16px; gap:8px; }
  .filter-bar input[type="text"] { min-width:0; }
  .filter-sep { display:none; }
  .stats-bar  { flex-wrap:wrap; height:auto; padding:8px 16px; gap:8px; }
  .pag-bar    { flex-wrap:wrap; height:auto; padding:10px 16px; gap:10px; }
  .top-bar    { padding:0 16px; gap:10px; }
  .pag-left   { flex-wrap:wrap; }
}
@media (max-width: 600px) {
  .top-title  { font-size:15px; }
  .btn-back, .btn-export { font-size:11.5px; padding:6px 10px; }
  .stats-prov-pills { display:none; }
}
