/* =====================================================================
   Regia - sistema visivo.
   Token e componenti copiati dall'app sala di Appetito
   (stazione-prenotazioni, pb_public/staff/staff.css, commit 9855cc8).
   Copia indipendente: nessun collegamento tra i due progetti.
   Il colore e' riservato a cio' che richiede un'azione:
   rosso = scaduto, ambra = da fare, blu = selezione. Il resto in grigio.
   ===================================================================== */
:root { color-scheme: light; }
body {
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #F4F2EE; --surface: #FFFFFF; --surface-2: #F7F5F1; --surface-3: #EAE7E1;
  --line: rgba(28, 26, 23, .08); --line-2: rgba(28, 26, 23, .18);
  --text: #1C1A17; --muted: #57524A; --faint: #7A7368;
  --primary-bg: #18181b; --primary-ink: #ffffff;
  --late: #C2341B; --late-bg: #FBE7E2; --late-ink: #8C2614;
  --todo: #F3B13F; --todo-bg: #FCEFD8; --todo-ink: #9A5B00;
  --ok: #2D6A4F; --ok-bg: #e5f5ec;
  --sel: #2F5B8A; --sel-bg: #E3ECF6; --sel-ink: #ffffff;
  --shadow: 0 12px 40px rgba(0, 0, 0, .14);
  --ease: cubic-bezier(.2, .8, .2, 1);
  background: var(--bg); color: var(--text); font-family: var(--font-ui);
}
body[data-theme="dark"] {
  --bg: #141311; --surface: #1D1B19; --surface-2: #252320; --surface-3: #2F2C28;
  --line: rgba(242, 239, 234, .08); --line-2: rgba(242, 239, 234, .18);
  --text: #F2EFEA; --muted: #BDB7AD; --faint: #8F897F;
  --primary-bg: #F2EFEA; --primary-ink: #141311;
  --late: #FF7A5C; --late-bg: #3A1A14; --late-ink: #FF7A5C;
  --todo: #F2B04A; --todo-bg: #3A2A10; --todo-ink: #F2B04A;
  --ok: #3D8B6A; --ok-bg: rgba(61, 139, 106, .14);
  --sel: #8DB3DD; --sel-bg: #1E2C3B; --sel-ink: #141311;
  --shadow: 0 16px 50px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-size: 15.5px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--sel); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ============================================================ struttura */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; margin-right: 6px; }
.bar .spacer { flex: 1; }
.nav { display: flex; gap: 2px; }
.nav a { text-decoration: none; height: 36px; padding: 0 11px; border-radius: 9px; font-size: 14.5px; font-weight: 550; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.nav a[aria-current="true"] { background: var(--surface-3); color: var(--text); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--todo); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
body[data-theme="dark"] .badge { color: #1a1206; }
.badge.late { background: var(--late); color: #fff; }
.badge:empty { display: none; }
main { padding: 18px 16px 90px; max-width: 1180px; margin: 0 auto; }
main.wide { max-width: none; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.015em; flex: 1 1 auto; }
.tabbar { display: none; }

/* timer in corso */
.timer { display: none; align-items: center; gap: 10px; padding: 8px 16px; background: var(--sel-bg); color: var(--text); font-size: 14px; border-bottom: 1px solid var(--line); }
.timer.on { display: flex; }
.timer .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sel); animation: blink 1.6s infinite; flex: 0 0 auto; }
.timer .what { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer b { font-variant-numeric: tabular-nums; }

/* ============================================================ controlli */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-size: 15px; font-weight: 600; text-decoration: none; white-space: nowrap; transition: transform .1s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary-bg); color: var(--primary-ink); border-color: transparent; }
.btn.todo { background: var(--todo); color: #fff; border-color: transparent; }
body[data-theme="dark"] .btn.todo { color: #1a1206; }
.btn.late { background: var(--late); color: #fff; border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.sel { background: var(--sel); color: var(--sel-ink); border-color: transparent; }
.btn.danger { color: var(--late); }
.btn.ghost { background: none; border-color: transparent; }
.btn.sm { height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.btn.xs { height: 30px; padding: 0 10px; border-radius: 8px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; height: 34px; padding: 0 12px; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 550; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 7px; font-size: 12.5px; font-weight: 600; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.chip.todo { background: var(--todo-bg); color: var(--todo-ink); }
.chip.late { background: var(--late-bg); color: var(--late-ink); }
.chip.sel { background: var(--sel-bg); color: var(--sel); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
button.chip { border: 0; }
button.chip[aria-pressed="true"] { background: var(--sel); color: var(--sel-ink); }

.select, .input { height: 38px; border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; padding: 0 10px; font-size: 14.5px; color: var(--text); }
.field { display: grid; gap: 6px; margin: 12px 0; }
.field > label, .lbl { font-size: 13px; font-weight: 650; color: var(--muted); }
.field input, .field textarea, .field select { width: 100%; border: 1px solid var(--line-2); background: var(--surface-2); border-radius: 11px; padding: 10px 12px; font-size: 16px; min-height: 44px; color: var(--text); }
.field textarea { min-height: 120px; line-height: 1.45; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus, .select:focus, .input:focus { outline: none; border-color: var(--sel); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sel) 20%, transparent); }
.field .help { font-size: 12.5px; color: var(--faint); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }

/* ============================================================ card e liste */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.sec-title { margin: 22px 2px 8px; font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sec-title:first-child { margin-top: 4px; }
.sec-title .btn { text-transform: none; letter-spacing: 0; }
.empty { padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 14.5px; display: flex; gap: 10px; align-items: center; }
.empty.calm::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }

/* numeri in cima a Oggi */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.late b { color: var(--late); }

/* righe attivita' */
.task { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px 12px 12px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 8px; position: relative; overflow: hidden; }
.task::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, transparent); }
.task.late { --c: var(--late); }
.task.today { --c: var(--todo); }
.task.running { box-shadow: inset 0 0 0 1.5px var(--sel); }
.task .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.task .tit { font-size: 16px; font-weight: 620; margin-top: 3px; }
.task .when { font-variant-numeric: tabular-nums; font-weight: 600; }
.task.late .when { color: var(--late); }
.task .acts { display: flex; gap: 6px; }
.task .pub { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; gap: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.task .pub img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; background: var(--surface-3); }
.task .caption { font-size: 14px; white-space: pre-wrap; max-height: 7.2em; overflow: hidden; color: var(--text); }
.task > div { min-width: 0; }

/* ============================================================ sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .38); z-index: 30; display: grid; place-items: center; padding: 20px; }
.sheet { width: min(640px, 100%); max-height: min(90dvh, 960px); overflow-y: auto; background: var(--surface); color: var(--text); border-radius: 20px; box-shadow: var(--shadow); padding: 18px 20px 20px; animation: rise .2s var(--ease); }
.sheet.wide { width: min(1080px, 100%); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 4px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.015em; line-height: 1.2; }
.sheet-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.x { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-3); color: var(--muted); font-size: 20px; line-height: 1; flex: 0 0 auto; }
.sheet-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.sheet-foot .spacer { flex: 1; }

#toasts { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(480px, calc(100% - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--primary-bg); color: var(--primary-ink); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 15px; animation: drop .2s var(--ease); }
.toast.err { background: var(--late); color: #fff; }

/* ============================================================ accesso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(360px, 100%); display: grid; gap: 4px; }
.login h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -.02em; }

/* ============================================================ calendario */
.cal-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cal-head .title { font-size: 22px; font-weight: 700; letter-spacing: -.015em; min-width: 190px; text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.cal .dow { background: var(--surface-2); padding: 6px 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.day { background: var(--surface); min-height: 128px; padding: 6px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.day.out { background: var(--surface-2); }
.day.out > * { opacity: .55; }
.day .n { font-size: 13px; font-weight: 650; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.day.today .n span { background: var(--sel); color: var(--sel-ink); border-radius: 999px; padding: 0 7px; }
.day .add { border: 0; background: none; color: var(--faint); width: 24px; height: 24px; border-radius: 6px; font-size: 18px; line-height: 1; opacity: 0; }
.day:hover .add, .day .add:focus { opacity: 1; }
.day.drop { background: var(--sel-bg); }
.week .day { min-height: 60vh; }
.ct { display: grid; grid-template-columns: 34px 1fr; gap: 6px; align-items: center; padding: 3px; border-radius: 9px; border: 1.5px solid var(--line-2); background: var(--surface); font-size: 12px; text-align: left; touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab; }
.ct .th { width: 34px; height: 34px; border-radius: 6px; background: var(--surface-3) center/cover no-repeat; }
.ct .tx { min-width: 0; line-height: 1.2; }
.ct .tx b { display: block; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct .tx span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.ct.st-slot { border-style: dashed; background: none; }
.ct.st-slot.soon { border-color: var(--todo); }
.ct.st-bozza { border-color: var(--line-2); }
.ct.st-pronto { border-color: var(--todo); }
.ct.st-approvato { border-color: var(--sel); }
.ct.st-programmato { border-color: var(--ok); }
.ct.st-pubblicato { border-color: transparent; background: var(--surface-3); }
.ct.st-pubblicato .tx b::before { content: "✓ "; color: var(--ok); }
.ct.dragging { opacity: .9; box-shadow: var(--shadow); position: fixed; z-index: 40; pointer-events: none; width: 160px; }
.week .ct { grid-template-columns: 56px 1fr; }
.week .ct .th { width: 56px; height: 56px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; border: 1.5px solid var(--line-2); margin-right: 5px; vertical-align: -1px; }

/* galleria asset */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.thumb { position: relative; border-radius: 10px; overflow: hidden; background: var(--surface-3); aspect-ratio: 1; border: 2px solid transparent; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb[aria-pressed="true"] { border-color: var(--sel); }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 11.5px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.6)); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .used { position: absolute; top: 5px; right: 5px; }

/* ============================================================ laboratorio tagli */
.dropzone { border: 2px dashed var(--line-2); border-radius: 16px; padding: 28px; text-align: center; color: var(--muted); background: var(--surface); }
.dropzone.over { border-color: var(--sel); background: var(--sel-bg); }
.lab { display: grid; gap: 16px; margin-top: 16px; }
.lab-item { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 16px; }
.lab-item .master { position: relative; cursor: crosshair; border-radius: 10px; overflow: hidden; background: var(--surface-3); align-self: start; }
.lab-item .master canvas { display: block; width: 100%; height: auto; }
.lab-item .poi { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px var(--sel), 0 1px 6px rgba(0,0,0,.5); pointer-events: none; }
.variants { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.variant { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.variant canvas { display: block; border-radius: 8px; background: var(--surface-3); cursor: grab; touch-action: none; }
.variant canvas:active { cursor: grabbing; }
.variant .warn { color: var(--todo-ink); font-weight: 600; }
.variant input[type="range"] { width: 100%; }
.tags { display: flex; gap: 5px; flex-wrap: wrap; }
.check { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; margin-top: 8px; }
.check .bad { color: var(--late); font-weight: 600; }
.check .good { color: var(--ok); font-weight: 600; }

/* ============================================================ tabelle impostazioni */
table.t { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); font-size: 14px; }
table.t th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; background: var(--surface-2); }
table.t td { padding: 6px 10px; border-top: 1px solid var(--line); vertical-align: middle; }
table.t td input, table.t td select { width: 100%; min-width: 60px; height: 34px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 0 8px; font-size: 14px; }
table.t td input[type="checkbox"] { width: 18px; height: 18px; min-width: 0; }
.list { display: grid; gap: 8px; }
.list a.card { text-decoration: none; color: var(--text); display: flex; justify-content: space-between; align-items: center; }

/* ============================================================ telefono */
@media (max-width: 760px) {
  .bar .nav { display: none; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a { flex: 1; text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 600; display: grid; justify-items: center; gap: 2px; padding: 4px 0; border-radius: 10px; position: relative; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="true"] { color: var(--text); }
  .tabbar .badge { position: absolute; top: 0; left: 55%; height: 17px; min-width: 17px; font-size: 11px; }
  main { padding: 14px 12px 100px; }
  .stats { gap: 6px; }
  .stat { padding: 10px; }
  .stat b { font-size: 24px; }
  .stat span { font-size: 12px; }
  .task { grid-template-columns: 1fr; }
  .task .acts { justify-content: stretch; flex-wrap: wrap; }
  .task .acts .btn { flex: 1; }
  .backdrop { padding: 0; place-items: end stretch; }
  .sheet, .sheet.wide { width: 100%; max-height: 94dvh; border-radius: 20px 20px 0 0; padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .day { min-height: 76px; padding: 3px; }
  .ct { grid-template-columns: 1fr; padding: 2px; }
  .ct .th { width: 100%; height: 26px; }
  .ct .tx span { display: none; }
  .ct .tx b { font-size: 10.5px; }
  .day .add { display: none; }
  .lab-item { grid-template-columns: 1fr; }
}
