/* Giacenza & margini — foglio di stile unico */

:root {
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --field:     #fbfbfc;
  --border:    #e3e6eb;
  --border-strong: #cdd2da;
  --text:      #1c2129;
  --text-soft: #414855;
  --muted:     #6b7280;
  --placeholder: #b0b6c0;
  --accent:    #2563eb;
  --accent-dk: #1d4ed8;
  --ring:      rgba(37, 99, 235, .16);
  /* Freccia dei menu a discesa: il colore è nell'SVG, quindi cambia col tema. */
  --arrow:     url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%236b7280' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --arrow-on:  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%232563eb' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --on-accent: #ffffff;
  color-scheme: light;
  --ok:        #15803d;
  --ok-bg:     #eaf7ee;
  --warn:      #b45309;
  --warn-bg:   #fdf4e3;
  --err:       #b91c1c;
  --err-bg:    #fdecec;
  --b2c:       #7c3aed;
  --b2b:       #0e7490;
  --radius:    10px;
  --shadow:    0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #14171c;
    --surface: #1c2027;
    --field:   #171a20;
    --border:  #2c323b;
    --border-strong: #3d4550;
    --text:    #e6e9ee;
    --text-soft: #c3cad4;
    --muted:   #9aa3af;
    --placeholder: #656d7a;
    --accent:  #60a5fa;
    --accent-dk: #3b82f6;
    --ring:    rgba(96, 165, 250, .2);
    --arrow:    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%239aa3af' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    --arrow-on: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%2360a5fa' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    /* Su fondo azzurro chiaro il testo bianco non si legge: serve scuro. */
    --on-accent: #0c1626;
    color-scheme: dark;
    --ok:      #4ade80;
    --ok-bg:   #16281c;
    --warn:    #fbbf24;
    --warn-bg: #2a2413;
    --err:     #f87171;
    --err-bg:  #2b1717;
    --b2c:     #a78bfa;
    --b2b:     #22d3ee;
    --shadow:  0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* L'attributo hidden deve prevalere sui display dichiarati (griglie e flex). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

h1 { font-size: 26px; margin: 28px 0 6px; }
h2 { font-size: 17px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 22px 0 8px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.hint  { color: var(--muted); font-size: 13px; display: block; margin-top: 4px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.pos { color: var(--ok); }
.neg { color: var(--err); }

/* -------------------------------------------------------------- topbar */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-in { display: flex; align-items: center; gap: 20px; height: 58px; }
.brand { font-weight: 650; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a {
  padding: 7px 12px; border-radius: 7px; color: var(--muted); font-size: 14px;
}
.topbar nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.topbar nav a.on { background: var(--accent); color: var(--on-accent); }
.nav-toggle { display: none; }

/* --------------------------------------------------------------- blocchi */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px 0;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { margin: 0; }
.card-warn { border-color: var(--warn); border-left: 4px solid var(--warn); }
.card-warn h2 { color: var(--warn); }
.card-narrow { max-width: 560px; }
.card-login  { max-width: 380px; width: 100%; }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.cols-wide { grid-template-columns: 1fr 1fr; }
/* Form stretto a sinistra, tabella larga a destra. */
.cols-form { grid-template-columns: minmax(320px, 390px) 1fr; }
@media (max-width: 1000px) { .cols-form { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .cols, .cols-wide { grid-template-columns: 1fr; } }

.centered {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}

.empty {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 40px; text-align: center; margin: 24px 0;
}

.foot { color: var(--muted); font-size: 12px; padding: 30px 20px 40px; }

/* ------------------------------------------------------------- messaggi */

.alert {
  padding: 11px 14px; border-radius: 8px; margin: 12px 0;
  border: 1px solid transparent; font-size: 14px;
}
.alert-ok   { background: var(--ok-bg);   color: var(--ok);   border-color: currentColor; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: currentColor; }
.alert-err  { background: var(--err-bg);  color: var(--err);  border-color: currentColor; }
.alert a { color: inherit; text-decoration: underline; }

/* -------------------------------------------------------------- giacenze */

.stock-grid {
  display: grid; gap: 14px; margin: 18px 0;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.stock-card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stock-card.state-warn { border-left-color: var(--warn); }
.stock-card.state-ko   { border-left-color: var(--err); }
.stock-head h3 { margin: 0; font-size: 15px; }
.stock-head .sku { font-size: 12px; }
.stock-qty { font-size: 40px; font-weight: 650; line-height: 1.1; margin: 8px 0 6px; }
.stock-qty small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.stock-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; }

.sku { color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; font-weight: 500; }
.badge-ok   { background: var(--ok-bg);   color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-ko   { background: var(--err-bg);  color: var(--err); }
.badge-off  { background: var(--bg); color: var(--muted); }

.chip {
  display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 4px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
  vertical-align: middle; font-weight: 600; letter-spacing: .03em;
}
.chip-b2c { color: var(--b2c); border-color: currentColor; background: transparent; }
.chip-b2b { color: var(--b2b); border-color: currentColor; background: transparent; }

/* ------------------------------------------------------------------ KPI */

.kpi-row {
  display: grid; gap: 12px; margin: 16px 0;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 3px;
}
.kpi-accent { border-color: var(--accent); }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 23px; font-weight: 650; }
.kpi-sub   { font-size: 12px; color: var(--muted); }
.kpi-row-sm .kpi-value { font-size: 19px; }

/* ---------------------------------------------------------------- tabelle */

.table-wrap { overflow-x: auto; }
.table-scroll { max-height: 460px; overflow-y: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top;
}
.table thead th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface);
}
/* Gli importi non devono spezzarsi tra numero e simbolo. */
.table td.r, .table th.r { white-space: nowrap; }
.table tfoot th { border-top: 2px solid var(--border); border-bottom: none; font-size: 14px; color: var(--text); }
.table tbody tr:hover { background: var(--bg); }
.table-compact th, .table-compact td { padding: 6px 8px; font-size: 13.5px; }
.row-off  { opacity: .5; }
.row-warn { background: var(--warn-bg); }

/* Barra di ricerca sopra il catalogo Shopify. */
.cat-toolbar {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 14px;
}
.cat-toolbar input[type=search] { flex: 1 1 260px; max-width: 380px; }
.cat-toolbar .hint { margin: 0; white-space: nowrap; }

/* Tabella di abbinamento articoli: la colonna con i menu deve respirare. */
.match-table td { vertical-align: middle; }
.match-table select { min-width: 220px; }
.match-table td:first-child { max-width: 420px; }

.pager { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; }
.pager a { padding: 6px 11px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.pager a.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ------------------------------------------------------------------ form */

.form { display: flex; flex-direction: column; gap: 15px; }
.form label, .filters label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12.5px; font-weight: 550; color: var(--text-soft);
  letter-spacing: .005em;
}

/* Campi di testo, numerici e a discesa condividono la stessa base.
   L'esclusione dentro :where() copre anche gli input senza attributo type
   senza gonfiare la specificità, così le regole successive possono rifinirla. */
input:where(:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=hidden])),
select, textarea {
  font: inherit; font-size: 14px; width: 100%; height: 40px;
  padding: 0 12px; color: var(--text);
  background: var(--field); border: 1px solid var(--border); border-radius: 8px;
  transition: border-color .15s, box-shadow .15s, background .15s;
  appearance: none; -webkit-appearance: none;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }

input:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--border-strong); }

input:focus, select:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--ring);
}

input::placeholder { color: var(--placeholder); }
input:disabled, select:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }

/* Menu a discesa: freccia disegnata al posto di quella del sistema. */
select {
  padding-right: 34px; cursor: pointer;
  background-image: var(--arrow);
  background-repeat: no-repeat;
  background-position: right 13px center;
}
select:focus { background-image: var(--arrow-on); }

/* Selettore di data: icona più discreta, leggibile anche su fondo scuro. */
input[type=date] { cursor: pointer; }
input[type=date]::-webkit-calendar-picker-indicator {
  opacity: .45; cursor: pointer; transition: opacity .15s; padding: 4px; margin-right: -4px;
}
input[type=date]:hover::-webkit-calendar-picker-indicator { opacity: .9; }

/* Frecce del campo numerico: compaiono solo quando servono. */
input[type=number]::-webkit-inner-spin-button { opacity: 0; transition: opacity .15s; height: 30px; }
input[type=number]:hover::-webkit-inner-spin-button,
input[type=number]:focus::-webkit-inner-spin-button { opacity: .55; }

/* Selezione file: area tratteggiata con pulsante interno. */
input[type=file] {
  font: inherit; font-size: 13.5px; width: 100%; color: var(--muted);
  padding: 9px 12px; border-radius: 8px;
  background: var(--field); border: 1.5px dashed var(--border-strong);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
input[type=file]:hover { border-color: var(--accent); background: var(--surface); }
input[type=file]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--ring); }
input[type=file]::file-selector-button {
  font: inherit; font-size: 13.5px; font-weight: 500;
  margin-right: 12px; padding: 6px 14px; cursor: pointer;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  transition: background .15s, border-color .15s;
}
input[type=file]:hover::file-selector-button { border-color: var(--accent); color: var(--accent); }

/* Caselle di spunta ridisegnate. */
input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 19px; height: 19px; flex: 0 0 19px; margin: 0; padding: 0;
  border: 1.5px solid var(--border-strong); border-radius: 5px;
  background: var(--field); cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
input[type=checkbox]:hover { border-color: var(--accent); }
input[type=checkbox]:checked {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='9' viewBox='0 0 11 9'%3E%3Cpath d='M1 4.6 4 7.6 10 1.4' fill='none' stroke='%23fff' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center no-repeat;
  border-color: var(--accent);
}
input[type=checkbox]:focus-visible { outline: none; box-shadow: 0 0 0 3.5px var(--ring); }

.form label.check, .filters label.check, label.check {
  flex-direction: row; align-items: center; gap: 9px;
  color: var(--text); font-size: 14px; font-weight: 400; cursor: pointer;
}

/* Unità di misura affiancata al campo: <span class="f-unit" data-unit="€"> */
.f-unit { position: relative; display: block; }
.f-unit > input { padding-left: 32px; }
.f-unit::before {
  content: attr(data-unit);
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 14px; color: var(--muted); pointer-events: none;
}
.f-unit-r > input { padding-left: 12px; padding-right: 34px; }
.f-unit-r::before { left: auto; right: 13px; }
.f-unit:focus-within::before { color: var(--accent); }

fieldset {
  border: 1px solid var(--border); border-radius: 9px;
  padding: 16px 18px 18px; margin: 0 0 14px;
  display: flex; flex-direction: column; gap: 14px;
}
legend {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; padding: 0 7px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; flex-wrap: wrap; }

/* Blocco dei campi che compaiono solo per il carico merce. */
.row-carico { display: flex; flex-direction: column; gap: 13px; }

/* Margine calcolato in tempo reale sotto al prezzo. */
.margin-preview {
  margin: -4px 0 0; padding: 9px 12px; font-size: 13px;
  background: var(--field); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 0 7px 7px 0;
  color: var(--text-soft);
}
.margin-preview strong { color: var(--text); font-weight: 600; }
.margin-preview.is-neg { border-left-color: var(--err); }
.margin-preview.is-neg strong { color: var(--err); }
.static-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.static-field .label { color: var(--muted); }

/* In tema scuro l'icona nativa del calendario è nera: va schiarita. */
@media (prefers-color-scheme: dark) {
  input[type=date]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .5; }
  input[type=date]:hover::-webkit-calendar-picker-indicator { opacity: .85; }
}

.filters {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px;
}
.filters label { flex: 1 1 160px; }
.filters-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Selettore a segmenti (tipo di movimento). */
.seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--field); border: 1px solid var(--border); border-radius: 9px;
}
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 8px 8px; border-radius: 6px;
  font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg span:hover { color: var(--text); background: var(--surface); }
.seg input:checked + span {
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .15);
}
.seg input:focus-visible + span { box-shadow: 0 0 0 3.5px var(--ring); }

details.card summary { cursor: pointer; font-size: 15px; padding: 2px 0; }
details.card[open] summary { margin-bottom: 16px; }

.inline { display: inline; }
.steps { padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.9; }
.code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; font-family: ui-monospace, Consolas, monospace; font-size: 13px;
  overflow-x: auto; margin: 8px 0 0;
}

/* --------------------------------------------------------------- bottoni */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 14px; font-weight: 500;
  height: 40px; padding: 0 18px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer; text-align: center;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .06s;
}
.btn:hover { background: var(--bg); border-color: var(--border-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3.5px var(--ring); border-color: var(--accent); }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1);
}
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--field); color: var(--text); }
.btn-block { width: 100%; }

.link-del {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 15px; padding: 0 4px; line-height: 1;
}
.link-del:hover { color: var(--err); }

/* --------------------------------------------------------------- grafico */

.chart {
  display: flex; align-items: flex-end; gap: 6px; height: 180px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; gap: 6px; }
.bars { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; }
.bar { width: 42%; border-radius: 3px 3px 0 0; min-height: 2px; transition: opacity .15s; }
.bar-r { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.bar-m { background: var(--accent); }
.bar-group:hover .bar { opacity: .75; }
.bar-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

.legend { font-size: 12px; color: var(--muted); margin-top: 10px; display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-left: 10px; }
.key-r { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.key-m { background: var(--accent); }

/* ------------------------------------------------------------- responsive */

@media (max-width: 760px) {
  .nav-toggle {
    display: block; margin-left: auto; background: none; border: 1px solid var(--border);
    border-radius: 7px; font-size: 18px; padding: 4px 11px; color: var(--text); cursor: pointer;
  }
  .topbar-in { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; }
  .topbar nav { display: none; width: 100%; margin-left: 0; flex-direction: column; gap: 2px; }
  .topbar nav.open { display: flex; }
  h1 { font-size: 22px; }
  .stock-qty { font-size: 32px; }
}
