/* Gestione PC — stile del sito, ispirato a Fluent (WinUI) come l'app desktop. */

:root {
  --bg: #f3f3f6;
  --surface: #ffffff;
  --surface-2: #f7f6fa;
  --surface-hover: #f0edf7;
  --border: #e3e1ea;
  --border-strong: #cfcbdb;
  --text: #1b1a1f;
  --muted: #615d6c;
  --faint: #8d8999;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: #efe7fd;
  --accent-text: #6d28d9;
  --on-accent: #ffffff;
  --ok: #0f7b3d;
  --ok-soft: #e3f4e9;
  --bad: #c42b1c;
  --bad-soft: #fde7e5;
  --warn: #9d5d00;
  --warn-soft: #fff4ce;
  --attention: #005fb8;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 6%);
  --radius: 8px;
  --sidebar: 228px;
  --topbar: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18171c;
    --surface: #222127;
    --surface-2: #29282f;
    --surface-hover: #302d39;
    --border: #36343e;
    --border-strong: #4a4755;
    --text: #f1eff5;
    --muted: #b2adbd;
    --faint: #85808f;
    --accent: #a78bfa;
    --accent-hover: #b9a1fb;
    --accent-soft: #352a4f;
    --accent-text: #c4b1fd;
    --on-accent: #1a1424;
    --ok: #6ccb8f;
    --ok-soft: #1f3528;
    --bad: #ff8f85;
    --bad-soft: #43221f;
    --warn: #f2c464;
    --warn-soft: #3d321b;
    --attention: #7fb6ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 26px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
p { margin: 0; }
a { color: var(--accent-text); }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.strong, strong { font-weight: 600; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.accent { color: var(--accent-text); }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; flex: none; }
.i.small { width: 14px; height: 14px; }

/* Utente in sola lettura: niente comandi di modifica. */
body.ro [data-w] { display: none !important; }

/* --- Controlli --- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 32px; padding: 5px 12px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text);
  font: inherit; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); }
.btn:active:not(:disabled) { transform: translateY(.5px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn .i { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.subtle { border-color: transparent; background: transparent; }
.btn.icon-only { width: 32px; padding: 0; }
.btn.icon-only.small, .btn.small.icon-only { width: 28px; min-height: 28px; }
.btn.small { min-height: 28px; padding: 3px 9px; font-size: 13px; }
.btn.wide { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-bottom-color: var(--faint);
  border-radius: 6px; padding: 6px 10px; min-height: 32px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; }
textarea { resize: vertical; }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span:first-child, .preview-header { font-size: 13px; color: var(--text); }
.field.narrow { max-width: 300px; }
.field.grow { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 32px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar.bottom { align-items: flex-end; }
.toolbar.nowrap { flex-wrap: nowrap; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { min-width: 170px; }
.filters .field.grow { max-width: 320px; }

/* --- Struttura --- */

#app.booting { display: grid; place-items: center; height: 100%; }

.shell {
  display: grid; width: 100%; height: 100vh; height: 100dvh;
  grid-template-columns: var(--sidebar) 1fr;
  grid-template-rows: var(--topbar) 1fr;
  grid-template-areas: "top top" "nav main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: var(--on-accent); }
.brand-mark .i { width: 16px; height: 16px; }
.topbar-user { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; font-size: 13px; }
.topbar-user small { color: var(--muted); font-size: 11px; }
.menu-toggle { display: none; }

.sidebar {
  grid-area: nav; display: flex; flex-direction: column; justify-content: space-between;
  padding: 10px 8px; overflow-y: auto; background: var(--bg);
}
.nav-main, .nav-footer { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 6px; color: var(--text); text-decoration: none;
}
.nav-item:hover { background: var(--surface-hover); }
.nav-item.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--accent);
}
.nav-item .i { color: var(--muted); }
.nav-item.active .i { color: var(--accent-text); }

.content { grid-area: main; overflow: auto; padding: 20px 28px 28px; outline: none; }
.page { display: flex; flex-direction: column; gap: 14px; max-width: 1500px; min-height: 100%; }
.page-title { display: flex; align-items: center; gap: 10px; }
.page-title .i { width: 26px; height: 26px; color: var(--accent-text); }
.totals { color: var(--muted); }
.scrim { display: none; }

/* --- 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: 32px 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 24px; }
.login-logo { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.login-logo .i { width: 28px; height: 28px; }

/* --- Banner e messaggi --- */

.infobar {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 8px 10px 14px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2);
}
.infobar > .i { margin-top: 1px; }
.infobar-text { flex: 1; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; min-height: 20px; }
.infobar .btn { margin: -4px 0; }
.infobar.success { background: var(--ok-soft); border-color: transparent; } .infobar.success > .i { color: var(--ok); }
.infobar.error { background: var(--bad-soft); border-color: transparent; } .infobar.error > .i { color: var(--bad); }
.infobar.warning { background: var(--warn-soft); border-color: transparent; } .infobar.warning > .i { color: var(--warn); }
.infobar.info > .i { color: var(--attention); }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; max-width: 420px;
  border-radius: 8px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: opacity .4s;
}
.toast.error .i { color: var(--bad); } .toast.success .i { color: var(--ok); }
.toast.hide { opacity: 0; }

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 48px 16px; color: var(--muted); text-align: center; }
.empty .i { width: 44px; height: 44px; color: var(--faint); }

/* --- Finestre di dialogo --- */

.dialog {
  width: min(480px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); box-shadow: 0 16px 48px rgb(0 0 0 / 28%);
}
.dialog.wide { width: min(640px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / 35%); }
.dialog form { display: flex; flex-direction: column; }
.dialog h2 { font-size: 20px; padding: 22px 24px 8px; }
.dialog-body { padding: 4px 24px 20px; display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow: auto; white-space: pre-wrap; }
.dialog-body .field, .dialog-body .form-grid { white-space: normal; }
.dialog-buttons { display: flex; gap: 8px; justify-content: flex-end; padding: 16px 24px; background: var(--surface-2); border-top: 1px solid var(--border); border-radius: 0 0 10px 10px; }
.dialog-buttons .btn { min-width: 110px; }
.form-grid { display: flex; flex-direction: column; gap: 12px; }

/* --- Tabelle --- */

.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.grid th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  text-align: left; font-weight: 400; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid:not(.static) tbody tr { cursor: default; user-select: none; }
table.grid tbody tr:hover { background: var(--surface-hover); }
table.grid tbody tr.selected { background: var(--accent-soft); }
table.grid tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
table.grid tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table.grid.static { table-layout: auto; }
th.sel, td.sel { text-align: center; }
/* Larghezze delle colonne (su <col>): "Dati tecnici" prende lo spazio che resta. */
col.sel { width: 44px; }
col.c-cat { width: 140px; }
col.c-desc { width: 24%; }
col.c-num { width: 110px; }
col.c-date { width: 100px; }
col.c-build { width: 180px; }
.c-num { text-align: right !important; }
.c-actions { width: 1%; text-align: right; white-space: nowrap; }
td.c-actions .btn { margin-left: 2px; }
.cat { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.cat .i { color: var(--accent-text); }
.cat span { overflow: hidden; text-overflow: ellipsis; }

/* Menu "Assegna a build" */
.menu-host { position: relative; }
.menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 260px; max-height: 60vh; overflow: auto;
  padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 4px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); outline: none; }
.menu-item span.i { display: inline-block; }

/* --- Editor --- */

.editor { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.editor h2 { font-size: 20px; margin-top: 4px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: end; }
.attributes { display: flex; flex-direction: column; gap: 12px; }
.attributes .field.narrow { max-width: 260px; }
.attributes > .field:not(.narrow) { max-width: 300px; }
fieldset.multi { border: 0; padding: 0; margin: 0; }
fieldset.multi legend { font-size: 13px; padding: 0; margin-bottom: 4px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 0 12px; }
.toolbar.actions { margin-top: 8px; }

/* --- Importa in blocco --- */

.bulk { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; min-height: 360px; }
.bulk .field { min-height: 0; }
textarea.code { flex: 1; font: 13px/1.5 Consolas, "Cascadia Mono", ui-monospace, monospace; white-space: pre; overflow: auto; min-height: 300px; }
.preview { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); padding: 0 12px; min-height: 300px; }
.preview-row { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.preview-line { display: flex; gap: 8px; align-items: baseline; }
.preview-line .line { color: var(--faint); }
.result { color: var(--muted); }

/* --- Vetrina --- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.card-head h2 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head span { font-size: 12px; }
.card-head .muted, .card .muted { color: var(--muted); }
.card-price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-price .price { font-size: 26px; font-weight: 600; }
dl.specs { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; margin: 0; }
dl.specs dt { font-size: 12px; color: var(--muted); padding-top: 2px; }
dl.specs dd { margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-check { font-size: 12px; }

/* --- Build --- */

.page-builds { max-width: none; height: 100%; }
.builds { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 24px; height: 100%; min-height: 0; }
.builds-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.build-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; min-height: 120px; }
.build-row {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 8px; text-align: left;
  border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; cursor: pointer; position: relative;
}
.build-row:hover { background: var(--surface-hover); }
.build-row.selected { background: var(--surface); box-shadow: var(--shadow); }
.build-row.selected::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 2px; background: var(--accent); }
.badge-icon { width: 36px; height: 36px; border-radius: 6px; display: grid; place-items: center; flex: none; background: var(--surface-2); }
.build-row-text { display: flex; flex-direction: column; min-width: 0; }
.build-row-text > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.build-detail { display: flex; flex-direction: column; gap: 12px; min-height: 0; min-width: 0; }
.detail-head { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
.detail-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.detail-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-line .i { width: 16px; height: 16px; }
.status-line .muted { color: var(--muted); }

.sale-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.sale-price { width: 150px; }
.sale-date { width: 160px; }
.margin { padding-bottom: 6px; }
.sale-row .field.grow { min-width: 220px; }
.sale-row textarea { min-height: 32px; max-height: 80px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 0; background: none; color: var(--muted);
  font: inherit; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

.parts-view { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; min-height: 0; }
.parts-view.single { grid-template-columns: 1fr; }
.parts-col { display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; }
.scroll { flex: 1; overflow: auto; min-height: 200px; padding-right: 6px; display: flex; flex-direction: column; gap: 8px; padding-bottom: 16px; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.issue { display: flex; gap: 8px; align-items: flex-start; }
.issue > .i { width: 16px; height: 16px; margin-top: 2px; }
.issue.ok { color: var(--ok); }
.issue.error > .i, .issue.error strong { color: var(--bad); }
.issue.missing > .i, .issue.missing strong { color: var(--warn); }
.issue.warning > .i, .issue.warning strong { color: var(--attention); }
.issue .dot { color: var(--faint); }

.row-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  min-height: 46px; padding: 5px 6px 5px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
}
.row-icon { display: grid; place-items: center; }
.row-text, .row-price { display: flex; flex-direction: column; min-width: 0; }
.row-text > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-price { align-items: flex-end; white-space: nowrap; }
.row-actions { display: flex; gap: 2px; min-width: 28px; justify-content: flex-end; }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }
.chip {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.chip:hover { background: var(--surface-hover); }
.chip.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.chip .i { width: 16px; height: 16px; }
.chip-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-badge { font-weight: 600; }
.chip-badge.ok { color: var(--ok); } .chip-badge.missing { color: var(--warn); } .chip-badge.optional { color: var(--muted); }

.photos-view { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.photos-area { flex: 1; overflow: auto; border: 2px dashed transparent; border-radius: 8px; min-height: 240px; }
.photos-area.drop { border-color: var(--accent); background: var(--accent-soft); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.photo {
  position: relative; margin: 0; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; background: var(--surface-2);
  cursor: grab; border: 2px solid transparent;
}
.photo.drop { border-color: var(--accent); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-badge { position: absolute; top: 6px; left: 6px; padding: 2px 8px; border-radius: 4px; font-size: 12px; background: var(--accent); color: var(--on-accent); }
.photo-actions { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 2px; padding: 2px; border-radius: 6px; background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(6px); }

/* --- Account --- */

dl.facts { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; margin: 0; max-width: 480px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.narrow-form { display: flex; flex-direction: column; gap: 12px; max-width: 380px; }

/* --- Schermi piccoli --- */

@media (max-width: 1100px) {
  .builds { grid-template-columns: 1fr; height: auto; }
  .page-builds { height: auto; }
  .build-list { max-height: 260px; }
  .parts-view { grid-template-columns: 1fr; }
  .scroll { overflow: visible; min-height: 0; }
  .detail-head { flex-direction: column; }
  .toolbar.nowrap { flex-wrap: wrap; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; z-index: 30; top: var(--topbar); bottom: 0; left: 0; width: 260px;
    background: var(--surface); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .18s;
  }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgb(0 0 0 / 30%); z-index: 25; }
  .content { padding: 16px; }
  h1 { font-size: 22px; }
  .row3, .bulk { grid-template-columns: 1fr; }
  .filters .field, .filters .field.grow { min-width: 0; max-width: none; flex: 1 1 100%; }
  /* Colonne meno importanti nascoste per intero (celle comprese), senza sfasare le altre. */
  col.c-sum, col.c-date, col.c-cat { visibility: collapse; width: 0; }
  col.c-desc { width: auto; }
  col.c-build { width: 110px; }
  .topbar-user small { display: none; }
}
