:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #1f1a17;
  --muted: #6b625b;
  --line: #e4ddd3;
  --accent: #8b1e2d;
  --accent-text: #ffffff;
  --gold: #b8892b;
  --libero: #e8e2d8;
  --libero-text: #3a332d;
  --prenotata: #e7b14a;
  --pagata: #8b1e2d;
  --attesa: #9aa0a6;
  --sel: #1f7a4d;
  --ok: #1f7a4d;
  --err: #b42318;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --card: #221c17;
    --text: #f2ece4;
    --muted: #a99f95;
    --line: #3a312a;
    --accent: #c4475a;
    --libero: #3a322b;
    --libero-text: #e6ddd2;
    --prenotata: #d39b2f;
    --pagata: #c4475a;
    --attesa: #6c7177;
    --sel: #2fa36b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
header.top {
  background: var(--accent);
  color: var(--accent-text);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
header.top h1 { font-size: 1.25rem; margin: 0; font-family: Georgia, "Times New Roman", serif; letter-spacing: .02em; }
header.top .spacer { flex: 1; }
header.top a, header.top button.link { color: var(--accent-text); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h2 { font-family: Georgia, "Times New Roman", serif; margin: 8px 0 12px; }
h3 { margin: 16px 0 8px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 8px; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 70px; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button.sec, .btn.sec { background: transparent; color: var(--accent); }
button.piccolo { padding: 4px 10px; font-size: .85rem; font-weight: 500; }
button.link { background: none; border: none; padding: 0; text-decoration: underline; font-weight: 400; color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
.azioni { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* tab */
nav.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
nav.tabs button {
  background: none; border: none; color: var(--muted);
  border-bottom: 3px solid transparent; border-radius: 0; padding: 10px 14px; white-space: nowrap;
}
nav.tabs button.attivo { color: var(--accent); border-bottom-color: var(--accent); }

/* mappa sala */
.sala-scroll { overflow-x: auto; padding-bottom: 8px; }
.sala { display: inline-block; min-width: 100%; text-align: center; }
.palco {
  margin: 0 auto 18px;
  max-width: 420px;
  padding: 8px;
  border-radius: 0 0 50% 50% / 0 0 18px 18px;
  background: linear-gradient(var(--accent), color-mix(in srgb, var(--accent) 70%, black));
  color: var(--accent-text);
  font-size: .8rem;
  letter-spacing: .3em;
}
.file { display: inline-flex; flex-direction: column; gap: calc(var(--gap, 4px) + 1px); }
.fila { display: flex; gap: var(--gap, 4px); align-items: center; justify-content: center; }
.fila-label { width: var(--lab, 22px); font-size: .8rem; color: var(--muted); font-weight: 600; }
.corridoio { width: var(--seat, 30px); height: var(--seat, 30px); }
.passaggio { height: calc(var(--seat, 30px) * .8); }
.posto.tre-cifre { font-size: .62rem; letter-spacing: -.03em; }
.posto {
  width: var(--seat, 30px); height: var(--seat, 30px); padding: 0;
  border: none; border-radius: 7px 7px 4px 4px;
  font-size: .72rem; font-weight: 600;
  background: var(--libero); color: var(--libero-text);
}
.posto.acc { box-shadow: inset 0 0 0 2px #2b6cb0; }
.posto.prenotata { background: var(--prenotata); color: #2a1d05; }
.posto.pagata { background: var(--pagata); color: #fff; }
.posto.in_attesa_pagamento { background: var(--attesa); color: #fff; }
.posto.sel { background: var(--sel); color: #fff; outline: 2px solid var(--sel); outline-offset: 1px; }
.posto:disabled { cursor: not-allowed; opacity: 1; }
.posto:not(:disabled):hover { filter: brightness(.92); }
.legenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin: 10px 0; }
.legenda span.acc::before { box-shadow: inset 0 0 0 2px #2b6cb0; }
.legenda span::before {
  content: ""; display: inline-block; width: 14px; height: 14px; border-radius: 4px;
  vertical-align: -2px; margin-right: 6px; background: var(--c);
}

/* editor sala */
.editor .cella {
  width: 30px; height: 30px; padding: 0; border-radius: 6px; font-size: .7rem; font-weight: 600;
  border: 1px dashed var(--line); background: transparent; color: var(--muted);
}
.editor .cella.S { background: var(--libero); color: var(--libero-text); border-style: solid; }
.editor .cella.H { background: var(--libero); color: var(--libero-text); border: 2px solid #2b6cb0; }
.editor .fila-label input { width: 34px; padding: 2px; text-align: center; margin: 0; font-size: .8rem; }
.editor .fila-label { width: 38px; }
.strumenti { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.strumenti button.attivo { outline: 3px solid var(--gold); }

/* liste */
.tabella-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.prenotata { background: color-mix(in srgb, var(--prenotata) 30%, transparent); }
.badge.pagata { background: color-mix(in srgb, var(--pagata) 25%, transparent); }
.badge.in_attesa_pagamento { background: color-mix(in srgb, var(--attesa) 30%, transparent); }
.badge.annullata, .badge.rimborsata { background: var(--line); color: var(--muted); }

.spettacoli { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.spettacolo { display: flex; flex-direction: column; }
.spettacolo img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; margin-bottom: 10px; }
.spettacolo .azioni { margin-top: auto; padding-top: 12px; }
.stat { font-size: 1.8rem; font-weight: 700; font-family: Georgia, serif; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.riepilogo li { margin-bottom: 6px; }
.riepilogo select { display: inline-block; width: auto; margin: 0 0 0 8px; padding: 2px 6px; }
.totale { font-size: 1.3rem; font-weight: 700; }

.biglietto { border: 2px dashed var(--accent); }
.codice { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.6rem; letter-spacing: .15em; font-weight: 700; color: var(--accent); }

#toasts { position: fixed; bottom: 16px; left: 16px; right: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: 8px; color: #fff; background: var(--ok); max-width: 520px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--err); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); max-width: 560px; width: calc(100% - 32px); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.nascosto { display: none !important; }

/* Su telefono la platea si stringe per stare tutta nello schermo. */
@media (max-width: 600px) {
  main { padding: 12px; }
  .card { padding: 12px; }
  .sala { --seat: min(18px, calc((100vw - 110px) / 19)); --gap: 1px; --lab: 14px; }
  .sala .posto { font-size: .55rem; border-radius: 5px 5px 3px 3px; }
  .sala .posto.tre-cifre { font-size: .46rem; letter-spacing: -.05em; }
  .palco { margin-bottom: 12px; }
}

/* crediti e licenza */
footer.crediti { text-align: center; font-size: .8rem; color: var(--muted); padding: 24px 16px 32px; }
footer.crediti strong { color: var(--text); font-weight: 600; }
.avviso { border-color: var(--err); color: var(--err); }
.attestato { border: 2px solid var(--gold); text-align: center; padding: 24px 16px; }
.attestato .sigillo { font-size: .75rem; letter-spacing: .25em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.attestato h2 { margin: 6px 0 4px; }
.attestato dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; text-align: left; max-width: 460px; margin: 16px auto 0; }
.attestato dt { color: var(--muted); }
.attestato dd { margin: 0; font-weight: 600; }
pre.contratto { white-space: pre-wrap; font: .85rem/1.55 ui-monospace, Menlo, Consolas, monospace; max-height: 420px; overflow: auto; margin: 0; }

@media print {
  header.top, nav.tabs, .azioni, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; }
}
