/*
  FX Hub — KIT design system FX (docs/v2.3/20).
  Riferimento visivo: docs/v2.3/fx-hub-users-mockup.html + hub-ui-guidelines.html.

  SORGENTE DI VERITÀ UNICA E GLOBALE dei componenti .fx-* (card, toolbar, campi,
  bottoni, tabella, badge, paginazione, modali, definition-list, form). Usato sia
  dalla shell (login, topbar, dashboard) sia dai moduli nativi / Hub App: una sola
  definizione per componente, un solo set di token (in base.css :root).

  Le classi NON sono più scopate sotto `.fx-module`: valgono ovunque. `.fx-module`
  resta solo come CONTENITORE di pagina del modulo (max-width + centratura).

  Font: Bricolage Grotesque (display) + Hanken Grotesk (body), self-hosted da
  internal/webassets (var --font-display/--font-body in base.css). Nessun CDN.
*/

/* =========================================================================
   CONTENITORE DI PAGINA DEL MODULO
   ========================================================================= */
.fx-module {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5);
}

/* intestazione di pagina del modulo */
.fx-page-header { margin-bottom: var(--sp-5); }
.fx-page-header h1 {
  font-family: var(--font-display); font-weight: 600; font-size: 26px;
  letter-spacing: -.01em; color: var(--text); line-height: 1.15;
}
.fx-page-header p { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

/* =========================================================================
   CARD
   ========================================================================= */
.fx-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  padding: 0;                 /* le sezioni interne gestiscono la propria spaziatura */
}
.fx-card__pad { padding: var(--sp-5); }

/* =========================================================================
   TOOLBAR
   ========================================================================= */
.fx-toolbar {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.fx-spacer { flex: 1; }

/* =========================================================================
   CAMPI (input / select)
   ========================================================================= */
.fx-field { display: flex; flex-direction: column; gap: 6px; }
.fx-field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.fx-input,
.fx-select {
  height: 38px; padding: 0 var(--sp-3); font-family: var(--font-body); font-size: 14px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color .15s, box-shadow .15s; min-width: 0;
}
.fx-input::placeholder { color: var(--text-subtle); }
.fx-input:focus,
.fx-select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
.fx-input--search { width: 280px; max-width: 100%; }
.fx-select {
  appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235C6470' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}

/* =========================================================================
   BARRA FILTRI (pattern riusabile per le card: estende .fx-toolbar)
   ========================================================================= */
/* Tutti i controlli del filtro hanno la stessa altezza dell'input del kit
   (input/select = 38px; .fx-datefield = 38px), baseline allineata da
   .fx-toolbar (align-items:center). Il bottone d'azione ("Filtra") sta SEMPRE a
   destra: margin-left:auto lo spinge a fine riga, e — grazie a flex-wrap — resta
   allineato a destra anche quando finisce su una riga propria. */
.fx-filterbar > .fx-btn { margin-left: auto; }

/* Datefield con PREFISSO inline ("Da"/"A" a sinistra, niente label sopra): il
   wrapper sembra un unico controllo (bordo+bg+radius sul wrapper), l'input date
   è senza bordo e trasparente. Il picker nativo resta a destra dell'input e NON
   viene clippato (nessun overflow:hidden sul wrapper). */
.fx-datefield {
  display: inline-flex; align-items: center; height: 38px; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); transition: border-color .15s, box-shadow .15s;
}
.fx-datefield:focus-within {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint);
}
.fx-datefield__label {
  padding: 0 var(--sp-2) 0 var(--sp-3); min-width: 1.75rem;
  font-size: 13px; font-weight: 600; color: var(--text-muted); white-space: nowrap;
}
.fx-datefield__input {
  height: 100%; border: none; background: transparent; outline: none; min-width: 0;
  padding: 0 var(--sp-3) 0 0; font-family: var(--font-body); font-size: 14px; color: var(--text);
}

/* =========================================================================
   BOTTONI
   ========================================================================= */
.fx-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 var(--sp-4); font-family: var(--font-body);
  font-size: 14px; font-weight: 600; border-radius: var(--r-md);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  background: var(--surface-2); color: var(--text);
}
.fx-btn:active { transform: translateY(1px); }
.fx-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-tint); }
.fx-btn:disabled { opacity: .55; cursor: not-allowed; }
.fx-btn--primary { background: var(--primary); color: #fff; }
.fx-btn--primary:hover { background: var(--primary-hover); }
.fx-btn--secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.fx-btn--secondary:hover { background: var(--surface); border-color: var(--gray-mid); }
.fx-btn--danger { background: var(--surface-2); color: var(--error); border-color: #EBC9C9; }
.fx-btn--danger:hover { background: var(--error-tint); }
.fx-btn--ghost { background: transparent; color: var(--text-muted); }
.fx-btn--ghost:hover { background: var(--surface); color: var(--text); }
.fx-btn--sm { height: 32px; padding: 0 var(--sp-3); font-size: 13px; }
.fx-btn--block { width: 100%; }   /* full-width: login e form a colonna */

/* =========================================================================
   TABELLA
   ========================================================================= */
.fx-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.fx-table thead th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-subtle);
  padding: 10px var(--sp-4); border-bottom: 1px solid var(--border);
}
.fx-table tbody td { padding: 14px var(--sp-4); border-bottom: 1px solid var(--border); color: var(--text); }
.fx-table tbody tr:last-child td { border-bottom: none; }
.fx-table tbody tr { transition: background .12s; }
.fx-table tbody tr:hover { background: var(--surface); }
.fx-table .fx-email { font-weight: 600; }
.fx-table .fx-muted { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.fx-table .fx-cell-action { text-align: right; }
/* Link di deep-link nelle celle (es. UTENTE in access-log → dettaglio utente):
   eredita il colore primario, sottolineato all'hover. Navigazione SPA via
   data-route (nessun reload). */
.fx-link { color: var(--primary); text-decoration: none; cursor: pointer; }
.fx-link:hover { text-decoration: underline; }
.fx-link:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-tint); border-radius: var(--r-sm); }

/* =========================================================================
   BADGE (pill di stato — canonica, styleguide §4. La bollina notifiche del
   campanello è .fx-notif-count in shell.css: nome distinto, niente collisione.)
   ========================================================================= */
.fx-badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
  font-size: 12px; font-weight: 600; border-radius: 999px; line-height: 1;
}
.fx-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.fx-badge--success { background: var(--success-tint); color: var(--success); }
.fx-badge--success::before { background: var(--success); }
.fx-badge--neutral { background: var(--surface); color: var(--text-muted); }
.fx-badge--neutral::before { background: var(--gray-mid); }
.fx-badge--danger { background: var(--error-tint); color: var(--error); }
.fx-badge--danger::before { background: var(--error); }
.fx-badge--info { background: var(--info-tint); color: var(--info); }
.fx-badge--info::before { background: var(--info); }
.fx-badge--role { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.fx-badge--role::before { display: none; }
/* Badge piccolo INLINE (es. stato "verificata" accanto all'email, senza label). */
.fx-badge--sm { height: 18px; padding: 0 7px; font-size: 11px; gap: 4px; }
.fx-badge--sm::before { width: 5px; height: 5px; }

/* =========================================================================
   CELLA VALORE CON COPY + ICON-BUTTON (dettaglio utente: Email/User ID/Nickname)
   ========================================================================= */
/* dd in flex: testo (+ eventuale badge) a sinistra, icona copy spinta a destra. */
.fx-copyrow { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.fx-copyrow > span { overflow-wrap: anywhere; }
.fx-copyrow .fx-iconbtn { margin-left: auto; }
/* Icon-button neutro (copia negli appunti). */
.fx-iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: 0 0 auto; padding: 0;
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: var(--r-sm); cursor: pointer;
}
.fx-iconbtn:hover { background: var(--surface); color: var(--text); }
.fx-iconbtn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-tint); }
/* Testo monospaziato (es. User ID UUID). */
.fx-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
/* Editor inline della riga Ruolo (select + conferma/annulla). */
.fx-rolecell-edit { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* =========================================================================
   FOOTER / PAGINAZIONE TABELLA
   ========================================================================= */
.fx-table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 13px;
}
/* Blocco di dettaglio (sezioni Sessioni/Device sotto i dati utente, M7 SM1b):
   titolo + tabella, reso come <details>/<summary> collassabile (vedi sotto). */
.fx-detail-block { margin-top: var(--sp-5); }
.fx-detail-block__title {
  font-size: 14px; font-weight: 600; color: var(--text); margin: 0 0 var(--sp-2);
}

/* Sezione collassabile nativa (<details>/<summary>): zero JS per il toggle.
   Il summary porta titolo + badge conteggio (.fx-count); collassata di default.
   Il marker di default è sostituito da una freccetta che ruota su [open]. */
.fx-detail-block__summary {
  display: flex; align-items: center; gap: var(--sp-2);
  cursor: pointer; user-select: none; list-style: none;
  padding: var(--sp-2) 0;
}
.fx-detail-block__summary::-webkit-details-marker { display: none; }
.fx-detail-block__summary::before {
  content: "\203A"; /* › */
  display: inline-block; font-size: 22px; line-height: 1; width: 16px; text-align: center;
  color: var(--text-muted); transition: transform .15s ease;
}
.fx-detail-block[open] > .fx-detail-block__summary::before { transform: rotate(90deg); }
.fx-detail-block__summary .fx-detail-block__title { margin: 0; }
.fx-detail-block__summary:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--primary-tint); border-radius: var(--r-sm);
}
/* Badge contatore nel summary: pill neutra coerente coi badge di stato. */
.fx-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  font-size: 12px; font-weight: 600; line-height: 1; border-radius: 999px;
  background: var(--surface); color: var(--text-muted); border: 1px solid var(--border-strong);
}
/* Riga azioni dentro la sezione collassabile (es. "Revoca tutte"). */
.fx-detail-block__actions {
  display: flex; justify-content: flex-end; margin-bottom: var(--sp-2);
}

/* Azioni compliance (export / legal-hold / retention, M7 SM1c): riga di
   controlli che va a capo su mobile; il campo data resta allineato in basso. */
.fx-compliance-actions {
  display: flex; align-items: flex-end; flex-wrap: wrap;
  gap: var(--sp-3); margin-top: var(--sp-3);
}
.fx-compliance-actions .fx-field { flex: 0 1 auto; }

.fx-pager { display: flex; align-items: center; gap: var(--sp-2); }
.fx-pager button {
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  border-radius: var(--r-sm); cursor: pointer; color: var(--text-muted);
}
.fx-pager button:hover:not(:disabled) { border-color: var(--gray-mid); color: var(--text); }
.fx-pager button:disabled { opacity: .4; cursor: default; }

/* =========================================================================
   MODALE (overlay + dialog)
   ========================================================================= */
.fx-overlay {
  position: fixed; inset: 0; background: rgba(22, 24, 29, .45); backdrop-filter: blur(2px);
  display: none; align-items: flex-start; justify-content: center; padding: 48px var(--sp-4);
  z-index: 50; overflow: auto;
}
.fx-overlay.is-open { display: flex; }
.fx-modal {
  width: min(640px, 92vw); max-width: 640px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); animation: fx-pop .16s ease-out;
  /* Colonna flessibile + altezza massima: con più box (Dati personali,
     Sessioni, Device, Compliance) il contenuto cresce → la modale non sborda,
     è il __body a scrollare mentre head/foot restano ancorati. */
  display: flex; flex-direction: column; max-height: min(90vh, calc(100vh - 64px));
}
@keyframes fx-pop {
  from { opacity: 0; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.fx-modal__head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
}
.fx-modal__head h2 { font-family: var(--font-display); font-weight: 600; font-size: 18px; }
.fx-modal__close {
  width: 32px; height: 32px; display: grid; place-items: center; border: none;
  background: transparent; border-radius: var(--r-sm); cursor: pointer; color: var(--text-muted);
}
.fx-modal__close:hover { background: var(--surface); color: var(--text); }
/* __body scrolla quando il contenuto supera la max-height della modale
   (min-height:0 è necessario perché un flex item scrolli davvero). */
.fx-modal__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--sp-5); }
.fx-modal__foot {
  flex: 0 0 auto;
  display: flex; justify-content: flex-end; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* =========================================================================
   DEFINITION LIST (dettaglio) — label | valore spaziati
   ========================================================================= */
.fx-dl { display: grid; grid-template-columns: 128px 1fr; gap: var(--sp-3) var(--sp-4); }
.fx-dl dt { color: var(--text-muted); font-size: 13px; font-weight: 600; padding-top: 1px; }
.fx-dl dd { color: var(--text); font-size: 14px; }
.fx-dl dd.fx-empty,
.fx-empty { color: var(--text-subtle); }
/* Campo editabile in una cella valore (dettaglio in modifica in-place): riempie
   la colonna del valore invece di restare alla larghezza intrinseca. */
.fx-dl dd .fx-input,
.fx-dl dd .fx-select { width: 100%; }

/* =========================================================================
   FORM
   ========================================================================= */
.fx-form { display: flex; flex-direction: column; gap: var(--sp-4); }
.fx-form .fx-field label { color: var(--text); font-size: 13px; }
.fx-form .fx-input,
.fx-form .fx-select { height: 40px; }
.fx-help { font-size: 12px; color: var(--text-subtle); }
.fx-form__error { margin: 0; color: var(--error); font-size: 13px; font-weight: 500; }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 640px) {
  .fx-input--search { width: 100%; }
  .fx-toolbar { align-items: stretch; }
  .fx-toolbar .fx-spacer { display: none; }
  .fx-dl { grid-template-columns: 1fr; gap: 2px var(--sp-4); }
  .fx-dl dt { padding-top: var(--sp-2); }
  /* Styleguide §3: su mobile i campi rispettano il target touch (≥44px) e
     font ≥16px (evita anche lo zoom-on-focus iOS). Vale per tutti i form. */
  .fx-input, .fx-select { min-height: 44px; font-size: 16px; }
  /* Barra filtri su mobile: ogni controllo a tutta larghezza e ≥44px; il
     datefield e il suo input seguono (font ≥16px no zoom iOS). "Filtra"
     full-width (margin-left:auto neutralizzato dallo stretch). */
  .fx-filterbar > .fx-input,
  .fx-filterbar > .fx-select,
  .fx-filterbar > .fx-datefield { width: 100%; min-height: 44px; height: 44px; }
  .fx-datefield__input { font-size: 16px; }
  .fx-filterbar > .fx-btn { width: 100%; margin-left: 0; min-height: 44px; font-size: 16px; }
  /* Azioni del modale impilate a tutta larghezza e ≥44px: tap comodo e bottoni
     mai tagliati/coperti (es. dialog di conferma FXHub.confirm). */
  .fx-modal__foot { flex-direction: column-reverse; align-items: stretch; }
  .fx-modal__foot .fx-btn { width: 100%; min-height: 44px; font-size: 16px; }

  /* Overlay con safe-area-inset: la modale non finisce sotto notch/barre su
     mobile. Padding ridotto ma rispettoso degli inset (fallback se non supportati). */
  .fx-overlay {
    padding:
      max(var(--sp-3), env(safe-area-inset-top))
      max(var(--sp-3), env(safe-area-inset-right))
      max(var(--sp-3), env(safe-area-inset-bottom))
      max(var(--sp-3), env(safe-area-inset-left));
  }
  /* La modale riempie la larghezza (meno il padding overlay) e limita l'altezza
     alla viewport dinamica (dvh: tiene conto della barra mobile) → scroll interno. */
  .fx-modal { width: 100%; max-width: none; max-height: min(92dvh, calc(100dvh - 24px)); }
  /* Touch target ≥44px per tutti gli interattivi della modale su mobile. */
  .fx-modal__close { width: 44px; height: 44px; }
  .fx-iconbtn { min-width: 44px; min-height: 44px; }
  .fx-detail-block__summary { min-height: 44px; padding: var(--sp-3) 0; }
  .fx-btn--sm { min-height: 44px; }
  /* Riga role-edit inline: il select prende una riga propria, i bottoni
     (Conferma/Annulla) vanno a capo sotto → nessuna rottura a ~360px. */
  .fx-rolecell-edit .fx-select { flex: 1 1 100%; }
}
