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

:root {
  --blue-900: #0a2342;
  --blue-700: #1a4d8f;
  --blue-500: #2563eb;
  --blue-100: #dbeafe;
  --blue-50:  #eff6ff;
  --gray-700: #374151;
  --gray-400: #9ca3af;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --white:    #ffffff;
  --green-600:#16a34a;
  --red-600:  #dc2626;
  --radius:   6px;
  --shadow:   0 1px 3px rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--gray-700);
  background: var(--gray-100);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--blue-500); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ──────────────────────────────────────────────────────── */
.navbar {
  background: var(--blue-900);
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 52px;
  flex-shrink: 0;
}

.navbar-brand { flex-shrink: 0; }
.brand-link { color: var(--white); font-size: 1.25rem; font-weight: 700; letter-spacing: -.5px; }
.brand-accent { color: #60a5fa; }

.navbar-search { flex: 1; max-width: 480px; min-width: 180px; display: flex; gap: .5rem; }
.search-input {
  flex: 1;
  padding: .35rem .75rem;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  background: rgba(255,255,255,.1);
  color: var(--white);
  font-size: .9rem;
}
.search-input::placeholder { color: rgba(255,255,255,.5); }
.search-input:focus { outline: none; border-color: #60a5fa; background: rgba(255,255,255,.15); }

.navbar-user { margin-left: auto; display: flex; align-items: center; align-self: center; gap: .6rem; flex-shrink: 0; }
.user-name { font-size: .82rem; opacity: .85; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); object-fit: cover; flex-shrink: 0; align-self: center; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .4rem .9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue-500); color: var(--white); border-color: var(--blue-500); }
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); }
.btn-outline { background: transparent; color: var(--white); border-color: rgba(255,255,255,.4); }
.btn-outline:hover { background: rgba(255,255,255,.1); }
.btn-search { background: var(--blue-500); color: var(--white); border-radius: var(--radius); }
.btn-search:hover { background: var(--blue-700); }
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }
.btn-lg { padding: .6rem 1.4rem; font-size: 1rem; }
.btn-google {
  background: var(--white); color: #3c4043;
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: .6rem 1.4rem; font-size: .95rem; font-weight: 500;
  display: inline-flex; align-items: center; gap: .6rem;
  box-shadow: var(--shadow);
}
.btn-google:hover { background: var(--gray-100); text-decoration: none; }

/* ── Main ────────────────────────────────────────────────────────── */
.main-content { flex: 1; padding: 2rem 2.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ── Footer ──────────────────────────────────────────────────────── */
.footer {
  background: var(--blue-900);
  color: rgba(255,255,255,.65);
  font-size: .78rem;
  padding: .5rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.footer-snapshots { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.snapshot-label { font-weight: 600; color: rgba(255,255,255,.85); }
.snapshot-date { color: #93c5fd; }
.snapshot-missing { color: rgba(255,255,255,.35); font-style: italic; }
.snapshot-sep { opacity: .35; }

/* ── Login ───────────────────────────────────────────────────────── */
.login-body { background: var(--blue-50); display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--white);
  padding: 3rem 2.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  text-align: center;
  min-width: 340px;
}
.login-title { font-size: 2.2rem; font-weight: 800; color: var(--blue-900); margin-bottom: .25rem; }
.login-subtitle { color: var(--gray-400); margin-bottom: 2rem; font-size: .9rem; }
.login-note { margin-top: 1rem; font-size: .8rem; color: var(--gray-400); }

/* ── Home hero ───────────────────────────────────────────────────── */
.home-hero {
  text-align: center;
  padding: 3rem 0 2.5rem;
}
.hero-title { font-size: 1.5rem; font-weight: 700; color: var(--blue-900); margin-bottom: 1.25rem; }
.hero-search-form { display: flex; gap: .5rem; max-width: 600px; margin: 0 auto; }
.hero-search-input {
  flex: 1; padding: .65rem 1rem;
  border: 2px solid var(--blue-100);
  border-radius: var(--radius);
  font-size: 1rem;
}
.hero-search-input:focus { outline: none; border-color: var(--blue-500); }

/* ── Stats grid ──────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--blue-500);
}
.stat-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-400); margin-bottom: .4rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--blue-900); }
.stat-empty { color: var(--gray-400); }
.stat-sub { font-size: .82rem; color: var(--gray-400); margin-top: .2rem; }
.stat-card-action { display: flex; flex-direction: column; justify-content: space-between; }

/* ── Import page ─────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header h2 { font-size: 1.35rem; color: var(--blue-900); }

.import-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}
.import-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.import-card-title { font-size: 1rem; font-weight: 700; color: var(--blue-900); margin-bottom: 1rem; border-bottom: 1px solid var(--gray-200); padding-bottom: .6rem; }
.import-current { font-size: .85rem; color: var(--gray-700); background: var(--blue-50); padding: .6rem .8rem; border-radius: var(--radius); margin-bottom: 1rem; line-height: 1.6; }
.import-empty { color: var(--gray-400); font-style: italic; }

.import-form { display: flex; flex-direction: column; gap: .75rem; }
.form-group { display: flex; flex-direction: column; gap: .25rem; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--gray-700); }
.form-control {
  padding: .4rem .6rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: .875rem;
}
.form-control:focus { outline: none; border-color: var(--blue-500); }
.form-hint { font-size: .75rem; color: var(--gray-400); }

/* ── Alerts ──────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: .9rem;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.alert-error   { background: #fee2e2; color: var(--red-600); border: 1px solid #fca5a5; }
.alert-info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }

/* ── Buttons extra ───────────────────────────────────────────────── */
.btn-outline-dark {
  background: transparent; color: var(--gray-700); border-color: var(--gray-200);
}
.btn-outline-dark:hover { background: var(--gray-100); }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: .2em .55em; border-radius: 4px;
  font-size: .72rem; font-weight: 600; letter-spacing: .3px; white-space: nowrap;
}
.badge-sm { font-size: .65rem; padding: .15em .4em; }
.badge-success   { background: #dcfce7; color: #15803d; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-danger    { background: #fee2e2; color: var(--red-600); }
.badge-secondary { background: var(--gray-200); color: var(--gray-700); }
.badge-crm       { background: #ede9fe; color: #6d28d9; }
.badge-num-rui   { background: var(--blue-100); color: var(--blue-700); font-size: .85rem; }

/* Sezione */
.badge-sez-a { background: #dbeafe; color: #1d4ed8; }
.badge-sez-b { background: #d1fae5; color: #065f46; }
.badge-sez-e { background: #fef3c7; color: #92400e; }
.badge-sez-f { background: #ede9fe; color: #6d28d9; }
.badge-sez-u { background: #fce7f3; color: #9d174d; }
.badge-sez-x { background: var(--gray-200); color: var(--gray-700); }

/* Ruolo operativo PF */
.badge-ruolo-rete   { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-ruolo-propria{ background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-ruolo-collab { background: #f9fafb; color: #6b7280; border: 1px solid #e5e7eb; }

/* Metodo matching */
.badge-metodo             { background: #f0fdf4; color: #166534; }
.badge-certo-ivass,
.badge-certo-cf,
.badge-certo-cf-nome,
.badge-certo-nome,
.badge-certo-ragsoc,
.badge-live-ivass         { background: #dcfce7; color: #15803d; }
.badge-probabile          { background: #fef9c3; color: #854d0e; }
.badge-ambiguo            { background: #ffedd5; color: #9a3412; }
.badge-non-trovato        { background: var(--gray-200); color: var(--gray-700); }
.badge-lookup-diretto     { background: var(--blue-100); color: var(--blue-700); }

/* ── Search results ──────────────────────────────────────────────── */
.search-query { color: var(--blue-500); }
.match-meta {
  display: flex; align-items: center; gap: .5rem;
  font-size: .85rem; margin-bottom: .75rem; color: var(--gray-700);
}
.results-count { font-size: .82rem; color: var(--gray-400); margin-bottom: .75rem; }

.results-table {
  width: 100%; border-collapse: collapse; background: var(--white);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  font-size: .875rem;
}
.results-table thead th {
  background: var(--blue-900); color: rgba(255,255,255,.85);
  padding: .55rem .8rem; text-align: left; font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .4px;
}
.results-table tbody tr { border-bottom: 1px solid var(--gray-200); }
.results-table tbody tr:last-child { border-bottom: none; }
.result-row { cursor: pointer; transition: background .1s; }
.result-row:hover { background: var(--blue-50); }
.results-table td { padding: .55rem .8rem; vertical-align: middle; }
.num-rui a { font-family: monospace; font-size: .85rem; font-weight: 600; color: var(--blue-700); }
.nominativo { font-weight: 500; max-width: 280px; }
.conf-pct { font-weight: 600; color: var(--blue-700); font-size: .82rem; }

/* ── Paginazione ─────────────────────────────────────────────────── */
.paginazione {
  display: flex; align-items: center; justify-content: center;
  gap: .35rem; padding: 1.25rem 0 .5rem; flex-wrap: wrap;
}
.pag-info {
  font-size: .875rem; color: var(--gray-700); font-weight: 500;
  min-width: 80px; text-align: center;
}
.pag-ellipsis {
  font-size: .875rem; color: var(--gray-400); padding: 0 .1rem;
  line-height: 1; align-self: flex-end; padding-bottom: 2px;
}
.pag-current {
  cursor: default; pointer-events: none;
}
.btn-disabled {
  opacity: .35; cursor: not-allowed; pointer-events: none;
}

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 4rem 2rem; color: var(--gray-400);
}
.empty-state p { font-size: 1rem; margin-bottom: .5rem; }
.empty-hint { font-size: .85rem; line-height: 1.9; }
.empty-hint code { background: var(--gray-100); padding: .1em .35em; border-radius: 3px; color: var(--gray-700); font-size: .8rem; }

/* ── Soggetto page ───────────────────────────────────────────────── */
.soggetto-title { font-size: 1.5rem; color: var(--blue-900); font-weight: 700; margin-bottom: .4rem; }
.soggetto-badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }

.soggetto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.data-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}
.data-card-crm { border-left: 3px solid #7c3aed; }
.data-card-crm-empty { border-left: 3px solid var(--gray-200); }
.data-card-placeholder { border-left: 3px solid var(--gray-200); opacity: .7; }
.data-card-title {
  font-size: .9rem; font-weight: 700; color: var(--blue-900);
  margin-bottom: .9rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: .5rem;
}

.field-list {
  display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem;
  font-size: .85rem;
}
.field-list dt {
  font-weight: 600; color: var(--gray-400);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .3px;
  padding-top: .1rem; white-space: nowrap;
}
.field-list dd { color: var(--gray-700); word-break: break-word; }

.inner-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.inner-table th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .3px;
  color: var(--gray-400); font-weight: 600; padding: .35rem .5rem;
  border-bottom: 1px solid var(--gray-200); text-align: left;
}
.inner-table td { padding: .35rem .5rem; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
.inner-table tr:last-child td { border-bottom: none; }

.siti-list { list-style: none; padding: 0; font-size: .85rem; }
.siti-list li { padding: .25rem 0; border-bottom: 1px solid var(--gray-100); word-break: break-all; }
.siti-list li:last-child { border-bottom: none; }

.crm-no-match { color: var(--gray-400); font-size: .875rem; font-style: italic; }
.placeholder-text { color: var(--gray-400); font-size: .85rem; font-style: italic; }

/* ── Breadcrumb ──────────────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--gray-400); margin-bottom: 1rem;
}
.breadcrumb a { color: var(--blue-500); }
.breadcrumb a:hover { text-decoration: underline; }
.bc-sep { color: var(--gray-400); }
.bc-current { color: var(--gray-700); font-weight: 600; }

/* ── Soggetto: card larga (rete) ─────────────────────────────────── */
.data-card-wide {
  grid-column: 1 / -1;
}

/* ── Rete ────────────────────────────────────────────────────────── */
.rete-subtitle { margin-left: auto; display: flex; gap: .35rem; font-weight: 400; }
.lev-badge {
  display: inline-block; padding: .15em .5em; border-radius: 4px;
  font-size: .7rem; font-weight: 600;
}
.lev-i  { background: #dbeafe; color: #1d4ed8; }
.lev-ii { background: #f0fdf4; color: #166534; }

/* ── Paginazione interna (rete) ──────────────────────────────────── */
.paginazione-inner {
  padding: .75rem 0 0;
  justify-content: flex-start;
  gap: .5rem;
}
.paginazione-inner .pag-info { min-width: auto; font-size: .8rem; }

/* ── Card subtitle ───────────────────────────────────────────────── */
.card-subtitle {
  font-size: .78rem; color: var(--gray-400); margin: -.5rem 0 .75rem;
  font-style: italic;
}

/* ── Navbar links ────────────────────────────────────────────────── */
.navbar-links { display: flex; gap: .25rem; margin: 0 .5rem; flex-shrink: 0; align-items: center; align-self: stretch; }
.nav-link {
  color: rgba(255,255,255,.8); font-size: .82rem; font-weight: 500;
  padding: .3rem .65rem; border-radius: var(--radius);
  white-space: nowrap;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }

/* ── Dropdown "Amministrazione" ──────────────────────────────────── */
.nav-dropdown {
  position: relative;
  display: flex;
  align-items: center;
  align-self: stretch; /* occupa i 52px della navbar → top:100% cade sotto la navbar */
}
.nav-dropdown-toggle { cursor: pointer; user-select: none; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%; /* bordo inferiore della navbar, non del solo toggle */
  right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 190px;
  z-index: 200;
  padding: .25rem 0;
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-item {
  display: block;
  padding: .5rem 1rem;
  color: var(--blue-900);
  font-size: .85rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.nav-dropdown-item:hover { background: #f5f7fa; color: var(--blue-900); text-decoration: none; }

/* ── Batch rows ──────────────────────────────────────────────────── */
.batch-row-certo       { background: #f0fdf4; }
.batch-row-certo:hover { background: #dcfce7; }
.batch-row-probabile       { background: #fefce8; }
.batch-row-probabile:hover { background: #fef9c3; }
.batch-row-ambiguo       { background: #fff7ed; }
.batch-row-ambiguo:hover { background: #ffedd5; }
.batch-row-non_trovato       { background: var(--white); }
.batch-row-non_trovato:hover { background: var(--gray-100); }

/* ── CRM fallback (CF trovato nel CRM ma non nel RUI) ───────────── */
.crm-fallback-card { max-width: 520px; margin-top: .75rem; }

/* ── Dev banner ──────────────────────────────────────────────────── */
.dev-banner {
  background: #fef3c7; color: #92400e;
  font-size: .78rem; font-weight: 600; text-align: center; padding: .3rem;
  letter-spacing: .3px;
}
