/* ===== Magazzino — stile applicazione ===== */
:root {
  --ink: #17262b;
  --muted: #627177;
  --line: #dfe5e6;
  --bg: #f3f5f4;
  --card: #ffffff;
  --side: #16323a;
  --side-ink: #c9d8da;
  --primary: #1f6f78;
  --primary-ink: #ffffff;
  --accent: #e8a33d;
  --danger: #b4372f;
  --ok: #2f7d4f;
  --warn: #a76a06;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 40, 45, .06), 0 2px 8px rgba(20, 40, 45, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; margin-bottom: .75rem; }
h3 { font-size: .95rem; margin: .5rem 0; }
code { font-family: var(--mono); background: #eef2f2; padding: 0 .3em; border-radius: 4px; }
.mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small, .small-help { font-size: .85rem; }
.small-help { margin: .5rem 0 0; }
.pre { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; vertical-align: -3px; }

/* ----- Layout ----- */
.app { display: flex; min-height: 100vh; }
.side { width: 232px; flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.1rem 1rem; font-weight: 700; color: #fff; font-size: 1.02rem; }
.brand .logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--side); }
.brand .logo .ic { width: 20px; height: 20px; }
.brand.big { color: var(--ink); font-size: 1.25rem; padding: 0 0 .5rem; }
.side nav { display: flex; flex-direction: column; padding: .25rem .6rem; gap: 2px; flex: 1; overflow-y: auto; }
.side nav a { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.side nav a.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-sep { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; opacity: .6; padding: 1rem .7rem .3rem; }
.me { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.1); }
.me a { color: #fff; display: flex; flex-direction: column; min-width: 0; }
.me small { color: var(--side-ink); opacity: .8; }
.me .icon-btn { color: var(--side-ink); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.5rem .25rem; }
.topbar h1 { font-size: 1.35rem; overflow-wrap: anywhere; }
.topbar .menu-btn { display: none; }
.content { padding: 1rem 1.5rem 3rem; max-width: 1100px; width: 100%; }
.content.wide { max-width: 1500px; }
.content > * + * { margin-top: 1rem; }

/* ----- Componenti ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.card.table-wrap { padding: 0; }
.table-wrap { overflow-x: auto; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { display: inline; margin: 0; }
details.card > summary::after { content: " ▾"; color: var(--muted); }
details.card[open] > summary { margin-bottom: 1rem; }
details.card > form.card { box-shadow: none; border: 0; padding: 0; margin-bottom: 1rem; }
details.sub { margin-top: .75rem; }
details.sub > summary { cursor: pointer; color: var(--primary); font-weight: 500; }
details.sub > form, details.sub > table { margin-top: .6rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-2 > .card { margin: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.section-head h2 { margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.meta-line { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 0 1rem; }

.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: #b9c6c8; background: #f7f9f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: #185c64; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.ghost:hover { background: rgba(31,111,120,.08); }
.btn.danger { color: var(--danger); }
.btn.danger:not(.ghost) { border-color: #e6b8b4; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
form.inline { display: inline; }

input, select, textarea { font: inherit; color: inherit; padding: .45rem .6rem; border: 1px solid #cdd6d7; border-radius: 7px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,111,120,.35); border-color: var(--primary); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
textarea { width: 100%; resize: vertical; }
.w-num { width: 5.5rem; text-align: right; }
.w-price { width: 7rem; text-align: right; }
.w-full { width: 100%; }
.grow { flex: 1; min-width: 10rem; }
.search { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid #cdd6d7; border-radius: 8px; padding: 0 .6rem; background: #fff; color: var(--muted); }
.search input { border: 0; padding: .45rem 0; outline: none; min-width: 14rem; color: var(--ink); background: transparent; }
.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .9rem; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem 1rem; align-items: start; }
.form-grid.narrow { max-width: 520px; grid-template-columns: 1fr; }
.form-grid h2 { margin: .5rem 0 0; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: .78rem; }
.field.full, .full { grid-column: 1 / -1; }
.field.wide { grid-column: span 2; }
.field.inline { flex-direction: row; align-items: center; gap: .4rem; }
.field.with-link { gap: .2rem; }
.field.with-link .field { flex: 1; }
.actions { display: flex; gap: .5rem; margin-top: .5rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.inline-form.wrap { margin-top: .75rem; }
.role-help, .small-help { line-height: 1.5; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .6rem .75rem; border-bottom: 1px solid var(--line); background: #fafbfb; white-space: nowrap; }
.table td { padding: .55rem .75rem; border-bottom: 1px solid #eef1f1; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafcfc; }
.table.compact td, .table.compact th { padding: .4rem .5rem; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.group td { background: #f3f6f6; font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: .4rem; padding-bottom: .4rem; }
.table tr.dim td { opacity: .55; }
.table tr.row-short td { background: #fff5f3; }
.table.totals td { padding: .35rem 0; }
.table.totals tr.grand td { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--ink); padding-top: .6rem; }
.w-check { width: 2rem; }
.lines input, .lines select { padding: .3rem .4rem; }
.neg, .neg-text { color: var(--danger); font-weight: 700; }
td.neg { background: #fdecea !important; }
td.zero { color: var(--warn); }
td.part { background: #fff8e8; }
.warn-text { color: var(--warn); font-weight: 600; }

.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .75rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; background: #eef1f1; color: var(--muted); white-space: nowrap; }
.badge .ic { width: 13px; height: 13px; }
.st-opzione { background: #fdf0d8; color: #8a5a00; }
.st-confermato { background: #dceafb; color: #1d4f8c; }
.st-in_corso { background: #ebe1fa; color: #5a2f9e; }
.st-rientrato { background: #ddf2e4; color: #22673e; }
.st-chiuso { background: #e9eded; color: #4c5a5e; }
.st-annullato { background: #f8e1df; color: #9b2c25; }
.badge.warn { background: #fdecc8; color: #8a5a00; }

.flash { margin: .5rem 1.5rem 0; padding: .7rem 1rem; border-radius: 8px; font-weight: 500; }
.bare .flash { margin: 0; }
.flash-ok { background: #ddf2e4; color: #1d5a35; }
.flash-warn { background: #fdf0d8; color: #7a5000; }
.flash-error { background: #f8e1df; color: #8f2620; }
.alert { display: flex; gap: .75rem; padding: .9rem 1rem; border-radius: var(--radius); background: #fff5f3; border: 1px solid #f0c9c4; color: #6e211b; }
.alert > .ic { color: var(--danger); width: 22px; height: 22px; margin-top: 2px; }
.alert ul { margin: .4rem 0; padding-left: 1.2rem; }

.tabs { display: flex; gap: .25rem; background: #e7ecec; padding: 3px; border-radius: 9px; }
.tabs a { padding: .35rem .8rem; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

.stats { display: flex; flex-wrap: wrap; gap: .5rem 1.75rem; margin-top: .5rem; }
.stats div { display: flex; flex-direction: column; }
.stats small { color: var(--muted); font-size: .78rem; }
.stats b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.qr-mini svg { display: block; border: 1px solid var(--line); border-radius: 6px; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .85rem; }
.dl dd { margin: 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .2rem; }
.kpi:hover { text-decoration: none; border-color: #b9c6c8; }
.kpi small { color: var(--muted); font-size: .8rem; }
.kpi b { font-size: 1.9rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-bad b { color: var(--danger); }
.kpi-warn b { color: var(--warn); }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid #eef1f1; flex-wrap: wrap; }
.plist li:last-child { border-bottom: 0; }
.plist a { display: flex; flex-direction: column; min-width: 0; }
.plist a small { color: var(--muted); }
.plist-meta { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .88rem; }
.plist.big li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .5rem; }

.progress { position: relative; height: 8px; border-radius: 99px; background: #eef1f1; overflow: hidden; min-width: 90px; }
.progress span { position: absolute; left: 0; top: 0; bottom: 0; background: #8e6ad0; border-radius: 99px; }
.progress span.back { background: #3a9a63; height: 4px; top: 4px; }

/* Disponibilità */
.avail-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 4px; }
.avail-strip .cell { border: 1px solid var(--line); border-radius: 6px; padding: .3rem; text-align: center; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.avail-strip .cell small { color: var(--muted); font-size: .72rem; }
.avail-strip .cell i { font-style: normal; font-size: .68rem; color: var(--warn); }
.avail-strip .cell.part { background: #fff8e8; }
.avail-strip .cell.neg { background: #fdecea; color: var(--danger); border-color: #f0c9c4; }
.avail-table .day { padding-left: .3rem; padding-right: .3rem; min-width: 2rem; font-size: .85rem; }
.avail-table th.day small { display: block; font-weight: 400; }
.avail-table .weekend { background: #f6f7f7; }

/* Ricerca articoli nel progetto */
.add-item { position: relative; margin-bottom: 1rem; }
.add-item .search { width: 100%; }
.add-item .search input { flex: 1; }
.search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 380px; overflow-y: auto; display: none; }
.search-results.open { display: block; }
.sr-item { display: grid; grid-template-columns: 1fr auto auto auto; gap: .75rem; align-items: center; padding: .55rem .75rem; border-bottom: 1px solid #eef1f1; }
.sr-item:last-child { border-bottom: 0; }
.sr-item small { color: var(--muted); display: block; }
.sr-item .avail { font-variant-numeric: tabular-nums; font-weight: 700; }
.sr-item .avail.neg { color: var(--danger); }
.sr-empty { padding: .8rem; color: var(--muted); }

/* Planning */
.planning { padding: 0; overflow-x: auto; }
.pl-row { display: grid; grid-template-columns: 200px minmax(calc(var(--days) * 28px), 1fr); border-bottom: 1px solid #eef1f1; min-height: 40px; }
.pl-row:last-child { border-bottom: 0; }
.pl-label { padding: .45rem .75rem; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid var(--line); position: sticky; left: 0; background: #fff; z-index: 2; min-width: 0; }
.pl-label a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.pl-label small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-head .pl-label { font-size: .78rem; text-transform: uppercase; color: var(--muted); font-weight: 600; background: #fafbfb; }
.pl-grid { display: grid; grid-template-columns: repeat(var(--days), minmax(28px, 1fr)); align-items: center; }
.pl-day { text-align: center; padding: .3rem 0; font-size: .8rem; color: var(--ink); display: flex; flex-direction: column; line-height: 1.1; background: #fafbfb; }
.pl-day small { color: var(--muted); font-size: .68rem; }
a.pl-day:hover { background: #e7f1f2; text-decoration: none; }
.pl-day.weekend, .pl-bg.weekend { background: #f1f4f4; }
.pl-day.today { background: var(--primary); color: #fff; }
.pl-day.today small { color: #d9eef0; }
.pl-bg { grid-row: 1; height: 100%; border-left: 1px solid #f2f4f4; }
.pl-bg.today { background: rgba(31,111,120,.08); }
.pl-bar { grid-row: 1; z-index: 1; margin: 6px 2px; padding: .2rem .5rem; border-radius: 6px; font-size: .78rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid rgba(0,0,0,.08); }
.pl-bar:hover { text-decoration: none; filter: brightness(.96); }
.pl-bar.cut-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.pl-bar.cut-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.pl-bar.late { background-image: repeating-linear-gradient(45deg, transparent 0 6px, rgba(180,55,47,.18) 6px 12px); }
.legend { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.month-title { margin: 0 .25rem; min-width: 10rem; text-align: center; }

/* Scansione */
.scan-app { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: .75rem; }
.scan-head { display: flex; flex-direction: column; gap: .6rem; }
.scan-project { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; color: var(--ink); }
.scan-project small { color: var(--muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #e2e8e8; padding: 4px; border-radius: 12px; }
.seg button { font: inherit; font-weight: 800; font-size: 1.05rem; border: 0; padding: .75rem; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.scan-app[data-mode=out] .seg-out { background: #5a2f9e; color: #fff; }
.scan-app[data-mode=in] .seg-in { background: #22673e; color: #fff; }
.scan-camera { position: relative; background: #0d1a1d; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; display: grid; place-items: center; }
.scan-camera video { width: 100%; height: 100%; object-fit: cover; display: none; }
.scan-camera.on video { display: block; }
.scan-camera #scan-fallback { position: absolute; inset: 0; }
.scan-camera #scan-fallback:empty { display: none; }
.scan-frame { position: absolute; inset: 18% 22%; border: 3px solid rgba(255,255,255,.75); border-radius: 14px; pointer-events: none; display: none; }
.scan-camera.on .scan-frame { display: block; }
.scan-camera.on .camera-btn { position: absolute; bottom: .6rem; right: .6rem; opacity: .85; }
.scan-camera.flash-ok { box-shadow: 0 0 0 4px #3a9a63; }
.scan-camera.flash-error { box-shadow: 0 0 0 4px var(--danger); }
.scan-manual { display: flex; gap: .5rem; }
.scan-manual input[name=code] { flex: 1; font-size: 1.1rem; font-family: var(--mono); }
.scan-msg { padding: .9rem 1rem; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); font-weight: 600; min-height: 3.2rem; }
.scan-msg.ok { background: #ddf2e4; border-color: #b9e0c6; color: #1d5a35; }
.scan-msg.warn { background: #fdf0d8; border-color: #f2d9a6; color: #7a5000; }
.scan-msg.error { background: #f8e1df; border-color: #f0c9c4; color: #8f2620; }
.scan-msg small { display: block; font-weight: 500; margin-top: .2rem; }
.scan-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.scan-row { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; padding: .55rem .9rem; border-bottom: 1px solid #eef1f1; align-items: center; }
.scan-row:last-child { border-bottom: 0; }
.scan-row small { color: var(--muted); font-family: var(--mono); }
.scan-row .count { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.05rem; }
.scan-row.done { background: #f2faf5; }
.scan-row.done .count { color: var(--ok); }
.scan-row.over .count { color: var(--warn); }
.scan-row .progress { grid-column: 1 / -1; }
.scan-log { margin: .5rem 0 0; padding-left: 1.4rem; font-size: .9rem; }
.scan-log li.error { color: var(--danger); }
.scan-log li.warn { color: var(--warn); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: .9rem; }
.login p { margin: 0; }
.error-card { max-width: 520px; }

/* Etichette / stampe */
.print-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .75rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.print-bar .btn.primary { margin-left: auto; }

/* ----- Mobile ----- */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  .side.open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.3); }
  .topbar .menu-btn { display: grid; }
  .topbar { padding: .75rem 1rem .25rem; position: sticky; top: 0; background: var(--bg); z-index: 10; }
  .topbar h1 { font-size: 1.15rem; }
  .content { padding: .75rem 1rem 3rem; }
  .flash { margin: .5rem 1rem 0; }
  .form-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
  .search input { min-width: 0; width: 100%; }
  .search { flex: 1; }
  .filters { width: 100%; }
  .pl-row { grid-template-columns: 140px minmax(calc(var(--days) * 30px), 1fr); }
  .sr-item { grid-template-columns: 1fr auto; }
  .sr-item .price { display: none; }
  .table th, .table td { padding: .5rem .5rem; }
}

/* Personale e mezzi nel progetto */
.grid-2.flat { gap: 1.5rem; }
.grid-2.flat h3 { display: flex; align-items: center; gap: .4rem; margin-top: 0; }
.assign-form { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; }
.assign-form select[multiple] { width: 100%; padding: .25rem; }
.assign-form option { padding: .2rem .4rem; }
.assign-form option.busy { color: var(--warn); }
.assign-form optgroup { font-weight: 700; color: var(--muted); }
.pl-row.pl-conflict .pl-label { box-shadow: inset 3px 0 0 var(--warn); }
.pl-row.pl-conflict .pl-label a { color: var(--warn); }
.table.totals tr.internal td { color: var(--muted); font-size: .9rem; border-top: 1px dashed var(--line); }
.table.totals tr.internal td b { color: var(--ink); }

/* Funzioni a preventivo e assegnazioni */
.ok-text { color: var(--ok); font-weight: 700; }
.add-fn { margin-top: .9rem; padding-top: .75rem; border-top: 1px dashed var(--line); }
.add-fn .inline-form.wrap { margin-top: 0; }
.slot { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; margin-bottom: .55rem; }
.slot-missing { border-color: #f2d9a6; background: #fffaf0; }
.slot-ok { background: #f6fbf8; border-color: #cfe8d8; }
.slot-head { display: flex; gap: .6rem; align-items: baseline; }
.slot-head b { flex: 1; }
.slot-row { display: grid; grid-template-columns: 1fr auto auto auto auto; gap: .5rem; align-items: center; padding: .3rem 0; border-top: 1px solid #eef1f1; }
.slot-form { margin-top: .45rem; }
.slot-form select { flex: 1; min-width: 10rem; }
.slot-form input[type=date] { width: 9.2rem; }

/* ===== Editor preventivo a due pannelli + catalogo ===== */
.editor-grid { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.catalog { position: sticky; top: .75rem; display: flex; flex-direction: column; gap: .5rem; border: 1px solid var(--line); border-radius: 10px; padding: .6rem; background: #fbfcfc; max-height: calc(100vh - 1.5rem); }
.catalog .search { width: 100%; }
.catalog .search input { flex: 1; min-width: 0; }
.cat-tree { overflow-y: auto; flex: 1; min-height: 200px; }
.cat-help { margin: 0; }
.cat-folder { border-bottom: 1px solid #eef1f1; }
.cat-head { display: block; width: 100%; text-align: left; font: inherit; font-weight: 700; font-size: .85rem; padding: .45rem .4rem; background: none; border: 0; cursor: pointer; color: var(--ink); text-transform: uppercase; letter-spacing: .02em; }
div.cat-head { cursor: default; color: var(--muted); }
.cat-head:hover { background: #f0f4f4; }
.cat-head .muted { font-weight: 400; }
.cat-item { display: grid; grid-template-columns: 1fr auto 3.2rem 1.9rem; gap: .35rem; align-items: center; padding: .3rem .4rem .3rem .9rem; border-top: 1px solid #f2f4f4; }
.cat-item:hover { background: #f4f8f8; }
.cat-item.busy { opacity: .5; }
.cat-name { min-width: 0; display: flex; flex-direction: column; }
.cat-name b { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-name small { color: var(--muted); font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-avail { font-variant-numeric: tabular-nums; font-weight: 700; font-size: .85rem; color: var(--ok); text-align: right; }
.cat-avail i { font-style: normal; font-weight: 400; color: var(--muted); font-size: .75rem; }
.cat-avail.low { color: var(--warn); }
.cat-avail.none { color: var(--danger); }
.cat-avail.fn { color: var(--muted); font-weight: 400; font-size: .72rem; }
.cat-qty { width: 100%; padding: .2rem .3rem; text-align: right; font-size: .85rem; }
.cat-add { width: 1.9rem; height: 1.9rem; border-radius: 7px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font-size: 1.1rem; font-weight: 700; cursor: pointer; line-height: 1; }
.cat-add:hover { background: #185c64; }
.editor-main { min-width: 0; }
.editor-bar { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; flex-wrap: wrap; }
.editor-table td { padding-top: .35rem; padding-bottom: .35rem; }
.editor-table .handle { cursor: grab; color: #a9b5b7; width: 1.4rem; text-align: center; user-select: none; font-size: 1rem; }
.editor-table .handle:hover { color: var(--ink); }
.editor-table .target-cell { width: 1.6rem; text-align: center; }
.editor-table tr.grp-head td { background: #eef3f3; border-top: 2px solid #dbe4e5; cursor: pointer; }
.editor-table tbody.is-target tr.grp-head td { background: #dcefee; }
.editor-table tbody.is-target tr.grp-head td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.grp-name { font-weight: 700; border: 1px solid transparent; background: transparent; padding: .2rem .4rem; width: 100%; max-width: 30rem; }
.grp-name:hover, .grp-name:focus { border-color: #cdd6d7; background: #fff; }
.editor-table tr.dragging { opacity: .4; }
.editor-table tr.drop-before td { box-shadow: inset 0 3px 0 var(--primary); }
.editor-table tbody.drop-into tr.grp-head td { background: #cfe9e7; }
.editor-table .fn-ic { width: 15px; height: 15px; color: var(--muted); }
.editor-table input[data-field] { padding: .25rem .35rem; }
.editor-hint { margin: .75rem 0 0; }
@media (max-width: 1100px) {
  .editor-grid { grid-template-columns: 1fr; }
  .catalog { position: static; max-height: 420px; }
}

/* Compositore kit */
.kit-bar { margin: 0 0 .75rem; }
.kit-counters { display: flex; gap: .6rem; flex-wrap: wrap; }
.kit-count { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; padding: .35rem .7rem; min-width: 7rem; background: #fff; }
.kit-count small { color: var(--muted); font-size: .72rem; }
.kit-count b { font-size: 1.35rem; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kit-count.ok b { color: var(--ok); }
.kit-count.bad { border-color: #f0c9c4; background: #fff5f3; }
.kit-count.bad b { color: var(--danger); }
.editor-table td.voce { min-width: 14rem; }
.editor-table .w-num { width: 4.3rem; }
.editor-table .w-price { width: 5.8rem; }
.editor-table th, .editor-table td { padding-left: .45rem; padding-right: .45rem; }

/* Suggeriti */
.suggest { border: 1px solid #f2d9a6; background: #fffaf0; border-radius: 8px; padding: .4rem; }
.suggest-head { display: flex; justify-content: space-between; align-items: center; padding: .1rem .3rem .35rem; }
.suggest .cat-item { padding-left: .4rem; }
[data-suggest].pulse .suggest { animation: pulse 1.2s ease; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(232,163,61,.7); } 100% { box-shadow: 0 0 0 10px rgba(232,163,61,0); } }
.sug-list .cat-item { padding-left: .4rem; }
.sug-dialog { border: 0; border-radius: 12px; padding: 1.2rem 1.3rem; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.sug-dialog::backdrop { background: rgba(15,30,35,.45); }
.sug-dialog h3 { margin: 0 0 .25rem; font-size: 1.1rem; }
.sug-rows { display: flex; flex-direction: column; gap: .35rem; margin: .75rem 0; max-height: 55vh; overflow-y: auto; }
.sug-row { display: grid; grid-template-columns: auto 1fr auto 4.5rem; gap: .6rem; align-items: center; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.sug-row:has(input:checked) { border-color: var(--primary); background: #f1f8f8; }
.sug-row.short { border-color: #f2d9a6; }
.sug-name { display: flex; flex-direction: column; min-width: 0; }
.sug-name small { color: var(--muted); }
.sug-row input[type=number] { width: 100%; text-align: right; }
.logo-preview { max-width: 240px; max-height: 90px; border: 1px solid var(--line); border-radius: 6px; padding: .4rem; background: #fff; }
