/* Backoffice: strumento di lavoro, sobrio. Si appoggia ai token di styles.css (caricato prima).
   Struttura da applicazione: menu laterale fisso su schermo largo, barra in basso sul telefono. */

:root { --side-w: 15rem; --line: #E6DCC0; --card: var(--white); }

/* ---------- Impianto ---------- */
.a-app { min-height: 100vh; min-height: 100dvh; }
.a-main { width: min(1120px, 100%); margin-inline: auto; padding: 1.25rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); }
.a-app--guest .a-main { display: grid; place-items: center; min-height: 100dvh; padding-bottom: 2rem; }
@media (min-width: 960px) {
  .a-app:not(.a-app--guest) { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .a-main { padding: 2rem clamp(1.5rem, 3vw, 3rem) 4rem; }
}
.a-main h2 { font-size: 1.5rem; margin: 0 0 .75rem; }
.a-main h3 { font-size: 1.2rem; margin: 0; }
.a-icon { flex: none; width: 1.25rem; height: 1.25rem; }

/* ---------- Menu laterale ---------- */
.a-side {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; background: var(--plum-900); color: var(--ivory-50);
}
.a-brand { display: flex; align-items: center; gap: .65rem; color: inherit; text-decoration: none; }
.a-brand img { width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--sand-300); }
.a-brand > span { display: flex; flex-direction: column; line-height: 1.2; }
.a-brand__name { font-weight: 700; font-size: .8125rem; letter-spacing: .18em; text-transform: uppercase; }
.a-brand__role { font-size: .6875rem; letter-spacing: .3em; text-transform: uppercase; color: var(--sand-300); opacity: .8; }

.a-nav { display: grid; gap: .2rem; }
.a-nav a, .a-side__link {
  position: relative; display: flex; align-items: center; gap: .75rem; min-height: 2.75rem; padding: .5rem .85rem;
  border: 0; border-radius: 12px; background: none; color: rgba(251, 248, 241, .78);
  font: 500 .9375rem/1.2 var(--font-body); text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), transform .16s var(--ease-out);
}
.a-nav a[aria-current="page"] { background: var(--plum-800); color: var(--ivory-50); }
.a-nav a[aria-current="page"] .a-icon { color: var(--coral-500); }
.a-side__link[aria-current="page"] { background: var(--plum-800); color: var(--ivory-50); }
.a-nav a:active, .a-side__link:active { transform: scale(.97); }
.a-nav__badge {
  margin-left: auto; min-width: 1.4rem; padding: .1rem .4rem; border-radius: 999px;
  background: var(--coral-600); color: var(--white); font-size: .75rem; font-weight: 700; text-align: center;
}
.a-side__foot { display: flex; align-items: center; }
.a-side__foot form { margin: 0; }
.a-side__link { width: 100%; font-size: var(--text-sm); }
.a-side :focus-visible { outline-color: var(--sand-300); }
@media (hover: hover) and (pointer: fine) {
  .a-nav a:not([aria-current]):hover, .a-side__link:hover { background: rgba(251, 248, 241, .07); color: var(--ivory-50); }
}

/* Telefono e tablet: in alto marchio ed "Esci", le cinque voci in una barra fissa in basso */
@media (max-width: 959px) {
  .a-side__foot .a-side__link span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .a-side__foot .a-side__link { width: 2.75rem; padding: 0; justify-content: center; }
  .a-nav {
    position: fixed; inset: auto 0 0; z-index: 40; grid-template-columns: repeat(5, 1fr); gap: 0;
    padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
    background: var(--plum-900); box-shadow: 0 -8px 24px -16px rgba(46, 24, 56, .6);
  }
  .a-nav a { flex-direction: column; gap: .2rem; min-height: 3.25rem; padding: .35rem .25rem; font-size: .75rem; text-align: center; }
  .a-nav__badge { position: absolute; top: .2rem; left: calc(50% + .45rem); margin: 0; min-width: 1.2rem; padding: 0 .3rem; font-size: .6875rem; line-height: 1.2rem; }
}
@media (min-width: 960px) {
  .a-side {
    flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 1.75rem;
    height: 100vh; height: 100dvh; padding: 1.5rem .85rem 1rem;
  }
  .a-brand { padding-inline: .5rem; }
  .a-side__foot { flex-direction: column; align-items: stretch; gap: .2rem; margin-top: auto; padding-top: 1rem; border-top: 1px solid rgba(251, 248, 241, .1); }
}

/* ---------- Intestazione di pagina ---------- */
.a-page { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem 1.5rem; margin-bottom: 1.5rem; }
.a-page__title { min-width: 0; }
.a-page h1 { margin: 0; font-size: clamp(1.85rem, 1.6rem + 1vw, 2.4rem); overflow-wrap: anywhere; }
.a-page__sub { margin: .35rem 0 0; color: var(--ink-soft); font-size: var(--text-sm); max-width: 60ch; }
.a-page__actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.a-crumb {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 2rem; margin-bottom: .1rem;
  color: var(--ink-soft); font-size: var(--text-sm); font-weight: 500; text-decoration: none;
}
.a-crumb::before { content: "←"; }
@media (hover: hover) and (pointer: fine) { .a-crumb:hover { color: var(--coral-700); } }

/* ---------- Schede (tab) ---------- */
.a-tabs { display: flex; gap: .25rem; margin: -.5rem 0 1.5rem; border-bottom: 1.5px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.a-tabs[hidden] { display: none; }
.a-tabs a {
  display: inline-flex; align-items: center; gap: .45rem; min-height: 2.75rem; padding: .5rem .9rem; margin-bottom: -1.5px;
  border-bottom: 2px solid transparent; color: var(--ink-soft); font-size: .9375rem; font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: color .2s var(--ease-out), border-color .2s var(--ease-out);
}
.a-tabs a[aria-selected="true"], .a-tabs a[aria-current="page"] { border-color: var(--coral-600); color: var(--plum-900); }
@media (hover: hover) and (pointer: fine) { .a-tabs a:hover { color: var(--plum-900); } }
.a-panel + .a-panel { margin-top: 2.5rem; }
.js-tabs .a-panel + .a-panel { margin-top: 0; }
.js-tabs .a-panel__title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.a-panel[hidden] { display: none; }
.a-count {
  display: inline-block; min-width: 1.5rem; padding: 0 .45rem; border-radius: 999px; background: var(--sand-200);
  color: var(--ink-soft); font-family: var(--font-body); font-size: .75rem; font-weight: 600; line-height: 1.5rem; text-align: center; letter-spacing: 0;
}

/* ---------- Riquadri ---------- */
.a-card { margin: 0 0 1.25rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.a-card--flush { padding: 0; overflow: hidden; }
.a-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; font-size: var(--text-sm); }
.a-card__head h2, .a-card__head h3 { display: flex; align-items: center; gap: .5rem; margin: 0; }
.a-card__head h2 { font-size: 1.35rem; }
.a-card--flush > .a-card__head { margin: 0; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.a-card__empty { margin: 0; padding: 2rem 1.25rem; color: var(--ink-soft); font-size: var(--text-sm); text-align: center; }
.a-card > :last-child { margin-bottom: 0; }
.a-grid { display: grid; gap: 1.25rem; }
.a-grid > .a-card { margin: 0; }
@media (min-width: 760px) { .a-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.a-link { color: var(--coral-700); font-size: var(--text-sm); font-weight: 600; text-decoration: none; }
@media (hover: hover) and (pointer: fine) { .a-link:hover { text-decoration: underline; } }

/* Righe cliccabili (scadenze, azioni rapide) */
.a-rows { margin: 0 -.5rem; padding: 0; list-style: none; }
.a-rows a {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.25rem; padding: .6rem .75rem;
  border-radius: 12px; text-decoration: none; transition: background-color .2s var(--ease-out);
}
.a-rows a > span:first-child { display: grid; min-width: 0; line-height: 1.35; }
.a-rows strong { font-weight: 600; overflow-wrap: anywhere; }
.a-rows small { color: var(--ink-soft); font-size: var(--text-sm); }
.a-rows .a-icon { color: var(--mauve-500); }
.a-rows li + li { border-top: 1px solid var(--sand-200); }
@media (hover: hover) and (pointer: fine) { .a-rows a:hover { background: var(--ivory-50); } }

/* ---------- Messaggi ---------- */
.a-flash { margin: 0 0 1.25rem; padding: .85rem 1.1rem; border-radius: 12px; background: #DDEBD8; color: #25521F; font-size: var(--text-sm); }
.a-flash--error { background: #F6DEDF; color: var(--coral-700); }
.a-flash[data-poll] { background: #F5E4B5; color: #4A3300; }
.a-empty { margin: 0 0 1.25rem; padding: 2rem 1rem; border: 1.5px dashed var(--line); border-radius: 16px; color: var(--ink-soft); font-size: var(--text-sm); text-align: center; }

/* ---------- Dashboard ---------- */
.a-stats { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 0 0 1.25rem; padding: 0; list-style: none; }
.a-stats a {
  display: grid; grid-template-columns: 1fr auto; align-items: start; gap: .25rem .5rem; height: 100%; padding: 1rem 1.1rem;
  border: 1px solid var(--line); border-radius: 16px; background: var(--card); text-decoration: none; font-size: var(--text-sm); line-height: 1.35;
  transition: border-color .2s var(--ease-out), transform .16s var(--ease-out);
}
.a-stats .a-icon { grid-column: 2; grid-row: 1; color: var(--mauve-500); }
.a-stats a:active { transform: scale(.98); }
.a-stats__n { grid-column: 1; grid-row: 1; font-family: var(--font-display); font-size: 2.25rem; font-weight: 600; line-height: 1; font-variant-numeric: lining-nums; }
.a-stats a.is-alert { border-color: #E8CF86; background: #FBF1D6; color: #4A3300; }
.a-stats a.is-alert .a-icon { color: #8A6400; }
@media (hover: hover) and (pointer: fine) { .a-stats a:hover { border-color: var(--plum-700); } }
@media (min-width: 1100px) { .a-stats { grid-template-columns: repeat(4, 1fr); } }

/* ---------- Moduli ---------- */
.a-form { display: grid; gap: 1.1rem; max-width: 44rem; }
.a-card.a-form { max-width: 44rem; }
.a-form--narrow { max-width: 24rem; }
.a-form__row { display: grid; gap: 1.1rem; }
@media (min-width: 640px) { .a-form__row { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); } }
.a-form__actions { display: flex; justify-content: flex-end; padding-top: .25rem; }
.a-field { display: grid; gap: .35rem; align-content: start; }
.a-field label { font-size: var(--text-sm); font-weight: 600; }
.a-optional { margin-left: .25rem; color: var(--ink-soft); font-weight: 400; }
.a-field small { font-size: var(--text-sm); color: var(--ink-soft); }
.a-field input, .a-field select, .a-field textarea {
  width: 100%; min-height: 2.75rem; padding: .6rem .85rem; border: 1.5px solid #CFC3D6; border-radius: 12px;
  background: var(--white); color: var(--plum-900); font: inherit; font-size: 1rem;
  transition: border-color .2s var(--ease-out);
}
@media (hover: hover) and (pointer: fine) { .a-field :is(input, select, textarea):hover { border-color: var(--mauve-500); } }
.a-field textarea { min-height: 7rem; resize: vertical; }
.a-field input:focus-visible, .a-field select:focus-visible, .a-field textarea:focus-visible { outline: 2px solid var(--coral-600); outline-offset: 2px; border-color: var(--plum-700); }
.a-field input[type="checkbox"] { width: 1.5rem; min-height: 1.5rem; height: 1.5rem; accent-color: var(--coral-600); }
.a-field input[type="file"] { padding: .4rem; border-style: dashed; cursor: pointer; font-size: var(--text-sm); }
.a-field input[type="file"]::file-selector-button {
  margin-right: .75rem; min-height: 2.25rem; padding: .4rem 1rem; border: 1.5px solid var(--plum-700); border-radius: 999px;
  background: var(--white); color: var(--plum-700); font: 600 var(--text-sm)/1 var(--font-body); cursor: pointer;
}

/* Interruttore: casella a sinistra, titolo e spiegazione accanto */
.a-switch { display: flex; align-items: flex-start; gap: .85rem; padding: .85rem 1rem; border-radius: 12px; background: var(--ivory-50); cursor: pointer; }
.a-switch input { flex: none; width: 1.4rem; height: 1.4rem; margin: .1rem 0 0; accent-color: var(--coral-600); cursor: pointer; }
.a-switch > span { display: grid; gap: .1rem; line-height: 1.4; }
.a-switch strong { font-size: .9375rem; font-weight: 600; }
.a-switch small { color: var(--ink-soft); font-size: var(--text-sm); }

/* ---------- Pannello a comparsa (popover) ---------- */
.a-sheet { margin: 2rem 0 0; padding: 1.25rem; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: inherit; }
.a-sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.a-sheet__head h2 { margin: 0; }
.a-sheet__close { display: none; }
.a-sheet:popover-open {
  position: fixed; inset: auto 0 0; width: auto; max-height: 90dvh; margin: 0; overflow: auto;
  padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom)); border: 0; border-radius: 20px 20px 0 0;
  box-shadow: 0 -20px 60px -20px rgba(46, 24, 56, .45);
  animation: a-sheet-up .32s var(--ease-out);
}
.a-sheet:popover-open .a-sheet__close {
  display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border: 0; border-radius: 50%;
  background: var(--sand-200); color: var(--plum-900); font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.a-sheet::backdrop { background: rgba(46, 24, 56, .4); }
@media (min-width: 640px) {
  .a-sheet:popover-open { inset: 0; width: min(32rem, calc(100% - 2rem)); height: fit-content; margin: auto; border-radius: 20px; animation-name: a-sheet-in; }
}
@keyframes a-sheet-up { from { transform: translateY(100%); } }
@keyframes a-sheet-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
/* Dove popover esiste il pannello resta chiuso finché non lo apri; altrove è un riquadro in fondo */
@supports selector(:popover-open) { .a-sheet:not(:popover-open) { display: none; } }

/* ---------- Avanzamento del caricamento ---------- */
.a-progress { display: grid; gap: .4rem; margin: 0; font-size: var(--text-sm); }
.a-progress[hidden] { display: none; }
.a-progress progress { width: 100%; height: .6rem; accent-color: var(--coral-600); }

/* ---------- Bottoni ---------- */
.a-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 2.75rem; padding: .55rem 1.25rem; border: 1.5px solid var(--coral-600); border-radius: 999px;
  background: var(--coral-600); color: var(--white); font: 600 var(--text-sm)/1.2 var(--font-body);
  text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), border-color .2s var(--ease-out), transform .16s var(--ease-out);
}
.a-btn .a-icon { width: 1.1rem; height: 1.1rem; margin-left: -.25rem; }
.a-btn:active { transform: scale(.97); }
.a-btn[disabled] { opacity: .6; cursor: progress; transform: none; }
.a-btn--quiet { background: var(--white); border-color: var(--plum-700); color: var(--plum-700); }
.a-btn--danger { background: var(--white); border-color: var(--coral-700); color: var(--coral-700); }
.a-btn--small { min-height: 2.5rem; padding: .4rem 1rem; }
.a-btn--block { width: 100%; }
@media (hover: hover) and (pointer: fine) {
  .a-btn:not(.a-btn--danger):not([disabled]):hover { background: var(--plum-700); border-color: var(--plum-700); color: var(--white); }
  .a-btn--danger:hover { background: var(--coral-700); color: var(--white); }
}

/* ---------- Azioni che non si annullano: chiuse finché non servono ---------- */
.a-danger { border-radius: 12px; }
.a-danger > summary {
  display: inline-flex; align-items: center; gap: .5em; min-height: 2.75rem; padding: .25rem 0;
  color: var(--coral-700); font-size: var(--text-sm); font-weight: 600; cursor: pointer; list-style: none;
}
.a-danger > summary::-webkit-details-marker { display: none; }
.a-danger > summary::before { content: "›"; display: inline-block; transition: transform .2s var(--ease-out); }
.a-danger[open] > summary::before { transform: rotate(90deg); }
.a-danger > :not(summary) { margin-top: .5rem; }
.a-danger p { font-size: var(--text-sm); }
.a-danger--section { max-width: 44rem; margin-top: 2rem; padding: .25rem 1.25rem; border: 1.5px solid #F0C9CB; border-radius: 16px; background: var(--white); }
.a-danger--section[open] { padding-bottom: 1.25rem; }
.a-danger--section > summary { font-size: .9375rem; }

/* ---------- Etichette di stato ---------- */
.a-pill { display: inline-block; padding: .15rem .7rem; border-radius: 999px; font-size: var(--text-sm); font-weight: 500; line-height: 1.5; white-space: nowrap; }
.a-pill--ok { background: #DDEBD8; color: #25521F; }
.a-pill--warn { background: #F5E4B5; color: #6B4A00; }
.a-pill--error { background: #F6DEDF; color: var(--coral-700); }
.a-pill--muted { background: var(--sand-200); color: var(--ink-soft); }

/* ---------- Tabelle: su telefono diventano liste ---------- */
.a-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.a-table th { padding: .65rem 1.25rem; background: var(--ivory-50); color: var(--ink-soft); font-size: .8125rem; font-weight: 600; text-align: left; border-bottom: 1px solid var(--line); }
.a-table td { padding: .8rem 1.25rem; vertical-align: middle; border-bottom: 1px solid var(--sand-200); }
.a-table tr:last-child td { border-bottom: 0; }
.a-table a { color: var(--plum-900); font-weight: 600; text-decoration: none; }
/* La riga intera porta al dettaglio: il link del nome si allarga a coprirla */
.a-table--rows tr { position: relative; }
.a-table--rows td:first-child a::after { content: ""; position: absolute; inset: 0; }
.a-table--rows tbody tr { transition: background-color .2s var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  .a-table--rows tbody tr:hover { background: var(--ivory-50); }
  .a-table--rows tbody tr:hover td:first-child a { color: var(--coral-700); }
}
@media (max-width: 639px) {
  .a-table, .a-table tbody, .a-table tr, .a-table td { display: block; }
  .a-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .a-table tr { padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .a-table tr:last-child { border-bottom: 0; }
  .a-table td { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 1.1rem; border: 0; text-align: right; }
  .a-table td::before { content: attr(data-label); flex: none; color: var(--ink-soft); font-weight: 500; text-align: left; }
  .a-table td:not([data-label])::before { content: none; }
  .a-table td:first-child { font-size: 1rem; }
  .a-table--rows td:first-child::before { content: none; }
}

/* ---------- Accesso ---------- */
.a-login { display: grid; justify-items: center; width: min(24rem, 100%); text-align: center; }
.a-login img { width: 3.5rem; height: 3.5rem; margin-bottom: 1rem; border-radius: 50%; background: var(--sand-300); }
.a-login h1 { margin: 0; font-size: 2.2rem; }
.a-login .a-page__sub { margin-bottom: 1.5rem; }
.a-login .a-form { width: 100%; text-align: left; }
.a-login__alt { justify-self: center; }

@media (prefers-reduced-motion: reduce) {
  .a-btn, .a-nav a, .a-side__link, .a-stats a, .a-rows a, .a-tabs a, .a-danger > summary::before { transition: none; }
  .a-btn:active, .a-nav a:active, .a-side__link:active, .a-stats a:active { transform: none; }
  .a-sheet:popover-open { animation: none; }
}
