/* Struttura pagina: header, sidebar, breadcrumb, area contenuti. */

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  font-feature-settings: 'cv11', 'tnum';
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

h1, h2, h3 { margin: 0; line-height: 1.3; }

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 12px 0 8px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
}

.topbar__left,
.topbar__right { display: flex; align-items: center; gap: 4px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand__mark { width: 26px; height: 26px; flex: none; }

.topbar__search {
  position: relative;
  justify-self: center;
  width: 100%;
  max-width: 460px;
}
.topbar__search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  translate: 0 -50%;
  width: 16px;
  height: 16px;
  color: var(--text-subtle);
  pointer-events: none;
}
.topbar__search input {
  width: 100%;
  height: 34px;
  padding: 0 40px 0 34px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 17px;
  color: var(--text);
  font: inherit;
}
.topbar__search input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); background: var(--input-bg); }
.topbar__search input::-webkit-search-cancel-button { display: none; }
.topbar__search kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  color: var(--text-subtle);
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  line-height: 18px;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow: auto;
}
.search-results li {
  display: flex;
  flex-direction: column;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.search-results li[aria-selected="true"] { background: var(--accent-soft); }
.search-results .sr-section { color: var(--text-muted); font-size: var(--fs-xs); }
.search-results .sr-empty { color: var(--text-muted); cursor: default; }

.topbar .search-toggle { display: none; }
.topbar__right { grid-column: 3; }

/* ---------- Sidebar ---------- */

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  z-index: 25;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.18s ease, transform 0.2s ease;
}

.nav { list-style: none; margin: 0; padding: 8px 0; }
.nav ul { list-style: none; margin: 0; padding: 0 0 6px; }

.nav__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 42px;
  padding: 0 18px;
  color: var(--sidebar-text);
  font-size: var(--fs-md);
  white-space: nowrap;
}
.nav__link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); text-decoration: none; }
.nav__link .icon { width: 20px; height: 20px; flex: none; }
.nav__link.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-strong);
  font-weight: 550;
}
.nav__link.is-active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
}
.nav__link:focus-visible { box-shadow: inset var(--focus-ring); border-radius: 0; }

.nav__sublink {
  display: block;
  padding: 6px 18px 6px 52px;
  color: var(--sidebar-muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.nav__sublink:hover { color: var(--sidebar-text-strong); text-decoration: none; }
.nav__sublink.is-active { color: var(--accent); font-weight: 550; }
.nav__sublink:focus-visible { box-shadow: inset var(--focus-ring); border-radius: 0; }

.sidebar__foot {
  margin-top: auto;
  padding: 12px 18px;
  border-top: 1px solid var(--sidebar-border);
  color: var(--sidebar-muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}
.sidebar__foot > span { display: block; }
.sidebar__mail {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--sidebar-text);
}
.sidebar__mail .icon { width: 14px; height: 14px; }
.sidebar__mail:hover { color: var(--sidebar-text-strong); }
.sidebar__mail:focus-visible { box-shadow: var(--focus-ring); }

.sidebar-collapsed .nav__link { padding: 0; justify-content: center; }
.sidebar-collapsed .nav__label,
.sidebar-collapsed .nav ul,
.sidebar-collapsed .sidebar__foot { display: none; }

/* ---------- Area contenuti ---------- */

.main {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 14px) var(--gutter) 40px;
  min-width: 0;
  transition: margin-left 0.18s ease;
}
.main:focus { outline: none; }

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.breadcrumb li + li::before { content: '›'; margin-right: 6px; color: var(--text-subtle); }
.breadcrumb [aria-current] { color: var(--text); font-weight: 550; }

.page-head { margin-bottom: 16px; }
.page-head h1 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-muted); max-width: 70ch; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 24;
  background: var(--scrim);
}

/* ---------- Responsive ---------- */

@media (max-width: 767px) {
  :root { --gutter: 16px; }

  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .nav-open .sidebar { transform: none; }
  .sidebar-collapsed .nav__link { padding: 0 18px; justify-content: flex-start; }
  .sidebar-collapsed .nav__label { display: inline; }
  .sidebar-collapsed .nav ul { display: block; }
  .sidebar-collapsed .sidebar__foot { display: block; }

  .main { margin-left: 0; }
}

@media (max-width: 599px) {
  .topbar { gap: 4px; }
  .topbar .search-toggle { display: inline-flex; }
  .topbar__search {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    max-width: none;
    padding: 8px 12px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    box-shadow: var(--shadow-lg);
  }
  .search-open .topbar__search { display: block; }
  .topbar__search .search-icon { left: 22px; }
  .topbar__search kbd { display: none; }
  .search-results { left: 12px; right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .main { transition: none; }
}

.topbar__search .search-icon svg { display: block; width: 100%; height: 100%; }

/* ---------- Selettore lingua ---------- */

.lang-switch {
  display: inline-flex;
  margin: 0 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.lang-switch button {
  height: 26px;
  min-width: 30px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.03em;
  cursor: pointer;
}
.lang-switch button + button { border-left: 1px solid var(--border-strong); }
.lang-switch button:hover { background: var(--surface-2); color: var(--text); }
.lang-switch button[aria-pressed="true"] { background: var(--btn-primary-bg); color: var(--btn-primary-text); }
.lang-switch button:focus-visible { box-shadow: inset var(--focus-ring); border-radius: 0; }

/* ---------- Contatore visite (solo locale) ---------- */

.visits {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}
.visits--header { margin-right: 6px; }
.visits--sidebar { display: none; margin-top: 6px; color: var(--sidebar-muted); }
@media (max-width: 767px) {
  .topbar .visits--header { display: none; }
  .sidebar__foot .visits--sidebar:not([hidden]) { display: block; }
}

/* Avvertenza: risultati indicativi, da verificare da parte di chi usa gli strumenti */
.disclaimer {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  max-width: 70ch;
  margin: 10px 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--warn);
  border-radius: 4px;
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--fs-sm);
}
.page-head .disclaimer { margin-top: 10px; color: var(--text); }
.disclaimer .icon { margin-top: 1px; color: var(--warn); }
.sidebar__disclaimer { color: inherit; font-weight: 600; }
