/* ---------------------------------------------------------
   19. UI polish: logout, active bar, button spacing, zebra,
   responsive help, mobile fixes
   --------------------------------------------------------- */

/* Account area: user menu on the right (static/css/layout.css .user-menu*). */
.site-header__user {
  margin-left: auto;
}

/* Clear active state in the grouped primary navigation: soft accent fill +
   accent ink text + weight 650. Filled tint + weight is a non-colour cue, so
   the state never relies on colour alone. No accent bar (docs/ui/DESIGN_CONTRACT.md
   §0.4 — it rendered as a full-height bracket in the desktop header row). */
.site-nav__list a[aria-current="page"],
.site-nav__list a[aria-current="location"],
.site-nav__list .is-active > a {
  font-weight: 650;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
}

/* Section sub-nav: a touch more spacing so labels never run together. */
.section-nav { gap: var(--sp-2); }

/* Button groups / action cells: never let buttons overlap or touch.
   NB: a <td> must stay display:table-cell — making it a flex container removes
   it from the table's column grid and misaligns the whole row. So inside table
   cells we keep table-cell layout and space the buttons inline; only a
   standalone div.actions uses flex. */
td.actions { white-space: nowrap; }
td.actions > a.btn,
td.actions > button.btn,
td.actions > form {
  display: inline-flex;
  vertical-align: middle;
  margin: 0 var(--sp-1);
}
td.actions > *:first-child { margin-left: 0; }
td.actions > *:last-child { margin-right: 0; }

div.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

.audit-action-form {
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.audit-action-form .input-sm {
  min-width: 12rem;
  max-width: 18rem;
}

/* Matrice / data tables: zebra striping + stronger header rule for clearer
   line separation. Semaforo row tints (.row-*, !important) still win. */
.data-table tbody tr:nth-child(even):not([class*="row-"]) {
  background: var(--color-bg);
}
.data-table th { border-bottom-width: 2px; }

/* Inline help popover never overflows a small viewport. */
.info__body { max-width: min(90vw, 32rem); }

/* --- Mobile (<640px) refinements --- */
@media (max-width: 639px) {
  /* Keep the header compact: brand left, menu + user menu right. The
     wordmark ("Gestionale Aziende") alone measures ~180px and, combined
     with the hamburger + theme toggle + bell + user menu on the right,
     forced ~69px of horizontal page overflow at 390px (whole-page scroll —
     never allowed, docs/ui/DESIGN_CONTRACT.md §0). Icon-only brand on
     mobile; the accessible name survives via aria-label on the <a> itself.
     The user menu trigger drops the email text too (avatar + caret only —
     the avatar's initials + the summary's title/aria stay the identity
     hint; the full address remains reachable via the account/profile page). */
  .site-header__brand span { display: none; }
  .user-menu__email { display: none; }
  .site-header__user {
    gap: var(--sp-2);
    margin-left: 0;
  }
  .nav-toggle { margin-left: auto; }
  /* Section tabs: tighter horizontal padding so more fit per row. */
  .section-nav { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .section-nav a { padding: var(--sp-2) var(--sp-3); }
}

/* Dashboard quick-add document widget. */
.quick-add__form {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  align-items: end;
}
.quick-add__field {
  display: grid;
  gap: var(--sp-1);
}
.quick-add__form label {
  font-size: var(--text-sm);
  font-weight: 600;
}
.quick-add__form select,
.quick-add__form input[type="search"] {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 100%;
  font-size: var(--text-sm);
}
.quick-add__form button {
  width: fit-content;
}

@media (min-width: 760px) {
  .quick-add__form {
    grid-template-columns: minmax(12rem, 1fr) minmax(12rem, 1fr) minmax(14rem, 1fr) auto;
  }
}

/* Dashboard OCR upload: single click/drop zone instead of the native
   "Browse…" button + separate submit. The real <input type=file> is visually
   hidden (still focusable + label-activated, so it works without JS); the zone
   is the picker. The submit button is stacked BELOW the zone at full width, so
   a long filename can never overlap it. */
.ocr-drop {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.ocr-drop__input {
  /* Visually hidden but focusable + operable via the label. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.ocr-drop__zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  text-align: center;
  min-height: 7rem;
  padding: var(--sp-4);
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.ocr-drop__zone:hover {
  border-color: var(--accent-ink);
}
/* Keyboard focus lands on the hidden input; mirror it onto the zone. */
.ocr-drop__input:focus-visible + .ocr-drop__zone,
.ocr-drop__zone.is-dragover {
  border-color: var(--accent-ink);
  background: var(--color-surface);
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}
.ocr-drop__icon {
  font-size: 1.75rem;
  line-height: 1;
  font-weight: 300;
  color: var(--color-text-muted);
}
.ocr-drop__text {
  /* Long filenames truncate with an ellipsis instead of overflowing. */
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  font-weight: 600;
}
.ocr-drop__pick {
  color: var(--accent-ink);
  text-decoration: underline;
}
.ocr-drop__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.ocr-drop__zone.is-filled .ocr-drop__meta {
  display: none;
}
.ocr-drop__submit {
  width: 100%;
  /* .btn is an inline-flex with default flex-start; center the label now that
     the button spans the full width. */
  justify-content: center;
}

/* ── DVR printable document (Stampa documento) ───────────────────────────── */
.dvr-documento .doc-section {
  page-break-inside: avoid;
  margin-bottom: var(--sp-6);
}
.dvr-documento .doc-section h1 {
  margin-bottom: var(--sp-1);
}
.dvr-documento .doc-section h2 {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--sp-1);
  margin-bottom: var(--sp-3);
}
.dvr-documento .doc-subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
}
.dvr-documento .doc-rif {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-muted);
}
.dvr-documento .doc-note {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--sp-2);
}
.dvr-documento .doc-dl {
  display: grid;
  gap: var(--sp-1);
  margin: var(--sp-3) 0;
}
.dvr-documento .doc-dl__row {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) 1fr;
  gap: var(--sp-3);
}
.dvr-documento .doc-dl dt {
  font-weight: 600;
}
.dvr-documento .doc-dl dd {
  margin: 0;
}
.dvr-documento .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--sp-3) 0;
}
.dvr-documento .doc-table th,
.dvr-documento .doc-table td {
  border: 1px solid var(--color-border);
  padding: var(--sp-2);
  text-align: left;
  vertical-align: top;
}
.dvr-documento .doc-firme .doc-firma__line {
  min-width: 12rem;
}

/* ── Print styles (reusable: DVR and any printable page will benefit) ──────
   Hides nav chrome, filter bar, action buttons; formats tables for paper.
   Any element that must be hidden when printing should carry class="no-print".
   ────────────────────────────────────────────────────────────────────────── */
@media print {
  @page { margin: 16mm; }

  /* Hide all interactive / navigation chrome */
  .site-header,
  .site-nav,
  .section-nav,
  .site-footer,
  .no-print,
  .btn,
  button,
  .filter-bar {
    display: none !important;
  }

  /* Tables: full width, collapsed borders for paper */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
  }

  /* Repeat table headers on each printed page */
  thead {
    display: table-header-group;
  }

  /* Avoid page breaks inside table rows and KPI cards */
  tr,
  .kpi-card {
    page-break-inside: avoid;
  }

  /* Printable fiscal receipt (quietanza detrazione under-18): keep it on its
     own page and drop the on-screen card chrome so it reads like a document. */
  .quietanza-print {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    page-break-inside: avoid;
  }
}

/* Printable fiscal receipt — on-screen look: a bordered, document-like block
   the user can review before hitting Stampa (window.print). */
.quietanza-print {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

/* ── Friendly error pages (403 / 404 / 500 …) ─────────────────────────────── */
.error-page {
  max-width: 32rem;
  margin: 3rem auto;
  padding: 2rem 1.5rem;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.error-page__code {
  margin: 0;
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--accent-ink);
}
.error-page__title {
  margin: 0.5rem 0 0;
  font-size: 1.5rem;
  color: var(--color-text);
}
.error-page__lead {
  margin: 0.75rem auto 0;
  max-width: 28rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}
.error-page__detail {
  margin: 1rem auto 0;
  max-width: 28rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  word-break: break-word;
}
.error-page__actions {
  margin-top: 1.5rem;
}

