/* Componenti riutilizzati da tutte le sezioni. */

/* ---------- Pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r-m);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: var(--fs-m); white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.07); }
.btn-ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn-danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-s { height: 30px; padding: 0 10px; font-size: var(--fs-s); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none;
  border: 0; border-radius: var(--r-m); background: none; color: var(--ink-3);
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); text-decoration: none; }
.icon-btn.on { color: #d69e00; }
.icon-btn.on .i { fill: currentColor; }
.icon-btn.danger:hover { color: var(--bad); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; }
.link-btn:hover { text-decoration: underline; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Campi ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: var(--fs-s); font-weight: 500; color: var(--ink-2); }
.field small { font-size: var(--fs-xs); color: var(--ink-3); }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
  width: 100%; height: 38px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: var(--r-m);
  background: var(--surface); color: var(--ink); font-size: var(--fs-m);
}
textarea { height: auto; min-height: 110px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { background: var(--surface-2); color: var(--ink-3); }
.input-euro { position: relative; }
.input-euro input { padding-right: 28px; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: var(--fs-l); }
.input-euro::after { content: '€'; position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.spacer { flex: 1; }
.form-error { color: var(--bad); font-size: var(--fs-s); }

/* Interruttore */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 11px; background: var(--line-strong); transition: background .15s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Selettore a segmenti */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-m); background: var(--sunken); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 0; border-radius: 6px; background: none; color: var(--ink-2); font-size: var(--fs-s); font-weight: 500; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg button b { font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.seg.full { display: flex; }
.seg.full button { flex: 1; justify-content: center; }

/* Filtri a pillola */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 15px; background: var(--surface);
  color: var(--ink-2); font-size: var(--fs-s); font-weight: 500; white-space: nowrap; cursor: pointer;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip b { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 600; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip.on b { color: inherit; opacity: .7; }
.chip.deal.on { background: var(--tag); border-color: var(--tag); color: var(--tag-ink); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
label.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
label.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Etichette */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px;
  border-radius: 4px; background: var(--sunken); color: var(--ink-2);
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge.wh { background: var(--wh-soft); color: var(--wh); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.vip { background: var(--tag-soft); color: #7a5800; }
:root[data-theme="dark"] .badge.vip { color: var(--tag); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.vip { color: var(--tag); } }
.badge.deal { background: var(--tag); color: var(--tag-ink); }
.asin { font-size: var(--fs-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; letter-spacing: .02em; }

/* Bandierine degli store */
.flag { display: inline-block; width: 18px; height: 12px; border-radius: 2px; overflow: hidden; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.12); vertical-align: -1px; }
.flag svg { display: block; width: 100%; height: 100%; }
.ali-mark { display: inline-flex; align-items: center; height: 16px; padding: 0 5px; border-radius: 3px; background: #e43225; color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .02em; }

/* ---------- Cartellino del prezzo (offerte sotto soglia) ---------- */
.tag {
  position: relative; display: inline-flex; flex-direction: column; align-items: flex-start;
  padding: 7px 16px 7px 22px; background: var(--tag); color: var(--tag-ink);
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
  border-radius: 0 4px 4px 0;
}
.tag::before { content: ''; position: absolute; left: 9px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--surface); }
.tag-price { font: 700 var(--fs-2xl)/1 var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tag-sub { font-size: var(--fs-xs); font-weight: 600; opacity: .8; margin-top: 3px; }
.tag.s { padding: 4px 10px 4px 17px; clip-path: polygon(8px 0, 100% 0, 100% 100%, 8px 100%, 0 50%); }
.tag.s::before { left: 7px; width: 4px; height: 4px; margin-top: -2px; }
.tag.s .tag-price { font-size: var(--fs-l); }

/* Prezzo normale (sopra soglia) */
.price { font: 600 var(--fs-l)/1.1 var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.price.l { font-size: var(--fs-xl); }
.price.none { color: var(--ink-3); font-weight: 500; font-family: var(--font); font-size: var(--fs-s); }

/* Distanza dalla soglia: barra con segno della soglia */
.gap { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; min-width: 0; }
.gap-bar { position: relative; height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.gap-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--ink-3); }
.gap-bar::after { content: ''; position: absolute; left: 66.6%; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .55; }
.gap.deal .gap-bar i { background: #d6a400; }
.gap.near .gap-bar i { background: var(--warn); }
.gap-val { font: 600 var(--fs-s)/1 var(--font-num); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; color: var(--ink-2); }
.gap.deal .gap-val { color: var(--ink); }

/* ---------- Pannello laterale ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(10, 14, 20, .38); }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(760px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow-lg);
  animation: panelIn .18s ease-out;
}
.panel.wide { width: min(980px, 100vw); }
@keyframes panelIn { from { transform: translateX(24px); opacity: .4; } }
.panel-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 22px 14px; border-bottom: 1px solid var(--line); }
.panel-titles { flex: 1; min-width: 0; }
.panel-kicker { font-size: var(--fs-xs); color: var(--ink-3); margin-bottom: 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-head h2 { font-size: var(--fs-xl); line-height: 1.25; }
.panel-tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.panel-tabs button {
  height: 42px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.panel-tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.panel-body { flex: 1; overflow-y: auto; padding: 20px 22px 28px; }
.panel-foot { display: flex; align-items: center; gap: 8px; padding: 12px 22px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface-2); }
.panel-foot:empty { display: none; }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

/* Sezioni dentro i pannelli e le impostazioni */
.block { display: flex; flex-direction: column; gap: 12px; padding: 18px 0; border-top: 1px solid var(--line); }
.block:first-child { border-top: 0; padding-top: 0; }
.block > h3 { font-size: var(--fs-m); }
.block-head { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.block-head h3 { font-size: var(--fs-m); }
.block-head .spacer + * { flex: none; }
.setting { display: flex; align-items: center; gap: 16px; padding: 10px 0; }
.setting + .setting { border-top: 1px dashed var(--line); }
.setting-text { flex: 1; min-width: 0; }
.setting-text b { display: block; font-weight: 500; }
.setting-text small { display: block; color: var(--ink-3); font-size: var(--fs-s); margin-top: 1px; }
/* Più specifico della regola generale dei campi (width: 100%), che altrimenti schiaccia il testo a zero */
.setting > input:not([type="checkbox"]):not([type="radio"]), .setting > select { width: 180px; flex: none; }
@media (max-width: 600px) {
  .setting { flex-wrap: wrap; gap: 8px 16px; }
  .setting > input:not([type="checkbox"]):not([type="radio"]), .setting > select { width: 100%; }
}
.fixed { font-size: var(--fs-xs); font-weight: 600; color: var(--ink-3); padding: 3px 8px; border: 1px solid var(--line); border-radius: 4px; white-space: nowrap; }

.note { padding: 11px 13px; border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-size: var(--fs-s); }
.note.warn { background: var(--warn-soft); border-color: transparent; color: var(--ink); }
.note.bad { background: var(--bad-soft); border-color: transparent; color: var(--ink); }
.note.ok { background: var(--ok-soft); border-color: transparent; color: var(--ink); }

/* ---------- Tabelle semplici ---------- */
.t { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.t th { text-align: left; font-weight: 500; color: var(--ink-3); padding: 0 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t .r { text-align: right; }
.t tr.off td { color: var(--ink-3); }

/* ---------- Ricerca rapida ---------- */
.palette { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; background: rgba(10, 14, 20, .38); }
.palette-box { width: min(620px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-l); box-shadow: var(--shadow-lg); overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); color: var(--ink-3); }
.palette-input input { border: 0 !important; box-shadow: none !important; height: 52px !important; padding: 0 !important; font-size: var(--fs-l) !important; background: none !important; }
.palette-list { overflow-y: auto; padding: 6px; }
.palette-group { padding: 10px 10px 4px; font-size: var(--fs-xs); color: var(--ink-3); font-weight: 600; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-m); cursor: pointer; min-width: 0; }
.palette-item.on { background: var(--sunken); }
.palette-item .pi-main { flex: 1; min-width: 0; }
.palette-item .pi-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item .pi-sub { font-size: var(--fs-xs); color: var(--ink-3); }
.palette-hint { padding: 8px 16px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--ink-3); }
.palette-empty { padding: 26px 16px; text-align: center; color: var(--ink-3); }

/* ---------- Conferma e avvisi ---------- */
.confirm { border: 0; border-radius: var(--r-l); padding: 22px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.confirm::backdrop { background: rgba(10, 14, 20, .45); }
.confirm p { margin-bottom: 18px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: var(--r-m); background: var(--ink); color: var(--paper); font-size: var(--fs-s); font-weight: 500; box-shadow: var(--shadow-lg); max-width: min(520px, calc(100vw - 32px)); }
.toast.bad { background: var(--bad); color: #fff; }
.toast-undo { position: relative; display: flex; align-items: center; gap: 14px; padding-right: 10px; overflow: hidden; pointer-events: auto; }
.toast-undo button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; padding: 4px 6px; border-radius: 4px; }
.toast-undo button:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
.toast-undo i { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--tag); transform-origin: left; animation: undoBar linear forwards; }
@keyframes undoBar { to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast-undo i { animation: none; opacity: .5; } }
@media (max-width: 860px) { .toasts { bottom: 86px; } }

/* ---------- Stati vuoti e caricamento ---------- */
.empty { padding: 34px 20px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: var(--fs-l); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.skel { display: flex; flex-direction: column; gap: 10px; }
.skel i { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--sunken), var(--surface-2), var(--sunken)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.skel i.h { height: 30px; width: 40%; margin-bottom: 10px; }
.skel i.row { height: 52px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel i { animation: none; } }

/* ---------- Grafico ---------- */
.chart { width: 100%; height: 200px; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--ink-3); font: 11px var(--font); }
.chart .l-new { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.chart .l-wh { fill: none; stroke: var(--wh); stroke-width: 1.6; }
.chart .l-th { stroke: #d6a400; stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-wrap { position: relative; }
.chart .cursor { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.chart .mark { stroke: var(--bad); stroke-width: 1.2; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.chart .hit { cursor: crosshair; }
.chart-tip {
  position: absolute; top: 6px; z-index: 2; min-width: 150px; padding: 8px 10px; border-radius: var(--r-m);
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow);
  font-size: var(--fs-xs); display: flex; flex-direction: column; gap: 3px; pointer-events: none;
}
.chart-tip b { font-weight: 600; }
.chart-tip span { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.chart-tip span b { margin-left: auto; color: var(--ink); }
.chart-tip i { width: 10px; height: 3px; border-radius: 2px; flex: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: var(--fs-xs); color: var(--ink-3); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* ---------- Accesso ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; border-radius: var(--r-l); background: var(--surface); box-shadow: var(--shadow); }
.login-card h1 { font-size: var(--fs-2xl); }
.login-card p { color: var(--ink-2); }
