:root {
  --bg: #f6f1e9; --surface: #fffdf9; --surface-2: #f0e9de; --ink: #2a2420; --muted: #75695f; --line: #e3d9cb;
  --accent: #b5532f; --accent-ink: #ffffff; --accent-soft: #f6e1d6;
  --ok: #3f7a4f; --ok-soft: #e1efe3; --warn: #a96b12; --warn-soft: #f8ecd2; --bad: #b0352b; --bad-soft: #f7dedb;
  --radius: 12px; --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714; --surface: #24201c; --surface-2: #2d2823; --ink: #f1e9df; --muted: #a99d91; --line: #3b342e;
    --accent: #e07a52; --accent-ink: #1b1714; --accent-soft: #3d2a20;
    --ok: #7fc18f; --ok-soft: #22352a; --warn: #e0ac55; --warn-soft: #3a2f1c; --bad: #ec8a7f; --bad-soft: #3d2422;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: var(--mono); }
code, .code { font-family: var(--mono); background: var(--surface-2); padding: .1em .4em; border-radius: 6px; }

/* layout gestore */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; padding: 0 10px 18px; display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; }
.brand svg { color: var(--accent); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 10px; font-size: .75rem; padding: 0 7px; font-weight: 700; }
.side .foot { margin-top: auto; padding: 10px; font-size: .85rem; }
.main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { margin: 0; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; z-index: 5; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 0; font-size: 1.1rem; }
  .brand span { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { white-space: nowrap; margin: 0; padding: 7px 10px; }
  .nav a .lbl-long { display: none; }
  .side .foot { margin: 0 0 0 auto; padding: 0 0 0 8px; white-space: nowrap; }
  .main { padding: 20px 16px 50px; }
}

/* componenti */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-family: var(--serif); font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 .92rem var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 7px; }
.btn.wa { background: #25d366; border-color: #25d366; color: #0b3d1f; }
button[disabled], .btn[aria-disabled=true] { opacity: .5; pointer-events: none; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.acc { background: var(--accent-soft); color: var(--accent); }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-soft); color: var(--ok); } .alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); } .alert.info { background: var(--surface-2); }

.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=email], input[type=tel], input[type=url], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); font: 15px var(--sans); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg label { margin: 0; padding: 8px 14px; cursor: pointer; font-weight: 600; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }

/* keybox */
.kb { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.kb .card { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.kb .code { font-family: var(--mono); font-size: 2rem; letter-spacing: .25em; font-weight: 700; }
.kb .card.urgente { border-color: var(--bad); }
.kb .card.avviso { border-color: var(--warn); }

/* elenco giorno */
.day { font-family: var(--serif); font-weight: 600; margin: 18px 0 6px; color: var(--muted); }
.line-preview { font-family: var(--mono); font-size: .72rem; white-space: pre; background: var(--surface-2); padding: 8px; border-radius: 8px; overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.docimg { max-width: 100%; max-height: 260px; border-radius: 8px; border: 1px solid var(--line); }

/* pagine ospite */
.guest { max-width: 620px; margin: 0 auto; padding: 24px 16px 70px; }
.guest .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.guest .hero { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.guest .hero .dates { display: flex; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.guest .hero .dates div span { display: block; font-size: .8rem; color: var(--muted); }
.guest .hero .dates div strong { font-family: var(--serif); font-size: 1.15rem; }
.ospite { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.ospite:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.ac { position: relative; }
.ac-list { position: absolute; z-index: 10; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; margin-top: 2px; }
.ac-list div { padding: 8px 11px; cursor: pointer; }
.ac-list div:hover, .ac-list div.sel { background: var(--accent-soft); }
.photo { border: 1.5px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; cursor: pointer; background: var(--surface-2); }
.photo img { max-width: 100%; max-height: 160px; border-radius: 6px; display: block; margin: 0 auto 6px; }
.bigcode { font-family: var(--mono); font-size: 3rem; font-weight: 700; letter-spacing: .3em; text-align: center; padding: 18px; background: var(--accent-soft); color: var(--accent); border-radius: var(--radius); margin: 12px 0; }
.sticky-submit { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 8px; }
.sticky-submit .btn { width: 100%; padding: 14px; font-size: 1rem; }
.err { color: var(--bad); font-size: .85rem; margin-top: 4px; }
.invalid { border-color: var(--bad) !important; }
