/* Viste: magazzino, scheda articolo, inventario, import, riepilogo, anagrafiche. */

.sheet-head { position: relative; }

/* ---- Ricerca e filtri ---- */
.search { position: relative; display: flex; align-items: center; }
.search-ico { position: absolute; left: 18px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 50px; padding-right: 52px; min-height: var(--tap); font-size: 16.5px; border-radius: var(--pill); border-color: var(--line-strong); background: var(--surface); }
.search-clear { position: absolute; right: 4px; display: grid; place-items: center; width: 48px; height: 48px; border: 0; background: transparent; color: var(--muted); border-radius: 50%; }
.search-input::-webkit-search-cancel-button { display: none; }
.kbd { position: absolute; right: 18px; display: grid; place-items: center; min-width: 24px; height: 24px; border-radius: 6px; color: var(--muted); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); pointer-events: none; }
.search:focus-within .kbd, .search-clear:not([hidden]) ~ .kbd { display: none; }
.filters {
  position: sticky; top: 0; z-index: 10; display: grid; gap: 10px;
  margin: 0 -18px; padding: calc(8px + var(--safe-t)) 18px 12px; background: var(--bg);
}
.facets { display: grid; gap: 8px; }
.facets:empty { display: none; }
.count-line { color: var(--muted); font-size: 14.5px; margin: 14px 0 10px; }
.count-below { color: var(--warn); font-weight: 600; }

/* ---- Schede articolo (telefono) ---- */
.card-groups { display: grid; gap: 22px; }
.group-title { font: 600 14px/1.2 var(--font-d); letter-spacing: .02em; color: var(--muted); margin: 0 0 10px 4px; }
.cards { display: grid; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden; position: relative; box-shadow: var(--shadow);
}
/* sotto scorta: barra gialla sottile a sinistra */
.card.is-below { box-shadow: inset 4px 0 0 var(--below), var(--shadow); }
.card-main { display: flex; gap: 12px; padding: 16px 18px 8px; color: var(--ink); text-decoration: none; }
.card-text { flex: 1; min-width: 0; display: grid; gap: 6px; align-content: start; }
.card-title { font: 600 19px/1.2 var(--font-d); letter-spacing: -.015em; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--muted); font-size: 14.5px; }
.card-detail { color: var(--muted); font-size: 14px; }
.card-qty { display: grid; justify-items: end; align-content: start; text-align: right; min-width: 64px; }
.qty { font: 600 42px/0.95 var(--font-d); letter-spacing: -.03em; }
.qty-unit { color: var(--muted); font: 500 14px var(--font-d); margin-top: 2px; }
.card.is-zero .qty { color: var(--out); }
.qty-pending { color: var(--link) !important; }
/* − giacenza + : il numero grande in mezzo, pulsanti da 56 px */
.card-stepper { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 10px; padding: 6px 16px 12px; }
.card-qty-mid { justify-items: center; text-align: center; min-width: 0; }
.card-qty-mid .qty { font-size: 46px; }
.card-stepper.is-busy .qty { opacity: .8; }
.step-q {
  display: inline-grid; place-items: center; width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%; vertical-align: middle;
  background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); transition: box-shadow .2s, background-color .2s;
}
.step-q .ico { width: 24px; height: 24px; stroke-width: 2.2; }
.step-q:hover { box-shadow: inset 0 0 0 1px var(--ring-hover); color: var(--link-hover); }
.step-q:active { background: var(--soft); }
.step-q:disabled { opacity: .3; cursor: not-allowed; }
.step-q[aria-busy="true"] { cursor: progress; }
.step-q.step-sm { width: 34px; height: 34px; }
.step-q.step-sm .ico { width: 17px; height: 17px; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 16px 16px; }
.card-actions .btn { width: 100%; }
.more-btn { margin-top: 16px; }

/* ---- Tabella magazzino (desktop) ---- */
.grid tbody tr { cursor: default; }
.grid td.td-title { min-width: 220px; }
.row-link { color: var(--ink); font-weight: 600; text-decoration: none; }
.row-link:hover { text-decoration: underline; color: var(--ink); }
.mag .grid tbody tr { cursor: pointer; transition: background-color .15s; }
.mag .grid tbody tr:hover td { background: var(--surface-2); }
.mag .grid tr.is-open td { background: var(--tint); }
.mag .grid tr.is-below td:first-child { box-shadow: inset 3px 0 0 var(--below); }
.mag .grid tr.is-zero .td-qty strong { color: var(--out); }
.td-qty strong { font: 600 18px var(--font-d); letter-spacing: -.01em; }
.td-qty .u { color: var(--muted); font-size: 13px; }
.td-qty.is-busy strong { opacity: .8; }
.td-step { white-space: nowrap; width: 1%; padding-left: 4px !important; }
.td-step .step-q + .step-q { margin-left: 6px; }
.th-step { width: 1%; }
.td-actions { white-space: nowrap; text-align: right; }
@media (min-width: 900px) {
  .td-actions .btn { min-height: 32px; padding: 0 12px; font-size: 13px; }
}
.td-actions .btn + .btn { margin-left: 6px; }

/* Materiali su telefono: righe impilate invece della tabella a tre colonne */
@media (max-width: 899px) {
  .mat-table, .mat-table tbody, .mat-table tr, .mat-table td { display: block; }
  .mat-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .mat-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--line); }
  .mat-table tr:last-child { border-bottom: 0; }
  .mat-table td { padding: 0; border: 0; }
  .mat-table td.num::before { content: "kg/dm³ "; color: var(--muted); font-size: 13px; }
  .mat-table td.td-actions { grid-column: 1 / -1; text-align: left; display: flex; gap: 8px; flex-wrap: wrap; }
  .mat-table td.td-actions .btn { min-height: var(--tap); flex: 1 1 auto; }
  .mat-table td.td-actions .btn + .btn { margin-left: 0; }
  .mat-table .input-sm { max-width: none; margin-left: 0; text-align: left; }
}
.th-actions { width: 1%; }

@media (min-width: 900px) {
  .filters { position: static; margin: 0; padding: 0; background: none; grid-template-columns: minmax(260px, 460px) auto; justify-content: start; align-items: center; column-gap: 14px; }
  .filters .chips-status { flex-wrap: nowrap; }
  .filters .search { grid-column: 1; grid-row: 1; }
  .filters .chips-status { grid-column: 2; grid-row: 1; }
  .filters > .chips:not(.chips-status), .filters .facets { grid-column: 1 / -1; }
  .chips-scroll { margin-right: 0; padding-right: 2px; flex-wrap: wrap; overflow: visible; }
  .search input { min-height: 48px; font-size: 15.5px; }
  .chip { min-height: 38px; font-size: 14px; padding: 0 16px; }
  .chip-sm { min-height: 34px; font-size: 13.5px; padding: 0 14px; }

  .mag { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; align-items: start; }
  .mag.has-panel { grid-template-columns: minmax(0, 1fr) minmax(400px, 34%); }
  .mag-panel {
    position: sticky; top: 20px; max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 24px 24px 26px; box-shadow: var(--shadow);
  }
  .mag-panel .page-head { margin-top: 0; }
}
@media (min-width: 1280px) {
  /* con il pannello aperto restano codice, articolo, giacenza, − +, minimo e azioni */
  .mag.has-panel .grid :is(.col-cat, .col-loc, .col-sup, .col-weight) { display: none; }
  .mag.has-panel .grid td.td-title { min-width: 0; }
  .mag.has-panel .grid :is(.td-actions, .th-actions) { display: none; } /* Arrivo e Uso sono nel pannello */
}
/* tabella densa: le colonne meno importanti spariscono quando manca spazio */
@media (min-width: 900px) and (max-width: 1599px) { .mag .grid :is(.col-weight) { display: none; } }
@media (min-width: 900px) and (max-width: 1439px) { .mag .grid :is(.col-sup) { display: none; } }
.mag .grid :is(th, td) { padding-inline: 12px; }
@media (min-width: 900px) and (max-width: 1279px) {
  /* schermi stretti: il pannello scorre sopra la tabella invece di restringerla */
  .mag.has-panel { grid-template-columns: minmax(0, 1fr); }
  .mag-panel { position: fixed; z-index: 20; top: 12px; right: 12px; bottom: 12px; width: min(460px, calc(100vw - 280px)); max-height: none; box-shadow: var(--shadow-pop); }
  .mag .grid :is(.col-sup, .col-weight) { display: none; }
}

/* ---- Scheda articolo ---- */
.article-page { display: grid; gap: 0; }
.art-head { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 18px; }
.art-head .back { margin-left: -12px; }
.art-titles { flex: 1; min-width: 0; display: grid; gap: 8px; }
.art-code { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14.5px; }
.art-title { font: 600 28px/1.1 var(--font-d); letter-spacing: -.025em; overflow-wrap: anywhere; }
.art-title:focus { outline: none; }
.art-hero {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  padding: 20px 22px; border-radius: var(--r-lg); background: var(--surface-2); position: relative; overflow: hidden;
}
.article-page .art-hero { margin-bottom: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.art-hero.is-below { box-shadow: inset 0 4px 0 var(--below); }
.article-page .art-hero.is-below { box-shadow: inset 0 4px 0 var(--below), var(--shadow); }
.art-qty { display: flex; align-items: baseline; gap: 10px; }
.qty-big { font: 600 72px/0.9 var(--font-d); letter-spacing: -.04em; }
.art-hero .qty-unit { font-size: 19px; }
.art-hero.is-zero .qty-big { color: var(--out); }
.art-kpi { display: grid; grid-template-columns: auto auto; gap: 3px 16px; font-size: 14.5px; }
.art-kpi .kv { display: contents; }
.art-kpi dt, .art-kpi dd { padding: 0; border: 0; }
.art-kpi dt { color: var(--muted); }
.art-kpi dd { font-weight: 600; text-align: right; }
.art-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 6px; }
.art-actions .btn-secondary { grid-column: 1 / -1; }
.art-form { margin: 14px 0; padding: 18px; border-radius: var(--r-lg); background: var(--surface); box-shadow: inset 0 0 0 1px var(--ring-hover), var(--shadow); }
.art-sec { margin-top: 28px; }
.art-sec .sec-title { font-size: 19px; }
.art-foot { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.mag-panel .qty-big { font-size: 64px; }

/* ---- Modulo Arrivo / Uso ---- */
.move-form { display: grid; gap: 18px; }
.move-stock { color: var(--muted); }
.move-stock strong { color: var(--ink); font: 600 20px var(--font-d); }
.move-in .stepper-field { border-color: var(--in); }
.move-out .stepper-field { border-color: var(--out); }
.remnant { display: grid; gap: 10px; padding: 6px 16px 16px; border-radius: var(--r); background: var(--surface-2); }
.remnant-fields { display: grid; gap: 12px; }
.note .ico { flex: none; }

/* ---- Nuovo articolo / categorie ---- */
.article-form, .cat-form { max-width: 860px; }
.cat-fields:empty { display: none; }
.fields-editor { display: grid; gap: 12px; counter-reset: f; }
.field-row { display: flex; gap: 8px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.field-row-grid { flex: 1; display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field-checks { display: flex; gap: 4px 16px; flex-wrap: wrap; align-items: center; }
.field-row-tools { display: flex; flex-direction: column; gap: 2px; }
.cat-list, .sup-list, .user-list { display: grid; }
.cat-item, .sup-item, .user-item { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 0; border-bottom: 1px solid var(--line); }
.cat-item:last-child, .sup-item:last-child, .user-item:last-child { border-bottom: 0; }
.cat-item[data-depth="1"] { padding-left: 24px; }
.cat-item[data-depth="2"] { padding-left: 48px; }
.cat-item[data-depth="3"] { padding-left: 72px; }
.cat-item[data-depth]:not([data-depth="0"]) .cat-name::before { content: "↳ "; color: var(--muted); }
.cat-main, .sup-main, .user-main { display: grid; gap: 4px; min-width: 0; flex: 1 1 260px; }
.cat-name, .sup-name, .user-name { font: 600 18px var(--font-d); letter-spacing: -.015em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-meta, .sup-meta, .user-meta { color: var(--muted); font-size: 14px; }
.sup-count { color: var(--muted); font-size: 14px; }
.cat-actions, .user-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.user-actions select { width: auto; min-width: 170px; }
.is-archived { opacity: .6; }
.sup-list, .user-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0 20px; box-shadow: var(--shadow); }
.panel-sec .user-list { border: 0; padding: 0; box-shadow: none; }
.inline-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-top: 16px; }
.inline-form .field { flex: 1 1 180px; }
.inline-form .form-error { flex-basis: 100%; }
.mat-table td:first-child { font-weight: 500; }
.input-sm { max-width: 120px; margin-left: auto; text-align: right; }
.temp-pw { display: block; font: 600 28px var(--font-d); letter-spacing: .06em; padding: 16px; border-radius: var(--r); background: var(--tint); text-align: center; user-select: all; overflow-wrap: anywhere; }

/* ---- Movimenti ---- */
.filters-panel { margin-bottom: 14px; }
.filter-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }
@media (min-width: 900px) { .filters-panel:not(details) { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow); } }

/* ---- Riordino ---- */
.reorder-group { margin-bottom: 24px; }
.reorder-group .grid { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.reorder-group .grid tr.is-below td:first-child { box-shadow: inset 3px 0 0 var(--below); }
.reorder-group .grid td a { font-weight: 600; color: var(--ink); }

/* ---- Inventario ---- */
.inv-tools { display: grid; gap: 12px; margin-bottom: 16px; }
.inv-filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.inv-group { margin-bottom: 22px; }
.inv-rows { display: grid; gap: 10px; }
.inv-row {
  display: grid; gap: 10px 12px; align-items: center; padding: 14px 16px;
  grid-template-columns: 1fr auto; grid-template-areas: "art sys" "ok input" "st st";
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.inv-row.is-ok { box-shadow: inset 4px 0 0 var(--in), var(--shadow); }
.inv-row.is-diff { box-shadow: inset 4px 0 0 var(--below), var(--shadow); }
.inv-art { grid-area: art; display: grid; gap: 4px; min-width: 0; }
.inv-title { font: 600 17px/1.2 var(--font-d); letter-spacing: -.01em; }
.inv-meta { color: var(--muted); font-size: 14px; }
.inv-sys { grid-area: sys; display: grid; justify-items: end; }
.inv-sys-n { font: 600 30px/1 var(--font-d); letter-spacing: -.02em; }
.inv-sys-u { color: var(--muted); font-size: 13px; }
.inv-ok { grid-area: ok; min-height: var(--tap); }
.inv-ok.on { background: var(--in); color: var(--on-in); box-shadow: none; }
.inv-input { grid-area: input; min-height: var(--tap) !important; text-align: center; font: 600 24px var(--font-d) !important; width: 120px !important; }
.inv-status { grid-area: st; font-weight: 600; font-size: 15px; }
.inv-status:empty { display: none; }
.inv-status .ok { color: var(--in); display: inline-flex; gap: 4px; align-items: center; }
.inv-status .diff { color: var(--warn); }
.inv-status .ico { width: 18px; height: 18px; }
.inv-sticky {
  position: sticky; bottom: calc(var(--tabbar-h) + 8px); z-index: 5; display: flex; align-items: center; gap: 10px; justify-content: space-between;
  margin-top: 14px; padding: 8px 8px 8px 20px; border-radius: var(--pill); background: var(--dark); color: var(--on-dark); font-weight: 600; box-shadow: var(--shadow-pop);
}
.inv-bar {
  display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 18px 20px; margin-top: 18px; box-shadow: var(--shadow-pop);
}
.inv-summary { font-weight: 600; }
@media (min-width: 900px) {
  .inv-row { grid-template-columns: 1fr 110px 110px 130px 170px; grid-template-areas: "art sys ok input st"; }
  .inv-row .inv-status:empty { display: block; }
  .inv-ok { min-height: 44px; }
  .inv-input { min-height: 44px !important; font-size: 20px !important; }
  .inv-sticky { display: none; }
  .inv-bar { position: sticky; z-index: 5; bottom: 16px; grid-template-columns: 1fr minmax(260px, 360px) auto; align-items: end; }
  .inv-bar .form-error { grid-column: 1 / -1; }
}

/* ---- Import / export ---- */
.export-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.export-item { display: grid; gap: 12px; align-content: start; padding: 18px; border-radius: var(--r-lg); background: var(--surface-2); }
.export-item h3 { font: 600 17px var(--font-d); letter-spacing: -.01em; }
.export-borz { background: var(--tint); }
.export-item .actions > .btn { white-space: normal; text-align: left; flex: 0 1 auto; min-height: var(--ctl); padding-block: 8px; }
.mode-list { display: grid; gap: 10px; border: 0; padding: 0; margin: 0; }
.mode-list legend { font: 600 14px var(--font-d); letter-spacing: .02em; margin-bottom: 10px; }
.mode { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r); cursor: pointer; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.mode input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.mode-text { display: grid; gap: 2px; }
.mode-text strong { font: 600 15px var(--font-d); }
.mode-text span { color: var(--muted); font-size: 14.5px; }
.mode:has(input:checked) { background: var(--tint); box-shadow: inset 0 0 0 2px var(--indicator); }
.mode-danger:has(input:checked) { background: var(--out-bg); box-shadow: inset 0 0 0 2px var(--out); }
.grid tr.imp-error td { background: var(--out-bg); }

/* ---- Riepilogo ---- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.fig { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; position: relative; overflow: hidden; box-shadow: var(--shadow); transition: box-shadow .25s; }
.fig dt { color: var(--muted); font-size: 14px; }
.fig dd { font: 600 34px/1.1 var(--font-d); letter-spacing: -.03em; margin-top: 6px; }
.fig dd.fig-note { font: 400 13px var(--font); letter-spacing: 0; color: var(--muted); }
.fig-link { color: inherit; text-decoration: none; display: block; }
.fig-link:hover { color: inherit; }
.fig-link::after { content: ""; position: absolute; inset: 0; }
.fig:has(.fig-link):hover { box-shadow: var(--shadow-hover); }
.fig.is-below { box-shadow: inset 0 4px 0 var(--below), var(--shadow); }
.dash-grid { display: grid; gap: 20px; }
.dash-grid > *, .dash-col { min-width: 0; }
.dash-col { display: grid; gap: 0; }
.dash-col .panel-sec { overflow-x: auto; }
@media (max-width: 899px) { .panel-sec { padding: 18px 16px; } .panel-sec .grid th, .panel-sec .grid td { padding-inline: 8px; } }
@media (min-width: 1100px) { .dash-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.dash-moves .mv { grid-template-columns: 60px 1fr auto; }
.art-form .actions { flex-wrap: nowrap; }
.art-form .actions .btn[type="submit"] { flex: 1 1 auto; white-space: normal; text-align: left; }
.inv-row .field-error-added { grid-column: 1 / -1; }
