:root {
  --bg: #f5f7fa; --panel: #ffffff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb; --line2: #d1d5db;
  --brand: #0f766e; --brand-d: #115e59; --brand-l: #ccfbf1;
  --ok: #15803d; --ok-l: #dcfce7; --warn: #b45309; --warn-l: #fef3c7; --err: #b91c1c; --err-l: #fee2e2; --info: #1d4ed8; --info-l: #dbeafe;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 6px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-size: 15px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-d); }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: .8rem 0 .4rem; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }
code { background: #f3f4f6; padding: 0 4px; border-radius: 4px; }

/* layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: #0f2f2c; color: #d1fae5; padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { font-weight: 700; color: #fff; font-size: 1.05rem; padding: 4px 10px 14px; line-height: 1.25; }
.sidebar .logo small { color: #99f6e4; display: block; font-weight: 400; font-size: .8rem; }
.sidebar a { display: flex; gap: 10px; align-items: center; color: #d1fae5; text-decoration: none; padding: 8px 10px; border-radius: 6px; margin: 1px 0; font-size: .95rem; }
.sidebar a:hover { background: rgba(255,255,255,.08); }
.sidebar a.active { background: var(--brand); color: #fff; }
.sidebar .sep { border-top: 1px solid rgba(255,255,255,.12); margin: 10px 4px; }
.sidebar .badge { margin-left: auto; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 18px 20px 40px; max-width: 1500px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head .grow { flex: 1; min-width: 240px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* componenti */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.stat { font-size: 1.8rem; font-weight: 700; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: #fff; color: var(--text); padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; font-size: .92rem; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--err); border-color: #fca5a5; }
.btn.danger:hover { background: var(--err-l); }
.btn.ok { color: var(--ok); border-color: #86efac; }
.btn.small { padding: 3px 8px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e5e7eb; color: #374151; }
.badge.err { background: var(--err-l); color: var(--err); } .badge.ok { background: var(--ok-l); color: var(--ok); }
.badge.warn { background: var(--warn-l); color: var(--warn); } .badge.info { background: var(--info-l); color: var(--info); }
.alert { padding: 10px 12px; border-radius: 6px; margin: 8px 0; border: 1px solid; font-size: .93rem; }
.alert.err { background: var(--err-l); border-color: #fca5a5; color: #7f1d1d; }
.alert.warn { background: var(--warn-l); border-color: #fcd34d; color: #78350f; }
.alert.ok { background: var(--ok-l); border-color: #86efac; color: #14532d; }
.alert.info { background: var(--info-l); border-color: #93c5fd; color: #1e3a8a; }
.alert ul { margin: 4px 0 0; padding-left: 20px; }
.help { background: #f0fdfa; border: 1px solid #99f6e4; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: .92rem; }
.help summary { cursor: pointer; font-weight: 600; color: var(--brand-d); }
.help ol, .help ul { margin: 6px 0; padding-left: 22px; }

/* tabelle */
table.t { width: 100%; border-collapse: collapse; background: #fff; font-size: .92rem; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.t th { background: #f9fafb; font-weight: 600; color: #374151; position: sticky; top: 0; }
table.t tr:hover td { background: #fafafa; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.neg { color: var(--err); font-weight: 600; } .pos { color: var(--ok); font-weight: 600; }

/* form */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .88rem; }
.field .hint { font-size: .8rem; color: var(--muted); }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line2); border-radius: 6px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #5eead4; border-color: var(--brand); }
input[type=checkbox] { width: 18px; height: 18px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
textarea { min-height: 60px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* codici turno */
.code { display: inline-block; min-width: 30px; text-align: center; padding: 2px 6px; border-radius: 5px; font-weight: 700; font-size: .8rem; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.palette button { border: 2px solid transparent; border-radius: 6px; padding: 6px 10px; font-weight: 700; cursor: pointer; font-size: .85rem; }
.palette button.sel { border-color: #111827; box-shadow: 0 0 0 2px #fff inset; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--muted); align-items: center; }

/* griglia mese */
.grid-wrap { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: .8rem; }
table.grid th, table.grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; text-align: center; height: 28px; min-width: 36px; }
table.grid thead th { position: sticky; top: 0; background: #f9fafb; z-index: 3; font-weight: 600; padding: 3px 2px; cursor: pointer; line-height: 1.15; }
table.grid thead th.fes { background: #fde2e2; color: #991b1b; }
table.grid thead th.today { box-shadow: inset 0 -3px 0 var(--brand); }
table.grid thead th .st { display: block; height: 5px; border-radius: 3px; margin: 2px 3px 0; }
table.grid th.name, table.grid td.name { position: sticky; left: 0; background: #fff; z-index: 2; text-align: left; padding: 0 8px; min-width: 190px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; cursor: pointer; }
table.grid thead th.name { z-index: 4; background: #f9fafb; cursor: default; }
table.grid td.c { cursor: pointer; font-weight: 700; position: relative; }
table.grid td.c:hover { outline: 2px solid #111827; outline-offset: -2px; z-index: 1; }
table.grid td.c.var::after { content: ''; position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; background: #1d4ed8; }
table.grid td.c.req::after { content: ''; position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; background: #ea580c; }
table.grid td.c.al { box-shadow: inset 0 0 0 2px #dc2626; }
table.grid td.c.note::before { content: ''; position: absolute; bottom: 0; right: 0; border-left: 6px solid transparent; border-bottom: 6px solid #6b7280; }
table.grid tr:hover td.name { background: #f0fdfa; }
table.grid tfoot td { position: sticky; bottom: 0; background: #f9fafb; font-weight: 600; font-size: .75rem; }
table.grid tfoot tr:nth-child(2) td { bottom: 0; }
table.grid td.short { background: #fecaca !important; color: #7f1d1d; }
table.grid td.over { background: #dbeafe !important; color: #1e3a8a; }
table.grid td.fes-col { background-image: linear-gradient(rgba(220,38,38,.04), rgba(220,38,38,.04)); }
table.grid .sep-row td { height: 6px; background: #f3f4f6; }

/* modale e cassetto */
.overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 720px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 1000px; }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; flex: 1; font-size: 1.1rem; }
.modal .body { padding: 16px 18px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); background: #f9fafb; border-radius: 0 0 10px 10px; flex-wrap: wrap; }
.x { border: none; background: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); line-height: 1; }
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; font-size: .92rem; }
.toast.err { background: #991b1b; } .toast.ok { background: #166534; }

/* copertura giorno */
.cov { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cov .box { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-align: center; }
.cov .box.short { background: var(--err-l); border-color: #fca5a5; }
.cov .box.okk { background: var(--ok-l); border-color: #86efac; }
.cov .box b { font-size: 1.4rem; display: block; }
.prop { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.prop:last-child { border-bottom: none; }
.prop .who { min-width: 180px; font-weight: 600; }
.prop .what { flex: 1; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: .75rem; font-weight: 700; }
.pill.p1 { background: #dcfce7; color: #166534; } .pill.p2 { background: #e0f2fe; color: #075985; } .pill.p3 { background: #fef3c7; color: #92400e; }
.daylist { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow: auto; }
.daylist button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 9px; cursor: pointer; font: inherit; font-size: .88rem; }
.daylist button.sel { border-color: var(--brand); background: #f0fdfa; }
.split { display: grid; grid-template-columns: 290px 1fr; gap: 14px; align-items: start; }
.seq { display: flex; flex-wrap: wrap; gap: 4px; }
.seq .d { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.seq .d small { font-size: .7rem; }
.seq select { padding: 4px 2px; font-weight: 700; font-size: .8rem; width: 72px; }

/* login */
.login { max-width: 400px; margin: 10vh auto; }
.login .card { padding: 26px; }
.login h1 { text-align: center; }

/* stampa */
.print-only { display: none; }
.print-area { background: #fff; padding: 10px; }
.print-area h1 { font-size: 1.2rem; }
.pg { page-break-after: always; break-after: page; }
.pg:last-child { page-break-after: auto; break-after: auto; }
table.pgrid { border-collapse: collapse; width: 100%; font-size: 8.5pt; }
table.pgrid th, table.pgrid td { border: 1px solid #9ca3af; padding: 2px 1px; text-align: center; }
table.pgrid td.name, table.pgrid th.name { text-align: left; padding: 2px 4px; white-space: nowrap; }
table.pgrid th.fes { background: #fde2e2; }
table.ptable { border-collapse: collapse; width: 100%; font-size: 10pt; }
table.ptable th, table.ptable td { border: 1px solid #9ca3af; padding: 4px 6px; text-align: left; vertical-align: top; }
table.ptable th { background: #f3f4f6; }
.cal7 { display: grid; grid-template-columns: repeat(7, 1fr); border-left: 1px solid #9ca3af; border-top: 1px solid #9ca3af; }
.cal7 > div { border-right: 1px solid #9ca3af; border-bottom: 1px solid #9ca3af; min-height: 62px; padding: 3px 5px; font-size: 10pt; }
.cal7 .h { min-height: 0; font-weight: 700; background: #f3f4f6; text-align: center; }
.cal7 .num { font-size: 9pt; color: #6b7280; }
.cal7 .fes .num { color: #b91c1c; font-weight: 700; }
.cal7 .big { font-size: 15pt; font-weight: 800; text-align: center; margin-top: 4px; border-radius: 4px; }

@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; font-size: 10pt; }
  .sidebar, .topbar, .no-print, .help, .toasts { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; max-width: none; }
  .print-only { display: block; }
  .card { box-shadow: none; border: none; padding: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-area { padding: 0; }
}
body.portrait-print { }
@media print { body.portrait-print { } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 240px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .split { grid-template-columns: 1fr; }
  .content { padding: 12px; }
}
