/* Admin UI — same palette as the public site (ink / brass / paper / oxblood), flat & square. No external fonts. */
:root {
  --ink: #14231d; --ink-2: #1c2f26; --brass: #c89b3c; --brass-light: #e8c579;
  --paper: #efead9; --paper-2: #e4dec8; --char: #262a1f; --ox: #8b3324; --ox-light: #a8492f;
  --ok: #2f6b3f; --line: rgba(38, 42, 31, .22);
  --display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--char); font: 15px/1.5 var(--body); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--ox); }
[id] { scroll-margin-top: 4.5rem; } /* keep anchors clear of the sticky header */
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0 0 .5rem; color: var(--ink); }
h1 { font-size: 2rem; } h2 { font-size: 1.5rem; }
.label, label span.l { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; color: #5b5f4f; }

.top { background: var(--ink); border-bottom: 1px solid rgba(200, 155, 60, .3); position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1200px; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--paper); text-decoration: none; font-family: var(--display); font-size: 1.25rem; }
.brand img { border-radius: 50%; }
.top nav { display: flex; gap: .25rem; flex: 1; }
.top nav a { color: var(--paper); text-decoration: none; padding: .4rem .8rem; text-transform: uppercase; letter-spacing: .1em; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.top nav { min-width: 0; }
@media (max-width: 1240px) and (min-width: 641px) { .top nav a { padding: .4rem .55rem; letter-spacing: .06em; } }
.top nav a.on, .top nav a:hover { color: var(--brass-light); box-shadow: inset 0 -2px var(--brass); }
.who { display: flex; align-items: center; gap: .75rem; color: var(--paper); font-size: .85rem; margin-left: auto; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Phones: row 1 = brand + user/logout, row 2 = full-width nav (scrolls sideways if it ever overflows) */
@media (max-width: 640px) {
  .top-in { gap: .35rem .75rem; padding: .5rem .75rem 0; }
  .brand { order: 1; font-size: 1.1rem; }
  .who { order: 2; min-width: 0; font-size: .8rem; gap: .5rem; }
  .who span { max-width: 9rem; }
  .top nav { order: 3; flex: 0 0 100%; margin: 0 -.75rem; padding: 0 .75rem; overflow-x: auto; border-top: 1px solid rgba(200, 155, 60, .2); }
  .top nav a { padding: .65rem .8rem; white-space: nowrap; }
  .wrap { padding-top: 1rem; }
}
button.link { background: none; border: 0; color: var(--brass-light); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }

.wrap { max-width: 1200px; width: 100%; margin: 0 auto; padding: 1.5rem 1rem 4rem; flex: 1 0 auto; }
.card { background: #f7f4e8; border: 1px solid var(--line); padding: 1.1rem 1.25rem; margin-bottom: 1.5rem; }
.flash { padding: .7rem 1rem; margin-bottom: 1rem; border-left: 4px solid var(--brass); background: #f7f4e8; }
.flash.ok { border-color: var(--ok); } .flash.error { border-color: var(--ox); background: #f6e3de; } .flash.warn { border-color: var(--brass); }

/* forms */
.grid { display: grid; gap: .8rem 1rem; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.grid > * { grid-column: span 12; min-width: 0; }
@media (min-width: 720px) {
  .c1 { grid-column: span 1 !important; } .c2 { grid-column: span 2 !important; } .c3 { grid-column: span 3 !important; } .c4 { grid-column: span 4 !important; }
  .c5 { grid-column: span 5 !important; } .c6 { grid-column: span 6 !important; } .c8 { grid-column: span 8 !important; } .c9 { grid-column: span 9 !important; }
}
label.f { display: flex; flex-direction: column; gap: .25rem; }
input[type=text], input[type=email], input[type=date], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; background: #fff; border: 1px solid var(--line); padding: .55rem .7rem; font: inherit; color: inherit; border-radius: 0;
}
/* Same look and size for every field, incl. iOS Safari, which draws date inputs natively (wider, taller, centred) */
input[type=text], input[type=email], input[type=date], input[type=password], input[type=number], input[type=search], select { height: 2.65rem; }
input[type=date] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; text-align: left; line-height: 1.5; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
label.f > input, label.f > select { min-width: 0; }
@media (max-width: 720px) { input, select, textarea { font-size: 16px; } } /* below 16px iOS zooms the page when a field gets focus */
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; border-color: var(--brass); }
.err { color: var(--ox); font-size: .8rem; }
.has-err input, .has-err select { border-color: var(--ox); }
/* amount field: "€" shown at the end, inside the box */
.amt { position: relative; display: block; }
.amt input { padding-right: 2.2rem; }
.amt::after { content: "€"; position: absolute; right: .8rem; top: 0; line-height: 2.65rem; color: #5b5f4f; pointer-events: none; }
/* 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; } }

.btn { display: inline-block; background: var(--ox); color: var(--paper); border: 0; padding: .65rem 1.4rem; font: 600 .75rem var(--body); letter-spacing: .14em; text-transform: uppercase; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--ox-light); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.btn.ghost:hover { background: var(--ink); color: var(--paper); }
.btn.sm { padding: .35rem .7rem; font-size: .68rem; }
.btn.danger { background: transparent; color: var(--ox); border: 1px solid var(--ox); }
.btn.danger:hover { background: var(--ox); color: var(--paper); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.hint { color: #6b6f5e; font-size: .8rem; }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); background: #fbf9f0; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td.wrapok { white-space: normal; min-width: 12rem; }
table.t th { background: var(--ink-2); color: var(--paper); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; }
table.t th a { color: inherit; text-decoration: none; }
table.t th a:hover { color: var(--brass-light); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.void td { color: #8a8d7c; text-decoration: line-through; background: #efecdf; }
table.t tr.void td.keep { text-decoration: none; }
table.t tbody tr:hover td { background: #f1ecd6; }
.badge { display: inline-block; font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; padding: .1rem .45rem; border: 1px solid currentColor; }
.badge.rf { color: var(--ox); } .badge.nf { color: #5b5f4f; } .badge.ok { color: var(--ok); } .badge.bad { color: var(--ox); background: #f6e3de; }

.totals { display: flex; gap: 1.5rem; flex-wrap: wrap; padding: .8rem 1rem; background: var(--ink); color: var(--paper); margin: 1rem 0 0; }
.totals b { display: block; font-family: var(--display); font-size: 1.5rem; color: var(--brass-light); line-height: 1.1; }
.totals span { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; }
.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); }
.quick a { margin-right: .75rem; font-size: .8rem; }

.login { max-width: 380px; margin: 8vh auto; }
.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); 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; }
details.menu > summary { list-style: none; cursor: pointer; width: 2.2rem; height: 2.2rem; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: #fff; font-size: 1.3rem; line-height: 1; color: var(--ink); user-select: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover, details.menu[open] > summary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.menu-panel { position: fixed; z-index: 30; min-width: 11rem; background: #fff; border: 1px solid var(--ink); 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); 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; }
/* collapsible filters (open on desktop, collapsed on phones by an inline script in ricevute.php) */
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; }
/* Touch: tell iOS Safari these are plain taps (no wait for a possible double-tap zoom) and give instant pressed feedback */
a, button, label, summary, input, select, textarea { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.seg label:active span, .opt:active { background: var(--paper-2); }
/* payment method: three big tappable options instead of a dropdown */
.seg { display: flex; border: 1px solid var(--line); margin-top: .25rem; }
.seg label { flex: 1; cursor: pointer; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 0 .6rem; line-height: 2.55rem; background: #fff; border-right: 1px solid var(--line); white-space: nowrap; }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--ink); color: var(--paper); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--brass); outline-offset: -2px; }
.has-err .seg { border-color: var(--ox); }
/* one-tap causali */
.chips { margin-top: .35rem; font-size: .8rem; color: #6b6f5e; line-height: 1.5; } /* same look as the "Rapidi:" line in the filters */
.chips-label { margin-right: .5rem; }
.chip { background: none; border: 0; padding: 0; margin: 0 .75rem 0 0; font: inherit; color: var(--ox); text-decoration: underline; cursor: pointer; }
@media (max-width: 720px) { .chip { padding: .35rem 0; } } /* keep a comfortable tap target */
details.notes > summary { cursor: pointer; font-size: .85rem; color: #5b5f4f; padding: .2rem 0; }
details.notes[open] > summary { margin-bottom: .4rem; }
.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 */
}
/* footer: same look as the public site (ink background, brass accents, centred) */
.site-foot { background: var(--ink); color: rgba(239, 234, 217, .8); margin-top: 2rem; }
.site-foot-in { max-width: 72rem; margin: 0 auto; padding: 3.5rem 1.25rem; text-align: center; }
.site-foot a { color: inherit; text-decoration: none; transition: color .15s; }
.site-foot a:hover, .site-foot a:focus-visible { color: var(--brass); }
.sf-name { margin: 0; font-family: var(--display); font-style: italic; font-size: 1.5rem; color: var(--paper); }
.sf-place { margin: .25rem 0 0; font-size: .75rem; letter-spacing: .14em; text-transform: uppercase; font-weight: 600; color: var(--brass); }
.sf-social { display: flex; justify-content: center; gap: 1.5rem; margin-top: 2rem; }
.sf-social a { color: rgba(239, 234, 217, .7); line-height: 0; }
.sf-social svg { width: 1.5rem; height: 1.5rem; }
.sf-nav { display: flex; justify-content: center; flex-wrap: wrap; gap: .5rem 1.5rem; margin-top: 2rem; font-size: .75rem; letter-spacing: .14em; text-transform: uppercase; font-weight: 600; color: rgba(239, 234, 217, .6); }
.sf-addr { font-style: normal; margin-top: 2rem; font-size: .75rem; line-height: 1.7; color: rgba(239, 234, 217, .6); }
.sf-copy { margin: 1rem 0 0; font-size: .75rem; color: rgba(239, 234, 217, .4); }
/* live refresh: toast + highlight of rows that just arrived */
#toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translate(-50%, 1rem); opacity: 0; pointer-events: none; z-index: 40; background: var(--ink); color: var(--paper); padding: .65rem 1.1rem; border-left: 4px solid var(--brass); box-shadow: 0 6px 18px rgba(20, 35, 29, .3); transition: opacity .2s, transform .2s; max-width: calc(100vw - 2rem); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes flash-new { from { background: #f1dc9c; } to { background: transparent; } }
table.t tr.flash-new td { animation: flash-new 4s ease-out; }
@media (prefers-reduced-motion: reduce) { table.t tr.flash-new td { animation: none; background: #f1dc9c; } }
/* 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; }
/* "Scuola" drop-down in the top bar (same mechanism as the row menus; the panel is placed by admin.js) */
.top nav details.navmenu { display: block; }
.top nav details.navmenu > summary { width: auto; height: auto; display: block; border: 0; background: none; color: var(--paper); padding: .4rem .8rem; text-transform: uppercase; letter-spacing: .1em; font-size: .75rem; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.top nav details.navmenu > summary::after { content: " \25BE"; font-size: .7rem; }
.top nav details.navmenu > summary:hover, .top nav details.navmenu[open] > summary, .top nav details.navmenu.on > summary { background: none; color: var(--brass-light); }
.top nav details.navmenu.on > summary { box-shadow: inset 0 -2px var(--brass); }
/* inside the white panel the links must NOT inherit the top bar's light, uppercase style */
.top nav .menu-panel a { color: var(--char); text-transform: none; letter-spacing: 0; font-size: .92rem; font-weight: 400; padding: .65rem .9rem; box-shadow: none; display: block; }
.top nav .menu-panel a:hover, .top nav .menu-panel a:focus-visible { color: var(--ink); background: var(--paper); box-shadow: none; }
.top nav .menu-panel a.on { color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 var(--brass); }
.nbadge { display: inline-block; min-width: 1.15rem; padding: 0 .3rem; margin-left: .25rem; text-align: center; font-size: .68rem; line-height: 1.15rem; background: var(--ox); color: var(--paper); border-radius: 999px; letter-spacing: 0; }
@media (max-width: 1240px) and (min-width: 641px) { .top nav details.navmenu > summary { padding: .4rem .55rem; letter-spacing: .06em; } }
@media (max-width: 640px) { .top nav details.navmenu > summary { padding: .65rem .8rem; } }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* 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; }
