/* Reusable components used by more than one area: switches, row menus, dialogs, filter panel and chips, pager, dashboards (KPIs, progress), page head,
   button rows. Loaded on every page, after base.css. */

/* option rows with an on/off switch (replaces bare checkboxes): whole row is the tap target */
.opt { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.65rem; padding: .35rem .8rem; background: #fff; border: 1px solid var(--line); cursor: pointer; position: relative; align-self: end; user-select: none; }
.opt > input[type=radio], .opt > input[type=checkbox] { position: absolute; opacity: 0; width: 100%; height: 100%; inset: 0; margin: 0; cursor: pointer; }
.opt-sw { flex: none; position: relative; width: 2.6rem; height: 1.4rem; background: #cfcbb6; transition: background .15s; }
.opt-sw::after { content: ""; position: absolute; top: .2rem; left: .2rem; width: 1rem; height: 1rem; background: #fff; transition: transform .15s; }
.opt input:checked ~ .opt-sw { background: var(--ink); }
.opt input:checked ~ .opt-sw::after { transform: translateX(1.2rem); background: var(--brass-light); }
.opt:has(input:checked) { border-color: var(--ink); background: #fbf9f0; }
.opt:has(input:checked) .opt-t { font-weight: 600; }
.opt:has(input:focus-visible) { outline: 2px solid var(--brass); outline-offset: 1px; }
@media (max-width: 720px) { .opt { align-self: stretch; } }

.pager { display: flex; gap: .4rem; margin-top: 1rem; flex-wrap: wrap; align-items: center; }
.pager a, .pager span { padding: .3rem .7rem; border: 1px solid var(--line); text-decoration: none; background: #fff; }
.pager span.cur { background: var(--ink); color: var(--paper); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { background: var(--ink); color: var(--paper); border-radius: var(--radius); padding: 1rem 1.2rem; }
.kpi b { display: block; font-family: var(--display); font-size: 2rem; color: var(--brass-light); line-height: 1.1; }
.bar { height: .6rem; background: var(--brass); min-width: 2px; }
.cols2 { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* row "⋯" menu: the panel is position:fixed (placed by admin.js) so the scrollable table never clips it */
details.menu { position: relative; display: inline-block; }
/* the "⋯" itself: round and see-through like the export button, so the rows stay calm; a soft tint on hover, filled while its menu is open */
details.menu > summary { list-style: none; cursor: pointer; user-select: none; }
details.menu:not(.navmenu) > summary { width: 2.2rem; height: 2.2rem; display: flex; align-items: center; justify-content: center; padding-bottom: .2em;
  border: 1px solid transparent; border-radius: 50%; background: transparent; font-size: 1.3rem; font-weight: 700; line-height: 1; color: #5b5f4f;
  transition: background .15s, color .15s, border-color .15s; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary svg { width: 1.1rem; height: 1.1rem; }
/* the export (share) button: round and see-through, so it sits quietly next to a title */
details.menu.export > summary { padding-bottom: 0; border-radius: 50%; border-color: transparent; background: transparent; color: #5b5f4f; }
details.menu.export > summary:hover, details.menu.export[open] > summary { background: rgba(20, 35, 29, .1); border-color: transparent; color: var(--ink); }
details.menu:not(.navmenu):not(.export) > summary:hover { background: rgba(20, 35, 29, .08); color: var(--ink); }
details.menu:not(.navmenu):not(.export)[open] > summary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
details.menu:not(.navmenu) > summary:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.menu-panel { position: fixed; z-index: 30; min-width: 11rem; background: #fff; border: 1px solid var(--ink); border-radius: 10px; overflow: hidden; box-shadow: 0 6px 18px rgba(20, 35, 29, .25); display: flex; flex-direction: column; }
.menu-panel a, .menu-panel button { display: block; width: 100%; text-align: left; padding: .65rem .9rem; background: none; border: 0; border-bottom: 1px solid var(--line);
  font: inherit; color: var(--char); text-decoration: none; cursor: pointer; }
.menu-panel > :last-child, .menu-panel form:last-child button { border-bottom: 0; }
.menu-panel a:hover, .menu-panel button:hover, .menu-panel a:focus-visible, .menu-panel button:focus-visible { background: var(--paper); outline: none; }
.menu-panel button.danger { color: var(--ox); }
.menu-panel form { margin: 0; }
dialog.dlg { border: 1px solid var(--ink); border-radius: calc(var(--radius) + 2px); background: #f7f4e8; color: var(--char); padding: 1.25rem 1.4rem; width: min(26rem, calc(100vw - 2rem)); }
dialog.dlg::backdrop { background: rgba(20, 35, 29, .55); }
dialog.dlg h2 { font-size: 1.3rem; padding-right: 1.8rem; }          /* the title never runs under the × */
dialog.dlg .dlg-x { position: absolute; top: .5rem; right: .5rem; width: 2.2rem; height: 2.2rem; display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink); font: 1.7rem/1 var(--body); cursor: pointer; }
dialog.dlg .dlg-x:hover { background: var(--paper-2); }
dialog.dlg .dlg-x:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }
/* collapsible filters (open on desktop, collapsed on phones by an inline script in the Filters panel) */
details.filters > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .6rem; font-family: var(--display); font-size: 1.35rem; font-weight: 600; color: var(--ink); user-select: none; }
details.filters > summary::-webkit-details-marker { display: none; }
details.filters > summary::before { content: "\25B8"; font-size: .9rem; color: var(--brass); transition: transform .15s; }
details.filters[open] > summary::before { transform: rotate(90deg); }
details.filters[open] > summary { margin-bottom: .9rem; }
details.filters > summary .badge { font-family: var(--body); font-size: .68rem; }

.form-actions { margin-top: 1.1rem; }
.form-actions .btn { min-width: 8.5rem; text-align: center; }
@media (max-width: 720px) { .form-actions > .btn { flex: 1 1 8.5rem; } }       /* buttons side by side share the row equally */
/* a row with link buttons and/or buttons wrapped in a <form>: on phones every item is full width, so they all have the same length */
@media (max-width: 720px) {
  .form-actions:is(:has(> form), :has(> a.btn)) > :is(.btn, form) { flex: 1 1 100%; }
  .form-actions:is(:has(> form), :has(> a.btn)) > form .btn { width: 100%; }
  .form-actions.stack-sm > .btn { flex: 1 1 100%; }          /* explicitly one button per line on phones */
}

/* active filters: one removable chip each */
.card.filters.has-chips { margin-bottom: .6rem; }
.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .5rem; margin: 0 0 1.1rem; }
.fchip { display: inline-flex; align-items: center; background: #fff; border: 1px solid var(--line); font-size: .82rem; padding: .15rem .15rem .15rem .6rem; max-width: 100%; }
.fchip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.fchip .x { text-decoration: none; font-size: 1.15rem; line-height: 1; padding: .2rem .55rem; color: var(--ox); margin-left: .25rem; }
.fchip .x:hover, .fchip .x:focus-visible { background: var(--ox); color: var(--paper); outline: none; }
.fclear { font-size: .8rem; margin-left: .25rem; }

/* list pages: title row with the "+ Nuovo" button; wider create dialogs */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.page-head h1 { margin: 0; }
dialog.dlg.wide { width: min(40rem, calc(100vw - 2rem)); }
.btn.plus::before { content: "+"; font-size: 1.1rem; font-weight: 700; margin-right: .5rem; letter-spacing: 0; }

/* inside dialogs the 12-column grid is narrow: give wide dialogs more room and let the 3-option selector shrink */
dialog.dlg.wide { width: min(48rem, calc(100vw - 2rem)); }
dialog.dlg { overflow-x: hidden; }
dialog.dlg .seg span { padding: 0 .4rem; white-space: nowrap; font-size: .92rem; }

/* "Cosa può fare ogni ruolo": a definition-style table that must fit its card, also on a phone */
table.t.roles-help { table-layout: fixed; }
table.t.roles-help td { white-space: normal; min-width: 0; overflow-wrap: anywhere; vertical-align: top; }
table.t.roles-help td:first-child { width: 40%; overflow-wrap: normal; word-break: normal; hyphens: none; }
@media (max-width: 720px) { table.t.roles-help td { padding-inline: .5rem; } }
@media (max-width: 440px) {       /* too narrow for two columns: the role name sits above its description */
  table.t.roles-help, table.t.roles-help tbody, table.t.roles-help tr, table.t.roles-help td { display: block; width: auto; }
  table.t.roles-help tr { padding: .5rem 0; border-bottom: 1px solid var(--line); }
  table.t.roles-help td { border-bottom: 0; padding: .1rem .5rem; }
  table.t.roles-help td:first-child { width: auto; }
}
table.t.roles-help td.wrapok { min-width: 0; }
table.t.roles-help code { overflow-wrap: anywhere; word-break: break-all; font-size: .85em; }
@media (min-width: 721px) { table.t.roles-help td:first-child { width: 14rem; } }

.opt:active { background: var(--paper-2); }

/* round profile photos (staff, teachers: profile pages and lists) */
.avatar { border-radius: 50%; object-fit: cover; background: #fff; border: 1px solid var(--line); display: block; flex: none; }
.avatar-xl { width: 120px; height: 120px; } .avatar-md { width: 64px; height: 64px; } .avatar-sm { width: 40px; height: 40px; }

.who-cell { display: flex; align-items: center; gap: .75rem; }

/* progress x / quota and small text/definition helpers (school lists, request review) */
.prog { height: .55rem; background: var(--paper-2); min-width: 5rem; margin-top: .25rem; }
.prog i { display: block; height: 100%; background: var(--brass); }
.prog.done i { background: var(--ok); }
.prog.over i { background: var(--ox); }
.progtxt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { display: block; font-size: .78rem; color: #6b6f5e; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1.2rem; margin: 0; }
.kv dt { color: #6b6f5e; } .kv dd { margin: 0; }
.preview { background: #fbf9f0; border-left: 4px solid var(--brass); border-radius: 0 var(--radius) var(--radius) 0; padding: .6rem .9rem; margin: .8rem 0 0; font-size: .9rem; }

/* a text field inside an option row must stay clickable above the row's hidden radio/checkbox overlay */
.opt .amt { position: relative; z-index: 2; }
.opt input[type=radio]:checked ~ .opt-t { font-weight: 600; }

/* toasts: the one-time messages after an action, floating from the top of the screen. A light card with a coloured icon stands out over the dark top bar. */
.toasts { position: fixed; left: 50%; top: .75rem; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .6rem; align-items: center; width: min(32rem, calc(100vw - 1.5rem)); pointer-events: none; }
.toast { --c: var(--brass); pointer-events: auto; position: relative; overflow: hidden; display: flex; align-items: center; gap: .85rem; width: 100%; box-sizing: border-box; padding: .9rem .7rem .9rem .9rem;
  border-radius: 14px; background: #fffdf6; color: var(--ink); font-size: .93rem; line-height: 1.4; border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  box-shadow: 0 14px 36px rgba(20, 35, 29, .38), 0 2px 6px rgba(20, 35, 29, .2); animation: toast-in .4s cubic-bezier(.2, .9, .3, 1.2); }
.toast.ok { --c: var(--ok); } .toast.error { --c: var(--ox); } .toast.warn { --c: #b07d12; }
.toast-ic { flex: none; width: 2rem; height: 2rem; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font: 700 1.05rem/1 var(--body); font-style: normal; }
.toast-ic::before { content: "\2713"; }
.toast.warn .toast-ic::before, .toast.error .toast-ic::before { content: "!"; font-size: 1.15rem; }
.toast span { flex: 1; overflow-wrap: anywhere; color: #3b4036; }
.toast span b { display: block; color: var(--ink); font-size: 1rem; font-weight: 700; line-height: 1.3; }
.toast-x { background: none; border: 0; border-radius: 50%; width: 1.9rem; height: 1.9rem; flex: none; color: #6b6f5e; font-size: 1.3rem; line-height: 1; padding: 0; cursor: pointer; }
.toast-x:hover { background: rgba(20, 35, 29, .08); color: var(--ink); }
.toast.ok::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--c); opacity: .55; transform-origin: left; animation: toast-timer 5s linear forwards; }
.toast.ok:hover::after { animation-play-state: paused; }
.toast.out { opacity: 0; transform: translateY(-.8rem); transition: opacity .25s, transform .25s; }
/* a deck: only the newest is shown whole, the older ones (still on their timer) peek out below it as two thinner edges; hovering the deck spreads
   them out, as a list, to read or close them */
.toasts:not(:hover) { display: grid; justify-items: center; }
.toasts:not(:hover) > .toast { grid-area: 1 / 1; align-self: end; transition: transform .3s cubic-bezier(.2, .9, .3, 1), opacity .3s; }
.toasts:not(:hover) > .toast:not(:last-child) { height: 3.4rem; padding-block: 0; }          /* the edges behind: as short as the shortest card, whatever their text */
.toasts:not(:hover) > .toast:not(:last-child) > * { visibility: hidden; }
.toasts:not(:hover) > .toast:not(:last-child)::after { opacity: 0; }                       /* hidden, but its timer keeps running: it is what dismisses the toast */
.toasts:not(:hover) > .toast:nth-last-child(2) { transform: translateY(.6rem) scale(.95); opacity: .85; z-index: -1; }
.toasts:not(:hover) > .toast:nth-last-child(3) { transform: translateY(1.2rem) scale(.9); opacity: .6; z-index: -2; }
.toasts:not(:hover) > .toast:nth-last-child(n+4) { transform: translateY(1.2rem) scale(.9); opacity: 0; z-index: -3; }
.toasts { isolation: isolate; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-1.2rem) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toast-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .toast.ok::after { animation: none; transform: none; } }

/* our own confirm dialog (window.ask in core.js) */
dialog.dlg.ask { border-radius: 14px; border: 0; box-shadow: 0 18px 50px rgba(20, 35, 29, .45); width: min(24rem, calc(100vw - 2rem)); padding: 1.4rem 1.5rem 1.2rem; }
dialog.dlg.ask p { margin: 0 0 1rem; padding-right: 1.4rem; font-size: 1.02rem; line-height: 1.45; color: var(--ink); }
dialog.dlg.ask input { width: 100%; box-sizing: border-box; margin: 0 0 1rem; }
dialog.dlg.ask .actions { margin: 0; justify-content: flex-end; flex-direction: row-reverse; }
dialog.dlg.ask .btn { border-radius: 8px; }

/* audit log: the before / after of a record, in a dialog */
.audit-dlg code { font-size: 1rem; }
.audit-dlg .kv { margin: .4rem 0 1rem; }
.audit-dlg table.audit-fields td { vertical-align: top; overflow-wrap: anywhere; }
.audit-dlg table.audit-fields tr.chg td { background: #f7ecc6; }
.audit-dlg table.audit-fields ul.plain { margin: 0; padding: 0; list-style: none; }
.audit-dlg .actions { margin-top: 1rem; }

/* a list of things waiting for a person (e.g. quota receipts with no socio yet): wraps instead of scrolling sideways */
.pending-list { list-style: none; margin: .6rem 0 0; padding: 0; border-top: 1px solid var(--line); }
.pending-list > li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.2rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.pending-list .pr-ref { flex: 0 0 9.5rem; }
.pending-list .pr-who { flex: 1 1 16rem; min-width: 0; }
.pending-list .pr-act { flex: 1 1 22rem; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; justify-content: flex-end; }
.pending-list .pr-act form { display: flex; flex: 1 1 15rem; gap: .5rem; margin: 0; min-width: 0; }
.pending-list .pr-act select { flex: 1 1 auto; min-width: 0; }
.pending-list .sub { display: block; }
.pending-list .why { color: var(--ox); }

/* the party after a new school year / a bilancio made definitivo (celebrate.js): a transparent canvas over everything, clicks go through */
.celebrate { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; }

/* Suggestions under a field while typing (core.js data-suggest, Movimenti banca) */
.bm-find, .suggest { position: relative; }
.bm-sugg { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; max-height: 17rem; overflow-y: auto; background: #fff; border: 1px solid var(--ink); border-top: 0;
  box-shadow: 0 8px 18px rgba(20, 35, 29, .2); text-transform: none; letter-spacing: 0; font-weight: 400; }
.bm-sugg[hidden] { display: none; }
.bm-sugg-o { display: grid; gap: .1rem; padding: .45rem .75rem; cursor: pointer; font-size: .88rem; color: var(--char); line-height: 1.35; }
.bm-sugg-o b { font-weight: 600; }
.bm-sugg-o small { font-size: .78rem; color: #6b6f5e; }
.bm-sugg-o.same b::after { content: " · stesso importo"; color: var(--ok); font-weight: 700; }
.bm-sugg-o:hover, .bm-sugg-o[aria-selected="true"] { background: var(--paper); }
.bm-sugg-none { padding: .5rem .75rem; font-size: .85rem; color: #6b6f5e; }
.bm-sugg.up { top: auto; bottom: 100%; border-top: 1px solid var(--ink); border-bottom: 0; }
