:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #1b2421; --muted: #5f6d67; --line: #dde4e1;
  --brand: #1f6f5c; --brand-ink: #ffffff; --brand-soft: #dff0ea;
  --warn: #9a4a06; --warn-soft: #fdf0dc; --bad: #b42318; --bad-soft: #fde8e6; --ok: #067647;
  --radius: 14px; --nav-h: 62px;
  --cell: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513; --card: #1a211e; --text: #e8efec; --muted: #9aaaa3; --line: #2c3632;
    --brand: #3fb596; --brand-ink: #06231b; --brand-soft: #1b3a31;
    --warn: #f0a94a; --warn-soft: #3a2d14; --bad: #f1857b; --bad-soft: #3f1d1a; --ok: #4cc58b;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; }
h4 { margin: 16px 0 6px; font-size: 15px; }

#app { max-width: 760px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
#app.full { max-width: none; }
.screen { padding: 0 16px; }
.topbar-wrap { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: env(safe-area-inset-top); }
.topbar { padding: 14px 16px 10px; display: flex; align-items: center; gap: 10px; }
.brandlogo + .topbar { padding-top: 6px; }
.topbar h1 { font-size: 22px; flex: 1; }
.sub { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
.center { text-align: center; }
.row { display: flex; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.gap { gap: 8px; }
.grow { flex: 1; min-width: 0; }

/* pulsanti */
.btn { border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 12px;
  padding: 11px 16px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); padding: 6px 10px; min-height: 36px; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; margin-top: 18px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn:focus-visible, .brush:focus-visible, .namebtn:focus-visible, .person:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.linkbtn { display: block; margin: 2px auto 0; border: 0; background: none; color: var(--brand); font-size: 13px; cursor: pointer; padding: 0; text-decoration: underline; }

/* card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.card.unread { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.card h3 { font-size: 17px; }
details.card > summary { font-weight: 700; cursor: pointer; font-size: 17px; list-style-position: inside; }
details.card[open] > summary { margin-bottom: 8px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.ok { background: var(--brand-soft); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.body-text { white-space: pre-wrap; word-wrap: break-word; margin: 8px 0 0; }
.reply { margin-top: 8px; padding: 8px 10px; background: var(--bg); border-radius: 10px; font-size: 14px; }
.line { padding: 8px 2px; border-bottom: 1px solid var(--line); }
.sect { margin: 16px 2px 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.person { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 12px; margin-bottom: 6px; cursor: pointer; }
.person.off { opacity: .55; }
.swatch { width: 18px; height: 18px; border-radius: 5px; flex: none; }

/* settimana */
.weeknav { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.weeknav .title { flex: 1; text-align: center; font-weight: 600; }
.card.total { display: flex; justify-content: space-between; align-items: center; }
.myday { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 6px; }
.myday.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.myday.off { opacity: .7; }
.myday .when { width: 86px; flex: none; }
.myday .dname { font-weight: 700; }
.myday .dnum { color: var(--muted); font-size: 14px; }
.myday .what { flex: 1; }
.myday .hrs { color: var(--muted); font-size: 14px; white-space: nowrap; }
.eline { padding: 1px 0; }
.eline.code { font-weight: 700; color: var(--warn); }

/* navigazione */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
nav.tabs .inner { max-width: 760px; margin: 0 auto; display: flex; height: var(--nav-h); }
nav.tabs button { flex: 1; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; cursor: pointer; }
nav.tabs button.on { color: var(--brand); }
nav.tabs .ico { font-size: 21px; line-height: 1; }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 99px;
  font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: flex; align-items: center; justify-content: center; }

/* form */
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 5px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; min-height: 46px; }
select.compact { width: auto; min-height: 38px; padding: 6px 10px; }
input[type=color] { padding: 4px; height: 46px; }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; }
.check.compact { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.check.chip { margin: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); border-left: 6px solid var(--c); }
.err { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 20px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.secret { font: 600 24px/1.2 ui-monospace, SFMono-Regular, Consolas, Menlo, monospace; background: var(--card); border: 1px dashed var(--brand);
  border-radius: 12px; padding: 14px; text-align: center; letter-spacing: 1px; margin: 12px 0; user-select: all; }

/* finestre */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 18px); }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sheet-head h2 { font-size: 19px; flex: 1; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.seglist { margin-top: 10px; }
.segrow { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.segrow select { min-height: 42px; padding: 6px 8px; width: auto; }
.segrow select.grow { flex: 1; }

/* accesso */
.login { padding: 10vh 22px 24px; max-width: 440px; margin: 0 auto; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 16px; }
.login h1 { font-size: 28px; margin-bottom: 4px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px);
  background: #1b2421; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: 92vw;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ griglia turni */
.grid-top { padding: calc(env(safe-area-inset-top) + 12px) 16px 6px; position: sticky; left: 0; }
.grid-top h1 { font-size: 22px; }
.toolbar { margin-top: 2px; }
.brushes { display: flex; flex-wrap: wrap; gap: 6px; }
.brush { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); background: var(--card); border-radius: 99px;
  padding: 5px 11px; font-size: 14px; font-weight: 600; cursor: pointer; }
.brush .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.brush.on { border-color: var(--text); box-shadow: 0 0 0 1px var(--text) inset; }
.brush.corso::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: repeating-linear-gradient(45deg, #777 0 3px, #ccc 3px 6px); }
.brush.erase::before { content: "⌫"; }

.gridwrap { overflow-x: auto; padding: 0 16px 8px; -webkit-overflow-scrolling: touch; }
.gblock { margin-bottom: 14px; }
.gblock.today table.grid thead th.name { color: var(--brand); }
table.grid { border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; user-select: none; -webkit-user-select: none; }
table.grid th, table.grid td { padding: 0; height: 28px; font-size: 12px; }
table.grid thead th { background: #fff7b8; color: #3a3500; font-weight: 700; border-bottom: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { table.grid thead th { background: #3a3714; color: #f3eaa0; } }
table.grid thead th.hh { text-align: left; padding-left: 3px; border-left: 1px solid var(--line); }
table.grid .name { position: sticky; left: 0; z-index: 2; background: var(--card); min-width: 132px; max-width: 132px; text-align: left; padding: 0 8px; border-right: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.grid thead th.name { background: #fff7b8; font-size: 13px; }
@media (prefers-color-scheme: dark) { table.grid thead th.name { background: #3a3714; } }
.namebtn { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 600; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; text-align: left; color: var(--text); }
.namebtn:hover { text-decoration: underline; }
table.grid td.c { width: var(--cell); min-width: var(--cell); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; }
table.grid td.c.half { border-left-style: dotted; }
table.grid td.c.on { background: var(--c); }
table.grid td.c.corso { background: repeating-linear-gradient(45deg, #8a8a8a 0 4px, #cfcfcf 4px 8px); }
#gridwrap.paint-on td.c { touch-action: none; cursor: crosshair; }
table.grid td.codecell { text-align: center; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; cursor: pointer; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); }
.code-ferie { background: #dbeafe; color: #1e3a8a; }
.code-recupero { background: #ede9fe; color: #4c1d95; }
.code-assente { background: #f3f4f6; color: #374151; }
.code-libero { background: #f0fdf4; color: #166534; }
.code-corso { background: repeating-linear-gradient(45deg, #e5e5e5 0 6px, #f5f5f5 6px 12px); color: #333; }
table.grid td.tot, table.grid th.tot { min-width: 44px; text-align: center; font-weight: 700; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
table.grid tfoot th, table.grid tfoot td { background: var(--bg); font-weight: 700; color: var(--muted); text-align: center; font-size: 11px; }
table.grid tfoot th.name { text-align: left; font-size: 12px; }
table.grid tr.cov td.n0 { background: var(--bad-soft); }
table.grid tr.cov td.n1 { background: var(--warn-soft); color: var(--warn); }
.summary { margin: 0 16px 16px; max-width: 900px; }
table.simple { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
table.simple tr.warnrow td:last-child { color: var(--warn); font-weight: 600; }

.log { max-height: 420px; overflow: auto; }
.logrow { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

/* ------------------------------------------------------------ stampa */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 14mm; }
  body.printing #app, body.printing nav, body.printing #toast, body.printing .overlay { display: none !important; }
  body.printing #print-root { display: block; }
  body { background: #fff !important; color: #000 !important; }
  .page { page-break-after: always; break-after: page; font-size: 13pt; }
  .page:last-child { page-break-after: auto; break-after: auto; }
  .p-head { display: flex; justify-content: space-between; font-size: 11pt; border-bottom: 2px solid #000; padding-bottom: 4mm; margin-bottom: 6mm; }
  .page h1 { font-size: 24pt; margin-bottom: 4mm; }
  .p-head { align-items: center; }
  .p-logo { height: 12mm; width: auto; }
  .p-draft { border: 2px solid #000; display: inline-block; padding: 1mm 3mm; font-weight: 700; margin-bottom: 4mm; }
  .page table { width: 100%; border-collapse: collapse; }
  .page th, .page td { border: 1px solid #000; padding: 3mm; text-align: left; vertical-align: top; }
  .page thead th { background: #eee; }
  .page tfoot td { font-weight: 700; }
  .page td:last-child, .page th:last-child { width: 18mm; text-align: center; }
  .page td:first-child { width: 42mm; }
  .p-foot { margin-top: 6mm; font-size: 9pt; color: #444; }
}

/* menu reparto e celle di altri reparti */
label.inline { display: inline; margin: 0; font-size: 15px; }
select.reparto { font-weight: 700; font-size: 16px; min-width: 210px; }
.dot.big { display: inline-block; width: 18px; height: 18px; border-radius: 50%; }
table.grid td.c.on.lock { background: repeating-linear-gradient(135deg, #c9d0cd 0 5px, #dde2e0 5px 10px); cursor: not-allowed; }
@media (prefers-color-scheme: dark) { table.grid td.c.on.lock { background: repeating-linear-gradient(135deg, #3a423f 0 5px, #2c3330 5px 10px); } }
#gridwrap.paint-on td.c.locked { cursor: not-allowed; }
table.grid td.week, table.grid th.week { min-width: 58px; background: var(--bg); }
table.grid td.week.over { color: var(--warn); background: var(--warn-soft); }
[hidden] { display: none !important; }

/* logo del negozio */
.brandlogo { display: block; height: 46px; width: auto; max-width: 70%; object-fit: contain; margin: 12px 16px 0; }
.grid-top .brandlogo { margin: 0 0 8px; }
.storelogo { display: block; max-width: 280px; max-height: 90px; object-fit: contain; margin-bottom: 18px; }
.logobox { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-height: 60px; display: flex; align-items: center; margin-bottom: 8px; }
.logobox img { max-height: 60px; max-width: 100%; }


/* allegati */
.atts { margin-top: 10px; display: grid; gap: 6px; }
.att { display: flex; align-items: center; gap: 4px; }
.attlink { flex: 1; display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); min-width: 0; }
.attlink:hover { border-color: var(--brand); }
.attlink .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attico { flex: none; font: 700 10px/1 Inter, system-ui, sans-serif; color: #fff; background: #6b7280; border-radius: 6px; padding: 6px 5px; min-width: 36px; text-align: center; }
.attico.ext-pdf { background: #b42318; }
.attico.ext-doc, .attico.ext-docx, .attico.ext-odt { background: #1d4ed8; }
.attico.ext-xls, .attico.ext-xlsx, .attico.ext-ods { background: #15803d; }
.attico.ext-jpg, .attico.ext-jpeg, .attico.ext-png { background: #7a4fb3; }
@media print { .brandlogo { display: none; } }

/* condivisione link */
.qrbox { display: flex; justify-content: center; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 8px 0; min-height: 120px; }
.qrbox img { width: 200px; height: 200px; image-rendering: pixelated; }
.sharelink { word-break: break-all; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.sharelink .linkbtn { display: inline; margin-left: 8px; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* informativa privacy */
.privacy-doc h2 { font-size: 20px; margin-bottom: 2px; }
.privacy-doc h3 { font-size: 16px; margin: 16px 0 4px; }
.privacy-doc p, .privacy-doc li { font-size: 15px; line-height: 1.5; margin: 4px 0; }
.privacy-doc ul { padding-left: 20px; margin: 4px 0; }
.privacy-gate { padding-top: 6vh; max-width: 640px; }
.privacy-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; max-height: 52vh; overflow: auto; margin: 14px 0 6px; }
.sheet.wide { max-width: 720px; }
.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--warn-soft); color: var(--warn); padding: 10px 16px; font-size: 14px; font-weight: 600; }
@media print { .privacy-print { font-size: 11pt; } .privacy-print h2 { font-size: 16pt; } .privacy-print h3 { font-size: 12pt; margin: 4mm 0 1mm; } }
.privacy-gate .storelogo { max-height: 56px; }
.iconpreview { width: 56px; height: 56px; border-radius: 14px; border: 1px solid var(--line); background: #fff; object-fit: cover; }
