/* Chrome dell'applicazione (home + editor). */
:root {
  --bg: #eef2f7; --panel: #fff; --border: #dde3ec; --text: #0f172a; --muted: #64748b;
  --accent: #1e3a5f; --accent-2: #2f5d9e; --danger: #c62828; --ok: #2e7d32;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: "Segoe UI", Inter, Calibri, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--accent-2); }
button, .btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 13px;
               border-radius: 8px; cursor: pointer; line-height: 1.2; text-decoration: none; display: inline-flex;
               align-items: center; gap: 6px; transition: background .12s, box-shadow .12s; }
button:hover, .btn:hover { background: #f4f6fa; box-shadow: 0 1px 3px rgba(15,23,42,.08); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #274b7a; }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; width: 100%;
                          background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 60px; font-size: 13px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > .fixed { flex: 0 0 auto; }

/* ── home ───────────────────────────────────────────────────────────── */
.hero { background: linear-gradient(120deg, #142a47 0%, #1e3a5f 55%, #2f5d9e 100%); color: #fff; }
.hero-inner { max-width: 1180px; margin: 0 auto; padding: 34px 24px 30px; display: flex; justify-content: space-between;
              align-items: flex-end; gap: 24px; flex-wrap: wrap; }
.hero .kicker { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; opacity: .75; font-weight: 600; }
.hero h1 { margin: 6px 0 6px; font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.hero p { margin: 0; opacity: .85; font-size: 14px; max-width: 560px; }
.ws-pill { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; padding: 7px 12px; border-radius: 999px;
           background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); white-space: nowrap; }
.ws-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; }
.ws-pill.ok .dot { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.ws-pill.ko .dot { background: #f87171; box-shadow: 0 0 0 3px rgba(248,113,113,.25); }

.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 48px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 22px; }
.doc-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
            box-shadow: 0 1px 2px rgba(15,23,42,.05), 0 8px 24px -12px rgba(15,23,42,.18); transition: transform .15s, box-shadow .15s; }
.doc-card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(15,23,42,.06), 0 16px 32px -14px rgba(15,23,42,.28); }
.thumb { display: block; position: relative; background: #e6ebf2; padding: 14px 14px 0; }
.thumb-inner { position: relative; aspect-ratio: 297 / 210; overflow: hidden; border-radius: 6px 6px 0 0;
               box-shadow: 0 -1px 0 rgba(15,23,42,.06), 0 6px 18px -8px rgba(15,23,42,.35); background: #fff; }
.thumb-inner .sheet { position: absolute; left: 0; top: 0; }
.thumb-badge { position: absolute; right: 24px; top: 24px; background: rgba(15,23,42,.75); color: #fff; font-size: 11px;
               padding: 3px 9px; border-radius: 999px; }
.doc-body { padding: 16px 18px 18px; }
.doc-body h2 { margin: 0; font-size: 18px; font-weight: 700; }
.doc-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 14px; }
.chip { font-size: 11.5px; background: #f1f5f9; border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px; color: #334155; }
.chip.muted { color: var(--muted); background: transparent; }
.chip.tipo { margin-left: 6px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: 10px; }
.chip.tipo.sicurezza { background: #fff3e0; border-color: #f5c48a; color: #8a4b00; }
.chip.tipo.funzionale { background: #e8eef8; border-color: #c5d3ea; color: #1e3a5f; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }

/* ── avviso dati di esempio ─────────────────────────────────────────── */
.notice { display: flex; gap: 12px; align-items: flex-start; background: #fff8e6; border: 1px solid #f5d78a; color: #6b4e00;
          border-radius: 12px; padding: 12px 16px; margin: 0 0 22px; font-size: 13.5px; line-height: 1.45; }
.notice-icon { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; background: #f0b429; color: #fff; font-weight: 700;
               display: flex; align-items: center; justify-content: center; font-size: 14px; }
.notice.slim { margin: 0; border-radius: 0; border-width: 0 0 1px; padding: 6px 14px; font-size: 12.5px; align-items: center; }
.notice.slim .notice-icon { width: 18px; height: 18px; font-size: 11px; }

/* ── editor ─────────────────────────────────────────────────────────── */
header.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel);
                border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
header.topbar h1 { font-size: 16px; margin: 0 8px 0 0; font-weight: 600; white-space: nowrap; }
header.topbar .spacer { flex: 1; }
header.topbar .status { font-size: 12px; color: var(--muted); white-space: nowrap; }
header.topbar .status.dirty { color: #b26a00; }
header.topbar .zoom { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
header.topbar .zoom input { width: 110px; padding: 0; }

.editor { display: grid; grid-template-columns: 1fr 340px; height: calc(100vh - 49px - 34px); }
#canvas { overflow: auto; padding: 24px; }
#canvas-inner { display: inline-block; }
#canvas .sheet { margin: 0 auto 24px; box-shadow: 0 2px 12px rgba(15,23,42,.18); }
#canvas .sheet::before { content: attr(data-label); position: absolute; left: 0; top: 0; font-size: 10px; color: #999; padding: 2px 6px; }
#canvas .node { cursor: pointer; }
#canvas .node:hover { outline: 2px solid rgba(47,93,158,.45); outline-offset: 2px; }
#canvas .node.selected { outline: 3px solid #f59e0b; outline-offset: 2px; }
#canvas .node.drop-target { outline: 3px dashed #2e7d32; outline-offset: 3px; }
#canvas .node.dragging { opacity: .5; }
#canvas .sheet.active { box-shadow: 0 0 0 3px rgba(47,93,158,.35), 0 2px 12px rgba(15,23,42,.18); }

aside#sidebar { background: var(--panel); border-left: 1px solid var(--border); overflow: auto; padding: 0 14px 20px; }
aside details { border-bottom: 1px solid var(--border); padding: 6px 0 12px; }
aside summary { cursor: pointer; font-weight: 600; padding: 8px 0; font-size: 12px; text-transform: uppercase;
                letter-spacing: .06em; color: #475569; }
aside .hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
aside .btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
aside .swatches { display: flex; gap: 6px; flex-wrap: wrap; }
aside .swatch { width: 24px; height: 24px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
aside .swatch.on { border-color: #0f172a; box-shadow: 0 0 0 2px #fff inset; }
aside .type-badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eef2f7; color: var(--accent); }
aside .page-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-top: 8px; }
aside .page-item.active { border-color: var(--accent-2); }
aside .page-item .row { margin-top: 6px; }
aside .page-item .num { font-weight: 600; color: var(--muted); font-size: 12px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0f172a; color: #fff;
         padding: 10px 16px; border-radius: 8px; font-size: 13px; max-width: 700px; z-index: 50; display: none;
         white-space: pre-line; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
#toast.show { display: block; }
#toast.error { background: #b71c1c; }
#toast.ok { background: #1b5e20; }
.busy { pointer-events: none; opacity: .6; }

/* ── login ──────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; padding: 24px;
              background: linear-gradient(120deg, #142a47 0%, #1e3a5f 55%, #2f5d9e 100%); }
.login-card { background: var(--panel); border-radius: 14px; padding: 28px 30px 32px; width: 100%; max-width: 360px;
              box-shadow: 0 24px 60px -20px rgba(15,23,42,.55); }
.login-card .kicker { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.login-card h1 { margin: 6px 0 4px; font-size: 22px; color: var(--accent); }
.login-card p { margin: 0 0 18px; }
.login-error { background: #fdecea; border: 1px solid #f5c6c2; color: var(--danger); border-radius: 8px;
               padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }
.hero-actions { display: flex; align-items: center; gap: 10px; }
.hero-actions .logout-form { margin: 0; }
.btn.ghost { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.ghost:hover { background: rgba(255,255,255,.2); }
