/* Ricamo Facile — stile Windows 11 (Fluent): Mica + Acrylic, accento rosso filo */
:root {
  --accent: #b4233c; --accent-hover: #9c1d33; --accent-press: #84182b; --on-accent: #fff; --accent-soft: rgba(180, 35, 60, .1);
  --mica: linear-gradient(135deg, #f3ece6 0%, #eef0f4 45%, #f1ebef 100%);
  --layer: rgba(255, 255, 255, .72); --layer-2: rgba(255, 255, 255, .9); --layer-solid: #fbfbfb;
  --stroke: rgba(0, 0, 0, .085); --stroke-strong: rgba(0, 0, 0, .16);
  --text: #1b1a19; --text-2: #55504c; --text-3: #6f6964;
  --ctrl: rgba(255, 255, 255, .78); --ctrl-hover: rgba(249, 249, 249, .6); --ctrl-press: rgba(249, 249, 249, .35);
  --sh-1: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 6px rgba(0, 0, 0, .05);
  --sh-2: 0 4px 12px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .06);
  --sh-3: 0 18px 48px rgba(40, 20, 20, .18), 0 4px 12px rgba(0, 0, 0, .08);
  --ok: #0f7b0f; --warn: #9d5d00; --err: #c42b1c;
  --r: 8px; --r-s: 4px;
  --font: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-d: "Segoe UI Variable Display", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --accent: #ff6b81; --accent-hover: #ff8496; --accent-press: #e95c71; --on-accent: #2a0a10; --accent-soft: rgba(255, 107, 129, .14);
  --mica: linear-gradient(135deg, #221d1f 0%, #1c1d22 50%, #221c20 100%);
  --layer: rgba(44, 42, 44, .7); --layer-2: rgba(52, 50, 52, .92); --layer-solid: #2b292b;
  --stroke: rgba(255, 255, 255, .08); --stroke-strong: rgba(255, 255, 255, .16);
  --text: #f3f1f0; --text-2: #cfc9c5; --text-3: #a9a29e;
  --ctrl: rgba(255, 255, 255, .06); --ctrl-hover: rgba(255, 255, 255, .09); --ctrl-press: rgba(255, 255, 255, .04);
  --sh-1: 0 1px 2px rgba(0, 0, 0, .3); --sh-2: 0 4px 14px rgba(0, 0, 0, .35); --sh-3: 0 18px 48px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #ff6b81; --accent-hover: #ff8496; --accent-press: #e95c71; --on-accent: #2a0a10; --accent-soft: rgba(255, 107, 129, .14);
    --mica: linear-gradient(135deg, #221d1f 0%, #1c1d22 50%, #221c20 100%);
    --layer: rgba(44, 42, 44, .7); --layer-2: rgba(52, 50, 52, .92); --layer-solid: #2b292b;
    --stroke: rgba(255, 255, 255, .08); --stroke-strong: rgba(255, 255, 255, .16);
    --text: #f3f1f0; --text-2: #cfc9c5; --text-3: #a9a29e;
    --ctrl: rgba(255, 255, 255, .06); --ctrl-hover: rgba(255, 255, 255, .09); --ctrl-press: rgba(255, 255, 255, .04);
    --sh-1: 0 1px 2px rgba(0, 0, 0, .3); --sh-2: 0 4px 14px rgba(0, 0, 0, .35); --sh-3: 0 18px 48px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--mica); background-attachment: fixed; min-height: 100vh; -webkit-font-smoothing: antialiased; }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-s); }
* { scrollbar-width: thin; scrollbar-color: var(--stroke-strong) transparent; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--font-d); margin: 0; letter-spacing: -.01em; }
.num, .stat b, .tab-num { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------ struttura */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr) 360px; grid-template-rows: 52px minmax(0, 1fr); height: 100vh; height: 100dvh; min-height: 560px; }
.titlebar { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; padding: 0 10px 0 14px; background: var(--layer); backdrop-filter: blur(30px) saturate(1.4); -webkit-backdrop-filter: blur(30px) saturate(1.4); border-bottom: 1px solid var(--stroke); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: 14px; min-width: 0; }
.brand svg { width: 26px; height: 26px; }
.brand b { font: 600 15px/1 var(--font-d); white-space: nowrap; }
.brand small { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.cmd { display: flex; gap: 2px; align-items: center; flex: 1; min-width: 0; overflow: hidden; }
.cmd .sep { width: 1px; height: 22px; background: var(--stroke-strong); margin: 0 6px; }
.right-cmd { display: flex; gap: 4px; align-items: center; }

/* bottoni */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 32px; padding: 5px 12px; border-radius: var(--r-s); border: 1px solid var(--stroke); border-bottom-color: var(--stroke-strong); background: var(--ctrl); color: var(--text); font: inherit; cursor: pointer; transition: background .12s, transform .08s; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--ctrl-hover); }
.btn:active { background: var(--ctrl-press); transform: translateY(.5px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.accent { background: var(--accent); color: var(--on-accent); border-color: transparent; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .18); }
.btn.accent:hover { background: var(--accent-hover); }
.btn.accent:active { background: var(--accent-press); }
.btn.big { min-height: 44px; font-size: 15px; font-weight: 600; width: 100%; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--ctrl-hover); border-color: var(--stroke); }
.btn.icon { padding: 5px 7px; }
.btn.sm { min-height: 26px; padding: 2px 8px; font-size: 12.5px; }

/* navigazione */
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; overflow: auto; border-right: 1px solid var(--stroke); background: color-mix(in srgb, var(--layer) 45%, transparent); }
.nav button { position: relative; display: flex; align-items: center; gap: 12px; padding: 9px 12px; border: 0; border-radius: var(--r-s); background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.nav button:hover { background: var(--ctrl-hover); }
.nav button[aria-current="true"] { background: var(--ctrl); box-shadow: var(--sh-1); font-weight: 600; }
.nav button[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav .grp { font-size: 11.5px; color: var(--text-3); padding: 14px 12px 4px; }
.nav .spacer { flex: 1; }
.nav button span.s { display: none; }

/* area di lavoro */
.work { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; min-width: 0; min-height: 0; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 8px 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--ctrl); border: 1px solid var(--stroke); border-radius: var(--r); padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--text-2); font: inherit; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--layer-solid); color: var(--text); font-weight: 600; box-shadow: var(--sh-1); }
.tabs .grow { flex: 1; }
.stage { position: relative; margin: 0 12px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--stroke); box-shadow: var(--sh-2); background: #f4f1ea; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.stage canvas.dragging { cursor: grabbing; }
.stage .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: #4a4542; pointer-events: none; }
.stage .empty div { max-width: 420px; pointer-events: auto; }
.stage .empty h2 { font-size: 22px; margin-bottom: 8px; color: #2b2725; }
.stage .empty p { margin: 0 0 16px; }
.stage.drop { outline: 2px dashed var(--accent); outline-offset: -8px; }
.zoom { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 2px; padding: 3px; border-radius: var(--r); background: var(--layer-2); border: 1px solid var(--stroke); box-shadow: var(--sh-2); backdrop-filter: blur(20px); }
.legend { position: absolute; left: 10px; top: 10px; padding: 6px 10px; border-radius: var(--r); background: var(--layer-2); border: 1px solid var(--stroke); font-size: 12px; color: var(--text-2); box-shadow: var(--sh-1); max-width: calc(100% - 20px); }
.busy { position: absolute; inset: 0; display: none; place-items: center; background: rgba(244, 241, 234, .55); backdrop-filter: blur(3px); }
.busy.on { display: grid; }
.busy .card { background: var(--layer-2); border: 1px solid var(--stroke); border-radius: var(--r); padding: 18px 22px; box-shadow: var(--sh-3); min-width: 260px; color: var(--text); }
.ring { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; margin-right: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* simulatore */
.sim { display: none; align-items: center; gap: 10px; padding: 8px 12px 0; }
.sim.on { display: flex; }
.sim input[type=range] { flex: 1; }
.sim .col { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--stroke-strong); }

.status { display: flex; gap: 18px; padding: 8px 14px 10px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.status b { color: var(--text); font-weight: 600; }

/* pannello proprietà */
.props { overflow: auto; border-left: 1px solid var(--stroke); background: color-mix(in srgb, var(--layer) 55%, transparent); padding: 14px 14px 30px; display: flex; flex-direction: column; gap: 12px; }
.panel { display: none; flex-direction: column; gap: 12px; }
.panel.on { display: flex; animation: in .22s cubic-bezier(.16, 1, .3, 1); }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }
.panel > h2 { font-size: 20px; font-weight: 600; }
.panel > p.lead { margin: -6px 0 2px; color: var(--text-2); }
.box { background: var(--layer-2); border: 1px solid var(--stroke); border-radius: var(--r); padding: 12px; box-shadow: var(--sh-1); display: flex; flex-direction: column; gap: 10px; }
.box h3 { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.row > .fix { flex: none; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); }
input[type=number], input[type=text], select, textarea { font: inherit; color: var(--text); background: var(--ctrl); border: 1px solid var(--stroke); border-bottom: 1px solid var(--stroke-strong); border-radius: var(--r-s); padding: 6px 9px; min-height: 32px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-bottom: 2px solid var(--accent); background: var(--layer-solid); }
textarea { resize: vertical; min-height: 64px; }
input[type=range] { accent-color: var(--accent); width: 100%; }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
.chk { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.hint { font-size: 12px; color: var(--text-3); margin: 0; }
details.adv > summary { cursor: pointer; font-weight: 600; font-size: 13.5px; list-style: none; display: flex; align-items: center; gap: 8px; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::after { content: ""; width: 7px; height: 7px; border-right: 1.6px solid var(--text-2); border-bottom: 1.6px solid var(--text-2); transform: rotate(-45deg); margin-left: auto; transition: transform .15s; }
details.adv[open] > summary::after { transform: rotate(45deg); }
details.adv[open] > summary { margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }

.drop-zone { border: 1.5px dashed var(--stroke-strong); border-radius: var(--r); padding: 16px; text-align: center; cursor: pointer; transition: background .15s, border-color .15s; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-2); }
.drop-zone:hover, .drop-zone.drop { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.drop-zone img { max-width: 100%; max-height: 110px; border-radius: var(--r-s); }
.examples { display: flex; gap: 6px; flex-wrap: wrap; }

/* passi automatici */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.steps li { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-3); }
.steps li i { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--stroke-strong); display: grid; place-items: center; font-style: normal; font-size: 11px; flex: none; }
.steps li.run { color: var(--text); }
.steps li.run i { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps li.ok { color: var(--text); }
.steps li.ok i { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps li small { margin-left: auto; color: var(--text-3); }

/* fili */
.threads { display: flex; flex-direction: column; gap: 6px; }
.thread { display: grid; grid-template-columns: 28px 1fr auto; gap: 4px 10px; align-items: center; padding: 8px; border-radius: var(--r-s); background: var(--ctrl); border: 1px solid var(--stroke); }
.thread .sw { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .2); box-shadow: inset 0 -3px 6px rgba(0, 0, 0, .18), inset 0 2px 3px rgba(255, 255, 255, .35); cursor: pointer; padding: 0; }
.thread .nm { font-weight: 600; font-size: 13px; line-height: 1.2; }
.thread .nm small { display: block; font-weight: 400; color: var(--text-3); font-size: 11.5px; }
.thread .ops { display: flex; gap: 2px; }
.thread .opts { grid-column: 2 / -1; display: grid; grid-template-columns: 1fr 74px; gap: 6px; }
.thread .opts select, .thread .opts input { min-height: 28px; padding: 3px 6px; font-size: 12.5px; }
.thread.off { opacity: .5; }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 8px; background: var(--layer-solid); border: 1px solid var(--stroke); border-radius: var(--r); box-shadow: var(--sh-3); position: absolute; z-index: 30; width: 272px; }
.palette button { aspect-ratio: 1; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .2); cursor: pointer; padding: 0; }
.palette button:hover { transform: scale(1.15); }

.elements { display: flex; flex-direction: column; gap: 4px; }
.el { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--r-s); border: 1px solid transparent; cursor: pointer; }
.el:hover { background: var(--ctrl-hover); }
.el.sel { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.el span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el small { color: var(--text-3); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { padding: 8px 10px; border-radius: var(--r-s); background: var(--ctrl); border: 1px solid var(--stroke); }
.stat span { display: block; font-size: 11.5px; color: var(--text-3); }
.stat b { font-size: 16px; font-weight: 600; }
.note { padding: 10px 12px; border-radius: var(--r-s); background: var(--accent-soft); font-size: 12.5px; }

.feature-list { display: flex; flex-direction: column; gap: 10px; }
.feature { display: grid; grid-template-columns: 22px 1fr; gap: 10px; }
.feature svg { margin-top: 2px; color: var(--accent); }
.feature b { display: block; font-size: 13.5px; }
.feature p { margin: 2px 0 0; color: var(--text-2); font-size: 12.5px; }

/* menu e dialoghi */
.menu { position: absolute; right: 10px; top: 48px; background: var(--layer-2); backdrop-filter: blur(30px); border: 1px solid var(--stroke); border-radius: var(--r); box-shadow: var(--sh-3); padding: 4px; min-width: 230px; display: none; z-index: 40; }
.menu.on { display: block; animation: in .16s ease-out; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent; color: var(--text); font: inherit; border-radius: var(--r-s); cursor: pointer; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--ctrl-hover); }
.menu hr { border: 0; border-top: 1px solid var(--stroke); margin: 4px 0; }
dialog { border: 1px solid var(--stroke); border-radius: var(--r); padding: 0; background: var(--layer-solid); color: var(--text); box-shadow: var(--sh-3); max-width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
dialog .dh { padding: 20px 22px 6px; }
dialog .db { padding: 6px 22px 16px; }
dialog .df { padding: 14px 22px; background: var(--ctrl); border-top: 1px solid var(--stroke); display: flex; justify-content: flex-end; gap: 8px; }
dialog ul { padding-left: 18px; margin: 8px 0; }
dialog li { margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--layer-solid); border: 1px solid var(--stroke); border-radius: var(--r); box-shadow: var(--sh-3); padding: 10px 16px; transition: .25s cubic-bezier(.16, 1, .3, 1); z-index: 60; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translateX(-50%); }

/* piede */
.foot { padding: 18px 16px 6px; text-align: center; color: var(--text-3); font-size: 12.5px; }
.foot a { color: var(--text-2); }
.piede-admin { text-align: center; margin: 0; padding: 0 16px 18px; font-size: 12px; }
.piede-admin a { color: var(--text-3); }

/* ------------------------------------------------ telefono e tablet */
@media (max-width: 1180px) and (min-width: 821px) { .app { grid-template-columns: 64px minmax(0, 1fr) 330px; } .nav button span, .nav .grp { display: none; } .nav button { justify-content: center; padding: 10px; } .brand small { display: none; } }
@media (max-width: 820px) {
  .app { display: block; height: auto; min-height: 0; }
  .titlebar { position: sticky; top: 0; height: 52px; }
  .cmd .lbl, .cmd .sep, .cmd .hide-m { display: none; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--stroke); background: var(--layer-2); backdrop-filter: blur(30px); overflow-x: auto; }
  .nav button { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; min-width: 52px; flex: 1; align-items: center; }
  .nav button span { display: none; }
  .nav button span.s { display: block; white-space: nowrap; }
  .nav button[aria-current="true"]::before { left: 30%; right: 30%; top: auto; bottom: 0; width: auto; height: 3px; }
  .nav .spacer, .nav .grp, .nav .desk { display: none; }
  .work { display: block; }
  .stage { height: 62vh; min-height: 320px; margin: 0 12px; }
  .props { border: 0; padding: 14px 12px; background: transparent; overflow: visible; }
  .foot { padding-bottom: 6px; }
  .piede-admin { padding-bottom: 90px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .app, .foot, .piede-admin { display: none !important; } }
