/* Base comune a gestionale e widget: colori, testo, pulsanti, campi, finestre. */
:root {
  --paper: #f4f4ef;
  --surface: #ffffff;
  --ink: #1d2a26;
  --muted: #5f6b66;
  --rule: #d6dbd3;

  --green: #2f7d52;
  --green-dark: #24633f;
  --green-soft: #e1efe6;
  --on-accent: #ffffff;          /* testo sopra il colore principale: il widget lo adatta al colore scelto */
  --field-border: #aeb7b0;
  --red: #c23b2e;
  --red-dark: #a02d22;
  --red-ink: #a02d22;            /* testo rosso su fondo rosso chiaro */
  --red-text: var(--red-dark);   /* testo rosso su fondo chiaro o rosso chiaro; il tema scuro lo schiarisce */
  --green-text: var(--green-dark); /* testo verde: nel widget segue il colore scelto dal ristoratore (--green-dark lo calcola il widget) */
  --red-soft: #f7e1de;
  --amber: #e9b949;
  --amber-soft: #fbf1d6;
  --amber-ink: #5a4310;
  --black: #1b1f1d;
  --grey-soft: #e9ebe7;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;

  --r-control: 8px;
  --r-panel: 14px;
}

/* Tema scuro: lo attiva il widget quando il ristoratore lo sceglie (attributo data-theme sull'elemento html). */
:root[data-theme="dark"], .anteprima-aspetto[data-theme="dark"] {
  color-scheme: dark;
  --red-text: #f5a89f;
  --paper: #121618;
  --surface: #1c2225;
  --ink: #edf1ee;
  --muted: #a8b3ad;
  --rule: #343d39;
  --field-border: #6a7772;
  --red-ink: #f5a89f;
  --red-soft: #3d1f1c;
  --amber-soft: #3a3115;
  --amber-ink: #f3dc92;
  --black: #0b0e0d;
  --grey-soft: #2a3230;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--font-ui);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0; }

a { color: var(--link, var(--green-text)); }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grow { flex: 1 1 auto; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Pulsanti ---------- */
.btn {
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--rule); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
/* Il colore «sotto il cursore» vale solo dove c'è un mouse: sul touch :hover resta acceso dopo il tocco e il pulsante sembrerebbe già scelto (versione W). */
@media (hover: hover) { .btn:hover { background: var(--grey-soft); } }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--green); border-color: var(--green); color: var(--on-accent); }
@media (hover: hover) { .btn-primary:hover { background: var(--green-dark); } }
.btn-dark { background: var(--black); border-color: var(--black); color: #fff; }
@media (hover: hover) { .btn-dark:hover { background: #000; } }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
@media (hover: hover) { .btn-danger:hover { background: var(--red-dark); } }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }

/* ---------- Campi ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .field-label { font-size: 0.9rem; font-weight: 600; }
.field .hint { font-size: 0.85rem; color: var(--muted); }

.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--field-border); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink); font: inherit;
}

/* Gruppo di campi senza cornice (serve a disabilitarli tutti insieme con l'attributo disabled). */
fieldset.plain { margin: 0; padding: 0; border: 0; min-width: 0; }
.textarea { min-height: 88px; resize: vertical; }
.input-narrow { width: 6.5rem; }

/* ---------- Etichette ---------- */
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--grey-soft); color: var(--ink);
  font-size: 0.82rem; font-weight: 600; white-space: nowrap;
}
.pill-green { background: var(--green-soft); color: var(--green-text); }
.pill-red { background: var(--red); color: #fff; }
.pill-amber { background: var(--amber-soft); color: var(--amber-ink); }

/* ---------- Finestre ---------- */
dialog.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  padding: 0; border: 0; border-radius: var(--r-panel);
  background: var(--surface); color: var(--ink);
}
dialog.dialog::backdrop { background: rgba(20, 28, 24, 0.55); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-actions {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end;
  position: sticky; bottom: 0; margin: 4px -20px -20px; padding: 12px 20px 20px;
  background: var(--surface); border-top: 1px solid var(--rule);
}

/* ---------- Messaggi ---------- */
.notice { padding: 10px 14px; border-radius: var(--r-control); background: var(--grey-soft); }
.notice-error { background: var(--red-soft); color: var(--red-ink); }
.notice-ok { background: var(--green-soft); color: var(--green-text); }

.toasts {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 50;
  width: min(420px, calc(100vw - 24px));
}
.toast {
  padding: 12px 16px; border-radius: var(--r-control);
  background: var(--black); color: #fff; font-weight: 600;
}
.toast-error { background: var(--red-dark); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
