:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #dde1e6;
    --text: #1f2933;
    --muted: #616e7c;
    --accent: #ef7d00;      /* arancio XMAG */
    --accent-dark: #c96800;
    --nav: #232f3e;         /* blu Amazon */
    --ok: #1e8e3e;
    --warn: #b06000;
    --err: #c5221f;
    --info: #1a73e8;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, sans-serif; }
h1 { font-size: 22px; margin: 0 0 16px; }
h1:focus { outline: none; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--info); }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--nav); color: #d9dee4; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .brand { padding: 18px 20px; font-weight: 700; font-size: 17px; color: #fff; border-bottom: 1px solid #37475a; }
.sidebar .brand span { color: var(--accent); }
.sidebar nav { display: flex; flex-direction: column; padding: 8px 0; flex: 1; }
.sidebar nav a { color: #d9dee4; text-decoration: none; padding: 8px 20px; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: #2f3e50; }
.sidebar nav a.active { border-left-color: var(--accent); background: #2f3e50; color: #fff; }
.sidebar .nav-group { padding: 14px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8d99a6; }
.sidebar .version { padding: 12px 20px; font-size: 11px; color: #8d99a6; }
.content { flex: 1; padding: 20px 28px; min-width: 0; }

.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 14px; border-radius: 6px; margin-bottom: 18px; font-weight: 600; }
.banner.sandbox { background: #e8f0fe; color: #174ea6; }
/* Produzione: ben riconoscibile ma non rossa, il rosso resta per gli errori (banner .blocked) */
.banner.production { background: var(--nav); color: #fff; }
.banner .env-pill { padding: 1px 10px; border-radius: 10px; font-size: 12px; letter-spacing: .04em; }
.banner.production .env-pill { background: var(--accent); color: #fff; }
.banner.sandbox .env-pill { background: #c6dafc; color: #174ea6; }
.banner.blocked { background: #fce8e6; color: #a50e0e; border: 1px solid var(--err); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.stat { font-size: 26px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #eceff1; color: #37474f; white-space: nowrap; }
.badge.ok, .badge.Success, .badge.Published, .badge.Imported, .badge.Shipped { background: #e6f4ea; color: var(--ok); }
.badge.warn, .badge.Warning, .badge.Valid, .badge.Partial, .badge.Restricted, .badge.NotOnAmazon { background: #fef7e0; color: var(--warn); }
.badge.err, .badge.Failed, .badge.Blocked, .badge.Error, .badge.NoEan, .badge.EanInvalid, .badge.EanDuplicate { background: #fce8e6; color: var(--err); }
.badge.Running { background: #e8f0fe; color: var(--info); }
.badge.dry { background: #ede7f6; color: #5e35b1; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f0f2f5; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
td.msg { max-width: 520px; white-space: pre-wrap; word-break: break-word; font-size: 12px; }

.form { display: grid; grid-template-columns: 220px 1fr; gap: 10px 16px; align-items: center; max-width: 900px; }
.form label { font-weight: 600; }
.form .hint { grid-column: 2; font-size: 12px; color: var(--muted); margin-top: -6px; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
    width: 100%; padding: 6px 9px; border: 1px solid var(--border); border-radius: 5px; font: inherit; background: #fff;
}
textarea { min-height: 140px; font-family: Consolas, monospace; font-size: 12px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input[type=text], .inline select { width: auto; min-width: 160px; }

button, .btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 5px;
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { background: var(--accent-dark); }
button.secondary, .btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
button.secondary:hover { background: #f0f2f5; }
button.danger { background: var(--err); border-color: var(--err); }
button:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: none; color: var(--info); padding: 0; font-weight: normal; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.alert.ok { background: #e6f4ea; color: #0d652d; }
.alert.err { background: #fce8e6; color: #a50e0e; }
.alert.info { background: #e8f0fe; color: #174ea6; }
.btn-sm { padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
/* Azioni di riga: la principale in alto, quelle che cambiano lo stato separate e meno in evidenza */
.row-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 150px; }
.row-actions-secondary { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; padding-top: 6px;
    border-top: 1px dashed var(--border); width: 100%; font-size: 12px; }
button.link.muted-link { color: var(--muted); font-size: 12px; }
button.link.muted-link:hover { color: var(--err); }
/* Finestra modale (verifica su Amazon) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); z-index: 900; }
.modal { position: fixed; z-index: 901; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 48px); overflow-y: auto; background: var(--surface); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.25); outline: none; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-close { font-size: 18px; color: var(--muted); }
.modal-body { display: grid; grid-template-columns: 220px 1fr; gap: 18px; padding: 16px 18px; }
.modal-photo { display: flex; align-items: flex-start; justify-content: center; }
.modal-photo img { max-width: 100%; max-height: 260px; border: 1px solid var(--border); border-radius: 8px; background: #fff; object-fit: contain; }
.no-photo { width: 100%; height: 180px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); font-size: 12px; }
.modal-info .item-name { font-weight: 600; margin: 4px 0 8px; }
.facts { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; margin: 12px 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.modal-issues { padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-issues h3 { font-size: 14px; margin: 0 0 8px; }
.modal-issues .issue { margin-bottom: 8px; font-size: 13px; }
.modal-issues .hint { margin: 4px 0 0 4px; color: var(--muted); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
@media (max-width: 600px) { .modal-body { grid-template-columns: 1fr; } .facts { grid-template-columns: 1fr; } }

/* Guida */
.guide { max-width: 980px; }
.guide section { scroll-margin-top: 16px; }
.guide h2 { font-size: 17px; }
.guide p, .guide li { line-height: 1.6; }
.guide table { margin: 8px 0 12px; border: 1px solid var(--border); }
.guide-toc ol { margin: 8px 0 0; padding-left: 20px; columns: 2; column-gap: 32px; }
@media (max-width: 700px) { .guide-toc ol { columns: 1; } }

/* Accesso */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--nav); padding: 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 10px; padding: 26px 28px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.auth-brand { font-weight: 700; font-size: 18px; margin-bottom: 14px; }
.auth-brand span { color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-weight: 600; margin-top: 6px; }
.auth-form button { margin-top: 14px; }
.user-box { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 20px; border-top: 1px solid #37475a; font-size: 13px; color: #fff; }
.user-box form { margin: 0; }
.user-box button.logout { color: #ffb366; font-size: 13px; }

/* Card con elenco di stati cliccabili (dashboard) */
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.stat-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stat-row { display: grid; grid-template-columns: 12px 1fr auto 14px; align-items: center; gap: 10px; padding: 10px 12px;
    color: var(--text); text-decoration: none; border-top: 1px solid var(--border); background: var(--surface); }
.stat-row:first-child { border-top: none; }
.stat-row:hover { background: #f4f7fb; }
.stat-row:focus-visible { outline: 2px solid var(--info); outline-offset: -2px; }
.stat-row .dot { width: 10px; height: 10px; border-radius: 50%; background: #b0bec5; }
.stat-row .label { font-weight: 500; }
.stat-row .count { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat-row .chev { color: var(--muted); font-size: 18px; line-height: 1; }
.stat-row.Published .dot, .stat-row.Imported .dot, .stat-row.Shipped .dot { background: var(--ok); }
.stat-row.Valid .dot, .stat-row.New .dot { background: var(--info); }
.stat-row.Restricted .dot, .stat-row.NotOnAmazon .dot, .stat-row.Partial .dot { background: #f0a500; }
.stat-row.Error .dot, .stat-row.EanInvalid .dot, .stat-row.EanDuplicate .dot, .stat-row.NoEan .dot, .stat-row.NotSelling .dot { background: var(--err); }
/* Riga "di cui non in vendita su Amazon": sotto Pubblicato, rientrata */
.stat-row.sub .label { font-weight: 400; padding-left: 14px; }
.err-text { color: var(--err); margin-top: 4px; }

/* Cerca su Amazon */
.modal.modal-wide { width: min(1100px, calc(100vw - 32px)); display: flex; flex-direction: column; max-height: calc(100vh - 48px); overflow: hidden; }
.modal-scroll { overflow-y: auto; flex: 1; }
.match-xmag { padding: 10px 18px; background: #f7f9fc; border-bottom: 1px solid var(--border); font-size: 13px; }
.match-progress { display: flex; align-items: center; gap: 10px; padding: 24px 18px 8px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.match-notes { padding: 10px 18px; }
.match-large { display: flex; align-items: center; gap: 14px; margin: 0 18px 12px; font-size: 13px; }
.match-large button { flex-shrink: 0; }
.match-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 0 18px 16px; }
.match-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 4px; background: var(--surface); }
.match-card.strong { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok) inset; }
.match-photo { height: 150px; display: flex; align-items: center; justify-content: center; background: #fff; }
.match-photo img { max-height: 150px; max-width: 100%; object-fit: contain; }
.match-photo .no-photo { height: 150px; }
.match-name { font-size: 12px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.match-badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.match-badges a.badge { text-decoration: none; }
.match-card button { margin-top: auto; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }

#blazor-error-ui { background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "Si è verificato un errore." }

@media (max-width: 800px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .content { padding: 16px; }
    .form { grid-template-columns: 1fr; }
    .form .hint { grid-column: 1; }
}

/* Pulizia account Amazon */
.cleanup-progress { display: flex; align-items: center; gap: 12px; }
.cleanup-progress span:nth-child(2) { flex: 1; }
.cleanup-groups { display: flex; flex-direction: column; gap: 6px; }

/* Crea scheda: anteprima */
.create-preview { display: grid; grid-template-columns: 240px 1fr; gap: 18px; padding: 12px 18px; }
.create-main { width: 100%; max-height: 300px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.create-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.create-thumbs img { width: 52px; height: 52px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.create-title { font-weight: 600; margin-bottom: 4px; }
.create-desc { color: var(--muted); }
.issue { margin-top: 2px; }
.issue.ERROR { color: var(--err); }
.issue.WARNING { color: #8a5a00; }
@media (max-width: 700px) { .create-preview { grid-template-columns: 1fr; } }
.create-needs { margin: 0 18px 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.create-needs h3 { margin: 0 0 4px; font-size: 14px; }
.create-needs select, .create-needs input[type=text] { width: 100%; }
.create-needs .need-scope { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); }
.create-needs button { margin-top: 10px; }

.category-target { border-color: var(--accent); }
.category-target .inline { flex-wrap: wrap; gap: 6px; }

.override-confirm { border: 1px solid var(--err); border-radius: 6px; padding: 8px; max-width: 320px; }
.override-confirm .inline { margin-top: 6px; }
