/* Stile ispirato a iOS: titoli grandi, liste raggruppate, vetro, fogli dal basso. */
:root {
  --bg: #f2f2f7; --card: #ffffff; --label: #000000; --secondary: rgba(60,60,67,.62);
  --sep: rgba(60,60,67,.16); --fill: rgba(120,120,128,.16);
  --blue: #007aff; --green: #34c759; --red: #ff3b30; --orange: #ff9500;
  --glass: rgba(255,255,255,.72);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1c1c1e; --label: #ffffff; --secondary: rgba(235,235,245,.6);
    --sep: rgba(84,84,88,.6); --fill: rgba(120,120,128,.36);
    --blue: #0a84ff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a;
    --glass: rgba(44,44,46,.72);
  }
}
:root[data-theme="dark"] {
    --bg: #000000; --card: #1c1c1e; --label: #ffffff; --secondary: rgba(235,235,245,.6);
    --sep: rgba(84,84,88,.6); --fill: rgba(120,120,128,.36);
    --blue: #0a84ff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a;
    --glass: rgba(44,44,46,.72);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--label); font: 17px/1.3 var(--font); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* Pagina */
.page { max-width: 680px; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 16px 130px; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; margin: 26px 4px 14px; gap: 12px; }
h1 { font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: .2px; margin: 0; }
.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .02em; color: var(--secondary); font-weight: 400; margin: 24px 16px 7px; }
.foot { font-size: 13px; color: var(--secondary); margin: 7px 16px 0; }
.pill { display: inline-block; background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange);
  font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 999px; margin: 6px 4px 0; }

/* Liste raggruppate */
.list { background: var(--card); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 16px; position: relative; width: 100%;
  background: none; border: 0; text-align: left; cursor: default; }
.row + .row::before, .row + .row-link::before, .row-link + .row::before, .row-link + .row-link::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.row-link { cursor: pointer; }
.row-link:active { background: var(--fill); }
.row .grow { flex: 1; min-width: 0; }
.row .t { display: block; }
.row .s { display: block; font-size: 14px; color: var(--secondary); margin-top: 1px; }
.row .v { color: var(--secondary); text-align: right; white-space: nowrap; }
.row .chev { width: 8px; height: 13px; flex: none; stroke: var(--secondary); opacity: .6; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row.blue { color: var(--blue); }
.row.red { color: var(--red); }
.row.center { justify-content: center; }
.row input:not([type=checkbox]) { flex: 1; min-width: 0; border: 0; background: none; outline: 0; text-align: right; color: var(--label); padding: 0; }
.row input::placeholder { color: color-mix(in srgb, var(--secondary) 70%, transparent); }
.row input[readonly] { color: var(--secondary); }
.row select { appearance: none; -webkit-appearance: none; border: 0; background: none; outline: 0; color: var(--blue); text-align: right; text-align-last: right; flex: 1; min-width: 0; padding: 0; cursor: pointer; }
.row input[type=time] { color: var(--blue); }
.row input[type=time]::-webkit-calendar-picker-indicator { display: none; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--secondary); display: inline-block; flex: none; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); } .dot.warn { background: var(--orange); }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--blue); color: #fff; font-weight: 600; font-size: 15px; }
.avatar.gray { background: var(--fill); color: var(--secondary); }
.avatar.green { background: var(--green); } .avatar.orange { background: var(--orange); } .avatar.red { background: var(--red); }
.empty { text-align: center; color: var(--secondary); padding: 28px 16px; }

/* Riquadri di stato */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--card); border-radius: 14px; padding: 14px 16px; }
.tile b { display: block; font-size: 28px; font-weight: 700; line-height: 1.15; }
.tile span { font-size: 14px; color: var(--secondary); }
.tile .st { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 700; }

/* Interruttore */
input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 31px; background: var(--fill);
  position: relative; flex: none; transition: background .2s; cursor: pointer; margin: 0; }
input[type=checkbox]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,.25); transition: transform .2s; }
input[type=checkbox]:checked { background: var(--green); }
input[type=checkbox]:checked::after { transform: translateX(20px); }

/* Pulsanti */
.btn { display: block; width: 100%; background: var(--blue); color: #fff; border: 0; border-radius: 14px; padding: 15px; font-weight: 600; cursor: pointer; margin-top: 16px; }
.btn:active { opacity: .8; }
.btn.plain { background: var(--card); color: var(--blue); }
.round { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--blue); color: #fff; font-size: 24px; line-height: 1; cursor: pointer; flex: none; margin-bottom: 4px; }
.round:active { opacity: .8; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 4px 2px; }
.link.bold { font-weight: 600; }
.error { color: var(--red); font-size: 14px; margin: 10px 16px 0; min-height: 0; }
.error:empty { display: none; }

/* Barra delle schede in vetro */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 10;
  display: flex; gap: 2px; padding: 6px; border-radius: 34px; background: var(--glass);
  -webkit-backdrop-filter: blur(26px) saturate(190%); backdrop-filter: blur(26px) saturate(190%);
  border: .5px solid var(--sep); box-shadow: 0 10px 34px rgba(0,0,0,.18); width: min(440px, calc(100% - 24px)); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px; border-radius: 28px;
  color: var(--secondary); text-decoration: none; font-size: 10.5px; font-weight: 500; }
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--blue); background: var(--fill); }

/* Fogli (sheet) */
dialog { border: 0; padding: 0; background: var(--bg); color: var(--label); width: min(560px, 100%); max-height: 92vh; overflow: auto;
  margin: auto auto 0; border-radius: 28px 28px 0 0; box-shadow: 0 -10px 50px rgba(0,0,0,.3); }
dialog[open] { animation: up .32s cubic-bezier(.2,.9,.3,1); }
dialog::backdrop { background: rgba(0,0,0,.38); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
@media (min-width: 700px) { dialog { margin: auto; border-radius: 28px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-bar { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 10px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.sheet-bar strong { font-size: 17px; }
.sheet-body { padding: 4px 16px 26px; }
.sheet-body .sec:first-child { margin-top: 8px; }
dialog.alert { width: min(300px, 86vw); margin: auto; border-radius: 20px; background: var(--card); text-align: center; padding: 22px 0 0; }
dialog.alert p { margin: 0 20px 18px; }
.alert-actions { display: grid; grid-template-columns: 1fr 1fr; border-top: .5px solid var(--sep); }
.alert-actions button { background: none; border: 0; padding: 14px; font-size: 17px; color: var(--blue); cursor: pointer; }
.alert-actions button + button { border-left: .5px solid var(--sep); font-weight: 600; color: var(--red); }
pre { background: var(--card); border-radius: 14px; padding: 14px; overflow: auto; font-size: 12px; line-height: 1.5; margin: 0; }

.toast { position: fixed; left: 50%; bottom: 104px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; z-index: 30;
  background: var(--glass); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border: .5px solid var(--sep);
  padding: 11px 20px; border-radius: 999px; font-size: 15px; transition: .22s; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { color: var(--red); }

/* Accesso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(380px, 100%); text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; background: #fff; padding: 5px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.login-box h1 { font-size: 30px; margin-top: 12px; }
.login-sub { color: var(--secondary); margin: 2px 0 24px; }
.login-box .row span { width: 90px; text-align: left; flex: none; }
.login-box .row input { text-align: left; }
.login-box .error { text-align: left; }

/* Navigazione a livelli e organigramma */
.back { display: inline-block; color: var(--blue); text-decoration: none; margin: 16px 4px 0; font-size: 17px; }
.back + .title-row { margin-top: 6px; }
.ico { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; color: #fff; }
.ico svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ico.blue { background: var(--blue); } .ico.green { background: var(--green); } .ico.orange { background: var(--orange); } .ico.purple { background: #af52de; }
.org, .org ul { list-style: none; margin: 0; padding: 0; }
.org ul { padding-left: 24px; position: relative; }
.org ul::before { content: ""; position: absolute; left: 11px; top: 0; bottom: 30px; border-left: 1.5px solid var(--sep); }
.org li { position: relative; padding-top: 10px; }
.org ul > li::before { content: ""; position: absolute; left: -13px; top: 34px; width: 13px; border-top: 1.5px solid var(--sep); }
.org .row { border-radius: 14px; background: var(--card); }
.prio { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.prio.p1 { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.prio.p2 { background: color-mix(in srgb, var(--blue) 16%, transparent); color: var(--blue); }
.prio.p3 { background: var(--fill); color: var(--secondary); }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 4px 0; }

/* Personalizzazione */
.ico.teal { background: #30b0c7; } .ico.pink { background: #ff2d55; }
.seg { display: flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 8px; font-size: 14px; cursor: pointer; color: var(--label); }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.25); font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 8px; padding: 16px 8px; }
.sw { display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; font-size: 12px; color: var(--secondary); cursor: pointer; }
.sw i { width: 42px; height: 42px; border-radius: 50%; display: block; border: 3px solid var(--card); box-shadow: 0 0 0 2px transparent; }
.sw.on { color: var(--label); }
.sw.on i { box-shadow: 0 0 0 2px var(--label); }
.logo-prev { width: 56px; height: 56px; border-radius: 12px; background: #fff; padding: 3px; object-fit: contain; flex: none; }
audio { width: 100%; height: 38px; }
.row audio { flex: 1; }

.ico.indigo { background: #5856d6; }
.row.area { flex-direction: column; align-items: stretch; gap: 4px; padding: 12px 16px; }
.row.area textarea { width: 100%; min-height: 92px; border: 0; outline: 0; background: transparent; color: var(--label); font: inherit; resize: vertical; padding: 0; }
.row.area textarea::placeholder { color: color-mix(in srgb, var(--secondary) 70%, transparent); }
