:root {
  --bg: #f4f5f1; --surface: #ffffff; --ink: #1f2f28; --muted: #64726a; --line: #dde2d9; --line-strong: #c5cdc1;
  --side: #1c3028; --side-ink: #dfe8dc; --side-muted: #9fb0a4; --side-active: #2c4a3c;
  --brand: #3f6a52; --brand-dark: #2d5340; --brand-soft: #e5eee7;
  --rust: #b66f50; --danger: #a8402f; --ok: #2f7a4f; --warn-bg: #fff4dd; --warn-ink: #7a5310;
  --c-visitors: #2d6cb5; --c-views: #c26d1a;
  --sans: "DM Sans", system-ui, sans-serif; --serif: "Playfair Display", Georgia, serif;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 15px/1.55 var(--sans); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #7fb094; outline-offset: 2px; }
.boot { padding: 40px; color: var(--muted); }
h1, h2, h3, p { margin-top: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Pulsanti ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: 14px; transition: background .15s, border-color .15s; }
.btn:hover { background: #f1f4ef; }
a.btn { text-decoration: none; color: var(--ink); }
a.btn.primary { color: #fff; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #e2bdb5; }
.btn.danger:hover { background: #fbeeeb; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eceee8; color: var(--ink); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--muted); }
.icon-btn:hover:not([disabled]) { background: #eceee8; color: var(--ink); }
.icon-btn[disabled] { opacity: .3; cursor: default; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.login-art { background: var(--side) url("../assets/meditation-sunset-mudra.jpg") center/cover; position: relative; }
.login-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(28,48,40,.2), rgba(28,48,40,.85)); }
.login-art p { position: absolute; z-index: 1; left: 48px; right: 48px; bottom: 48px; margin: 0; color: #fff; font: 500 34px/1.2 var(--serif); letter-spacing: -.5px; }
.login-box { display: grid; place-content: center; padding: 40px 24px; }
.login-form { width: min(380px, 100%); }
.login-form h1 { font: 500 30px/1.2 var(--serif); margin-bottom: 6px; }
.login-form .lead { color: var(--muted); margin-bottom: 28px; }
.field { margin-bottom: 16px; }
.field label, .lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.help { display: block; color: var(--muted); font-size: 13px; margin-top: 5px; line-height: 1.45; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=time], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; }
textarea { resize: vertical; line-height: 1.55; min-height: 90px; }
input:hover, select:hover, textarea:hover { border-color: #9fb0a4; }
.pw { position: relative; }
.pw button { position: absolute; right: 4px; top: 4px; height: 36px; padding: 0 10px; border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.pw input { padding-right: 78px; }
.msg-error { background: #fbeeeb; color: var(--danger); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 14px; }

/* ---------- Struttura ---------- */
.shell { display: grid; grid-template-columns: 276px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 22px 14px 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.side-brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 22px; }
.side-brand .mark { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.12); display: grid; place-items: center; font-size: 20px; }
.side-brand strong { display: block; font: 500 19px/1.1 var(--serif); color: #fff; }
.side-brand small { color: var(--side-muted); font-size: 12px; }
.nav-group { margin: 14px 0 4px; padding: 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .6px; color: var(--side-muted); }
.nav button { width: 100%; display: flex; align-items: center; gap: 11px; padding: 10px 10px; border: 0; background: none; color: var(--side-ink); border-radius: 8px; text-align: left; font-size: 14.5px; }
.nav button:hover { background: rgba(255,255,255,.07); }
.nav button[aria-current=page] { background: var(--side-active); color: #fff; font-weight: 600; }
.nav .dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: #e0a458; }
.side-foot { margin-top: auto; padding: 18px 10px 0; font-size: 13px; color: var(--side-muted); }
.side-foot a, .side-foot button { color: var(--side-ink); background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.side-foot .row { display: flex; gap: 16px; margin-top: 8px; }
.main { min-width: 0; padding: 30px clamp(18px, 4vw, 48px) 120px; }
.main-inner { max-width: 880px; margin: 0 auto; }
.main-inner.wide { max-width: 1060px; }
.topbar-m { display: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font: 500 30px/1.2 var(--serif); margin-bottom: 4px; letter-spacing: -.4px; }
.page-head p { color: var(--muted); margin: 0; max-width: 560px; }

.banner { display: flex; gap: 12px; align-items: flex-start; background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 13px 16px; margin-bottom: 18px; font-size: 14px; }
.banner button { margin-left: auto; flex: none; }
.banner strong { display: block; }

/* ---------- Campi ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 14px; }
.divider { margin: 30px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line-strong); font-weight: 700; font-size: 15px; }
.panel .divider:first-child { margin-top: 0; }
.tb { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.tb .lbl { margin: 0; }
.chip { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line-strong); background: #fff; }
.chip:hover { background: #f1f4ef; }
.chip em { font-family: var(--serif); color: var(--rust); font-weight: 500; }
.preview { margin-top: 8px; padding: 12px 14px; background: #f4f5f1; border-radius: 8px; font: 500 21px/1.3 var(--serif); }
.preview em { color: var(--rust); }
.preview small { display: block; font: 500 11px var(--sans); letter-spacing: .3px; color: var(--muted); margin-bottom: 4px; }

.img-field { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 16px; align-items: start; }
.img-drop { position: relative; aspect-ratio: 4/3; border-radius: 8px; background: #e9ece6 center/cover no-repeat; border: 1px solid var(--line); overflow: hidden; }
.img-drop.over { outline: 3px dashed var(--brand); }
.img-drop .busy { position: absolute; inset: 0; display: none; place-items: center; background: rgba(255,255,255,.8); font-size: 13px; font-weight: 600; }
.img-drop.loading .busy { display: grid; }
.img-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.img-note { grid-column: 2; }

/* Liste */
.list { margin: 4px 0 0; display: grid; gap: 10px; }
.item { border: 1px solid var(--line-strong); border-radius: 10px; background: #fcfdfb; }
.item > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; cursor: pointer; min-height: 52px; }
.item > summary::-webkit-details-marker { display: none; }
.item > summary .chev { transition: transform .15s; color: var(--muted); }
.item[open] > summary .chev { transform: rotate(90deg); }
.item > summary .ttl { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item > summary .ttl small { font-weight: 500; color: var(--muted); margin-right: 6px; }
.item > summary .thumb { width: 44px; height: 34px; border-radius: 5px; background: #e9ece6 center/cover; flex: none; }
.item-body { padding: 6px 16px 16px; border-top: 1px solid var(--line); }
.item-body .field:first-child { margin-top: 12px; }
.row-inline { display: grid; grid-template-columns: 90px minmax(0, 1fr) 120px auto; gap: 8px; align-items: center; padding: 8px 8px 8px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: #fcfdfb; }
.row-inline .ctl { display: flex; }
.row-head { display: grid; grid-template-columns: 90px minmax(0, 1fr) 120px 112px; gap: 8px; padding: 0 8px 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.add { margin-top: 10px; }
.empty-list { padding: 18px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 10px; }

/* Barra di salvataggio */
.savebar { position: fixed; left: 276px; right: 0; bottom: 0; z-index: 30; display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px 20px; background: #fff; border-top: 1px solid var(--line-strong); box-shadow: 0 -8px 24px rgba(31,47,40,.08); transform: translateY(110%); transition: transform .2s; }
.savebar.show { transform: none; }
.savebar span { font-weight: 600; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600; transition: .25s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }
dialog { border: 0; border-radius: 14px; padding: 24px; width: min(420px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(20,32,26,.5); }
dialog h3 { font: 500 22px var(--serif); margin-bottom: 8px; }
dialog .acts { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.section-foot { margin-top: 26px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 13px; }

/* ---------- Panoramica e statistiche ---------- */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 8px 14px; font-size: 14px; font-weight: 500; min-height: 40px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: var(--brand); color: #fff; font-weight: 600; }
.seg button:hover:not([aria-pressed=true]) { background: #f1f4ef; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 18px 0 14px; }
.kpi { padding: 20px 24px; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi .k { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .v { font: 500 40px/1.1 var(--serif); letter-spacing: -1px; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 13px; color: var(--muted); }
.kpi .d b { font-weight: 700; }
.kpi .d .up { color: var(--ok); } .kpi .d .down { color: var(--danger); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.card h2 { font: 700 16px/1.3 var(--sans); margin-bottom: 2px; }
.card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.legend { display: flex; gap: 18px; font-size: 13.5px; margin: 6px 0 2px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font: 12px var(--sans); fill: var(--muted); }
.chart .grid { stroke: #e8ebe5; stroke-width: 1; }
.chart .endlbl { fill: var(--ink); font-weight: 600; }
.tip { position: absolute; pointer-events: none; z-index: 5; background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 11px; font-size: 13px; box-shadow: 0 6px 20px rgba(31,47,40,.14); white-space: nowrap; display: none; }
.tip b { display: block; margin-bottom: 3px; }
.tip span { display: flex; gap: 7px; align-items: center; }
.tip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.t th { text-align: left; font-weight: 600; font-size: 13px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--line-strong); }
table.t th.n, table.t td.n { text-align: right; }
table.t td { padding: 8px 0; border-bottom: 1px solid var(--line); }
table.t tr:last-child td { border-bottom: 0; }
.bars { display: grid; gap: 11px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar-row .top span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .top span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.bar-row .top b { color: var(--ink); font-weight: 700; }
.bar-row .track { height: 8px; border-radius: 4px; background: #edf0ea; margin-top: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 4px; background: var(--c-visitors); min-width: 3px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 20px; background: var(--brand-soft); color: var(--brand-dark); margin-left: 6px; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.todo { display: grid; gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }
.todo li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; font-size: 14px; }
.todo li button { margin-left: auto; }
.link-view { color: var(--brand-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.mini-link { background: none; border: 0; padding: 0; color: var(--brand-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; font-size: 13.5px; }
.backup-list { display: grid; gap: 8px; }
.backup-list > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: fixed; z-index: 60; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(20,32,26,.5); }
  .topbar-m { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; background: var(--side); color: #fff; padding: 10px 14px; }
  .topbar-m button { background: rgba(255,255,255,.1); color: #fff; border: 0; border-radius: 8px; height: 40px; padding: 0 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
  .topbar-m strong { font: 500 17px var(--serif); }
  .savebar { left: 0; }
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; }
  .kpi { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px 20px; }
  .kpi:last-child { border-bottom: 0; }
  .img-field { grid-template-columns: 1fr; }
  .img-note { grid-column: 1; }
  .img-drop { max-width: 260px; }
  .row-head { display: none; }
  .row-inline { grid-template-columns: 1fr 1fr; }
  .row-inline .ctl { grid-column: 1 / -1; justify-content: flex-end; }
  .panel { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Collegamenti */
.status { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-weight: 600; font-size: 14px; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: #e0a458; flex: none; }
.status.ok::before { background: var(--ok); }
.adv { margin-top: 6px; }
.adv summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
