:root {
  --bg: #f4f6f8; --card: #fff; --text: #1b2430; --muted: #66727f; --line: #e2e7ec;
  --accent: #0f6cbd; --accent-text: #fff; --warn-bg: #fff4d6; --warn-text: #6b4b00; --danger: #b3261e;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --card: #1a222b; --text: #e8edf2; --muted: #93a0ad; --line: #2b3640; --accent: #4aa3f0; --accent-text: #08131d; --warn-bg: #3a2f10; --warn-text: #ffd978; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding-bottom: env(safe-area-inset-bottom); }
h2 { margin: 0 0 4px; font-size: 22px; } h3 { margin: 0 0 12px; } h4 { margin: 0 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); } .small { font-size: 13px; } .pad { padding: 12px 16px; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; color: var(--text); margin-left: 4px; }
.spacer { flex: 1; }
.iconbtn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; font-size: 24px; color: var(--accent); border-radius: 10px; cursor: pointer; }
.iconbtn:hover { background: var(--bg); }
.back { display: none; }
.demo { background: var(--warn-bg); color: var(--warn-text); padding: 8px 16px; font-size: 14px; }

.cols { display: grid; grid-template-columns: 340px 1fr; gap: 0; max-width: 1280px; margin: 0 auto; align-items: start; }
#list { border-right: 1px solid var(--line); min-height: calc(100vh - 62px); background: var(--card); position: sticky; top: 62px; max-height: calc(100vh - 62px); overflow: auto; }
#detail { padding: 16px; min-width: 0; }
.searchrow { display: flex; gap: 8px; padding: 12px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.searchrow input { flex: 1; min-width: 0; }
.banner { display: block; margin: 0 12px 8px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-weight: 600; }
.pitem { display: block; padding: 12px 16px; color: var(--text); border-bottom: 1px solid var(--line); min-height: 56px; }
.pitem:hover, .pitem.active { background: var(--bg); }
.pitem.active { box-shadow: inset 3px 0 var(--accent); }
.pname { font-weight: 600; } .pmeta { font-size: 13px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.inner { background: var(--bg); box-shadow: none; margin-top: 12px; }
.card.subtle { background: transparent; border-style: dashed; }
.homecard { text-align: center; padding: 40px 16px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 15px; color: var(--text); }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
input[type=checkbox] { width: 20px; height: 20px; margin: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; font: inherit; font-weight: 600; color: var(--accent); background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btnrow { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; justify-content: flex-end; }
.btnrow.wrap { justify-content: flex-start; }

.files { list-style: none; margin: 0; padding: 0; }
.files li { border-top: 1px solid var(--line); } .files li:first-child { border-top: 0; }
.files li.plain { padding: 10px 0; }
.file { display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px 0; min-height: 52px; text-align: left; font: inherit; color: var(--text); background: none; border: 0; cursor: pointer; }
.ficon { font-size: 24px; }
.fbody { display: flex; flex-direction: column; min-width: 0; }
.fname { overflow-wrap: anywhere; } .fmeta { font-size: 13px; color: var(--muted); }

.rlist { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.rrow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: start; }
.rfile { display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.tag { align-self: flex-start; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.tag.alta { background: #d9f2e0; color: #14532d; } .tag.media { background: var(--warn-bg); color: var(--warn-text); } .tag.bassa, .tag.nessuna { background: #fde2e0; color: #7a1410; }
.rtarget input { margin-top: 6px; }

.preview { overflow: auto; background: #e9edf1; padding: 12px; border-radius: 10px; }
.sheet { background: #fff; color: #111; max-width: 640px; margin: 0 auto; padding: 28px 32px; font-family: Calibri, "Segoe UI", sans-serif; font-size: 14px; box-shadow: 0 1px 6px rgba(0,0,0,.2); aspect-ratio: 210 / 297; }
.sheet .lh { text-align: center; border-bottom: 2px solid #444; padding-bottom: 8px; margin-bottom: 14px; }
.lh-name { font-size: 20px; font-weight: 700; } .lh-small { font-size: 11px; color: #555; }
.sheet h3 { text-align: center; margin: 14px 0; } .sheet p { margin: 0 0 6px; }
.sig-date, .sig-name { text-align: right; margin-top: 18px; }
.sig { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.sig img { max-height: 80px; max-width: 45%; } .foot { margin-top: 24px; text-align: center; }
.imgbox { min-height: 70px; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px dashed var(--line); border-radius: 10px; padding: 8px; }
.imgbox img { max-height: 100px; max-width: 100%; }

.designer { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.designer-preview { position: sticky; top: 76px; }
.designer-controls h3 { font-size: 16px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.rl { display: flex; justify-content: space-between; } .rv { color: var(--text); font-weight: 600; }
input[type=range] { padding: 0; height: 28px; }
input[type=color] { height: 44px; padding: 4px; }

.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { max-width: 460px; width: 100%; }
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10,16,22,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal, .busybox { background: var(--card); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; }
.busybox { width: auto; display: flex; gap: 14px; align-items: center; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 60; background: #1b2430; color: #fff; padding: 12px 18px; border-radius: 12px; max-width: 90vw; transition: .25s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.err { background: var(--danger); }

@media (max-width: 899px) {
  .cols { grid-template-columns: 1fr; }
  #list { position: static; max-height: none; border-right: 0; min-height: 0; }
  body[data-view="detail"] #list { display: none; }
  body[data-view="home"] #detail { display: none; }
  body[data-view="detail"] .back { display: inline-flex; }
  body[data-view="detail"] .brand { display: none; }
  .grid2, .rrow { grid-template-columns: 1fr; }
  .designer { grid-template-columns: 1fr; }
  .designer-preview { position: static; order: -1; }
  #detail { padding: 12px; }
}
.frow { display: flex; align-items: center; gap: 8px; }
.frow .file { flex: 1; min-width: 0; }
.appbtn { flex: none; }

.badge { display: inline-block; margin-left: 8px; padding: 1px 8px; font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 99px; vertical-align: middle; }
.chips { display: flex; gap: 6px; padding: 0 12px 8px; }
.chip { min-height: 32px; padding: 0 14px; font: inherit; font-size: 14px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 99px; cursor: pointer; }
.chip.on { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.kvs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 10px; }
.kv { display: flex; flex-direction: column; } .kv .k { font-size: 12px; color: var(--muted); }
.checks .full { grid-column: 1 / -1; }
.grid4 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.card.note { border-left: 3px solid var(--accent); }
@media (max-width: 899px) { .kvs { grid-template-columns: 1fr; } .grid4 { grid-template-columns: 1fr 1fr; } }

.sync { padding: 0 14px 6px; font-size: 12px; color: var(--muted); min-height: 18px; }
.diag { font: 12px/1.4 ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 260px; overflow: auto; white-space: pre-wrap; margin: 0; }

.phead { position: sticky; top: 62px; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -16px -16px 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.pheadname { font-weight: 700; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 899px) { .phead { margin: -12px -12px 10px; padding: 8px 12px; top: 58px; } }
