/* ============================================================
   baywarp — base layout + component library
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4 { font-family: var(--font-display); font-weight: var(--display-weight, 600); margin: 0; line-height: var(--lh-tight); color: var(--text); letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.tnum { font-variant-numeric: tabular-nums; }
::selection { background: var(--accent-weak); }

/* scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ---------------- App frame ---------------- */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Sandbox strip */
.sandbox-strip {
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  background: var(--sandbox-bg); color: var(--sandbox-fg);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em;
  padding: 6px var(--s4); flex: 0 0 auto; position: relative; z-index: 60;
  border-bottom: 1px solid color-mix(in oklch, var(--sandbox-accent) 50%, transparent);
}
.sandbox-strip .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--sandbox-accent); box-shadow: 0 0 0 3px color-mix(in oklch, var(--sandbox-accent) 30%, transparent); animation: pulse 2.4s var(--ease) infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }
.sandbox-strip strong { font-weight: 700; }
.sandbox-strip .sb-link { text-decoration: underline; text-underline-offset: 2px; cursor: pointer; opacity: .9; }
.sandbox-strip .sb-link:hover { opacity: 1; }

.frame { display: flex; flex: 1 1 auto; min-height: 0; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  flex: 0 0 244px; width: 244px; background: var(--nav-bg); color: var(--nav-fg);
  border-right: 1px solid var(--nav-border); display: flex; flex-direction: column;
  min-height: 0; transition: flex-basis var(--dur) var(--ease), width var(--dur) var(--ease);
}
.sidebar .brand {
  display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5) var(--s4);
  height: 57px; flex: 0 0 auto; border-bottom: 1px solid var(--nav-border);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 15px;
  position: relative; overflow: hidden;
}
.brand-mark::after { content:""; position:absolute; inset:0; background: linear-gradient(135deg, rgba(255,255,255,.28), transparent 55%); }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); color: var(--nav-brand); letter-spacing: -0.02em; }
.brand-name b { font-weight: 700; }

.nav { flex: 1 1 auto; overflow-y: auto; padding: var(--s4) var(--s3) var(--s6); }
.nav-group { margin-bottom: var(--s5); }
.nav-group-label {
  font-size: var(--fs-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--nav-fg-muted); padding: 0 var(--s3) var(--s2); margin-top: var(--s2);
}
.nav-item {
  display: flex; align-items: center; gap: var(--s3); width: 100%; text-align: left;
  padding: 8px var(--s3); border-radius: var(--r-ctl); color: var(--nav-fg);
  background: transparent; border: 0; font-size: var(--fs-sm); font-weight: 500;
  position: relative; transition: background var(--dur), color var(--dur);
}
.nav-item .ico { flex: 0 0 18px; opacity: .82; }
.nav-item > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: color-mix(in oklch, var(--nav-active-bg) 55%, transparent); color: var(--nav-active-fg); }
.nav-item.active { background: var(--nav-active-bg); color: var(--nav-active-fg); font-weight: 600; }
.nav-item.active .ico { opacity: 1; }
.nav-item .nav-badge {
  margin-left: auto; font-size: var(--fs-2xs); font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; display: grid; place-items: center; background: var(--danger); color: #fff;
}
.nav-item.disabled { opacity: .45; cursor: not-allowed; }
.nav-item.disabled .soon { margin-left: auto; font-size: var(--fs-2xs); font-weight: 600; color: var(--nav-fg-muted); border: 1px solid var(--nav-border); padding: 1px 6px; border-radius: 99px; }

.sidebar .side-foot { flex: 0 0 auto; border-top: 1px solid var(--nav-border); padding: var(--s3); }
.acct {
  display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-ctl);
  width: 100%; background: transparent; border: 0; color: var(--nav-fg); text-align: left;
}
.acct:hover { background: color-mix(in oklch, var(--nav-active-bg) 50%, transparent); }
.avatar { width: 30px; height: 30px; border-radius: 99px; background: var(--accent-weak); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-xs); flex: 0 0 auto; }
.acct .meta { min-width: 0; }
.acct .meta .nm { font-size: var(--fs-sm); font-weight: 600; color: var(--nav-brand); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct .meta .role { font-size: var(--fs-2xs); color: var(--nav-fg-muted); }

/* ---------------- Main column ---------------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  flex: 0 0 auto; height: 57px; display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s6); border-bottom: 1px solid var(--border);
  background: var(--topbar-bg); color: var(--topbar-fg); backdrop-filter: blur(8px); position: relative; z-index: 30;
}
.topbar .crumbs { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-2); min-width: 0; }
.topbar .crumbs .sep { color: var(--text-3); }
.topbar .crumbs .cur { color: var(--topbar-fg); font-weight: 600; }

.search {
  margin-left: auto; position: relative; width: min(420px, 38vw);
}
.search input {
  width: 100%; height: 38px; border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 0 var(--s4) 0 38px; font-size: var(--fs-sm);
  transition: border var(--dur), box-shadow var(--dur);
}
[data-theme="notte"] .search input { background: color-mix(in oklch, var(--nav-bg) 70%, #000); border-color: var(--nav-border); color: var(--topbar-fg); }
.search input::placeholder { color: var(--text-3); }
[data-theme="notte"] .search input::placeholder { color: var(--nav-fg-muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.search .si { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-family: var(--font-mono);
  font-size: var(--fs-2xs); color: var(--text-3); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; background: var(--surface-2);
}
.topbar .tb-actions { display: flex; align-items: center; gap: var(--s2); }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r-ctl); border: 1px solid transparent; background: transparent;
  color: var(--topbar-fg); display: grid; place-items: center; position: relative; transition: background var(--dur), border var(--dur);
}
.icon-btn:hover { background: color-mix(in oklch, var(--text) 8%, transparent); }
[data-theme="notte"] .icon-btn:hover { background: color-mix(in oklch, #fff 12%, transparent); }
.icon-btn .ind { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 99px; background: var(--danger); border: 2px solid var(--topbar-bg); }

.env-pill {
  display: inline-flex; align-items: center; gap: var(--s2); height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em;
  background: var(--sandbox-bg); color: var(--sandbox-fg);
}
.env-pill .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--sandbox-accent); }

/* scroll body */
.page { flex: 1 1 auto; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
.page-inner { max-width: 1320px; margin: 0 auto; padding: var(--s7) var(--s7) var(--s10); }
.page-inner.wide { max-width: none; }

/* page header */
.page-head { display: flex; align-items: flex-start; gap: var(--s4); margin-bottom: var(--section-gap); flex-wrap: wrap; }
.page-head .ph-text { min-width: 0; }
.page-title { font-size: var(--fs-2xl); }
.page-sub { color: var(--text-2); font-size: var(--fs-md); margin-top: 6px; max-width: 64ch; text-wrap: pretty; }
.page-head .ph-actions { margin-left: auto; display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px; padding: 0 16px; border-radius: var(--r-ctl); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); font-weight: 600;
  white-space: nowrap; transition: background var(--dur), border var(--dur), box-shadow var(--dur), transform var(--dur);
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .ico { opacity: .8; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary .ico { opacity: 1; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: color-mix(in oklch, var(--text) 7%, transparent); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-lg { height: 44px; padding: 0 22px; font-size: var(--fs-md); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }

/* ---------------- Cards ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-1); }
.card-pad { padding: var(--card-pad); }
.card-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--card-pad); border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: var(--fs-md); font-weight: 600; }
.card-head .ch-actions { margin-left: auto; display: flex; gap: var(--s2); align-items: center; }
.card-head .ch-sub { font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; }

.grid { display: grid; gap: var(--s5); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px){ .grid-4{grid-template-columns:repeat(2,1fr)} .grid-3{grid-template-columns:repeat(2,1fr)} }
@media (max-width: 720px){ .grid-2,.grid-3,.grid-4{grid-template-columns:1fr} }

/* ---------------- Stat / KPI ---------------- */
.stat { display: flex; flex-direction: column; gap: var(--s2); padding: var(--card-pad); }
.stat .lbl { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.stat .lbl .ico { color: var(--text-3); }
.stat .val { font-family: var(--font-display); font-size: var(--fs-3xl); font-weight: var(--display-weight); letter-spacing: -0.02em; line-height: 1; }
.stat .val small { font-size: var(--fs-lg); color: var(--text-3); font-weight: 500; }
.stat .delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; }
.stat .delta.up { color: var(--ok-text); }
.stat .delta.down { color: var(--danger-text); }
.stat .sub { font-size: var(--fs-xs); color: var(--text-3); }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .02em; white-space: nowrap; border: 1px solid transparent;
}
.badge .bdot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.badge-accent { background: var(--accent-weak); color: var(--accent-text); }
.badge-ok { background: var(--ok-weak); color: var(--ok-text); }
.badge-warn { background: var(--warn-weak); color: var(--warn-text); }
.badge-danger { background: var(--danger-weak); color: var(--danger-text); }
.badge-info { background: var(--info-weak); color: var(--info-text); }
.badge-outline { background: transparent; border-color: var(--border-strong); color: var(--text-2); }

.chip { display:inline-flex; align-items:center; gap:6px; height: 26px; padding: 0 10px; border-radius: var(--r-pill); border:1px solid var(--border); background: var(--surface); font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.chip.active { background: var(--accent-weak); border-color: color-mix(in oklch, var(--accent) 40%, transparent); color: var(--accent-text); }
.chip button { border:0; background:transparent; color:inherit; display:grid; place-items:center; padding:0; opacity:.7; }
.chip button:hover { opacity:1; }

/* ---------------- Banners (alerts) ---------------- */
.banner { display: flex; gap: var(--s3); padding: var(--s4) var(--s4); border-radius: var(--r-card); border: 1px solid; align-items: flex-start; position: relative; }
.banner .b-age { position: absolute; top: var(--s4); right: var(--s4); font-size: var(--fs-2xs); color: var(--text-3); white-space: nowrap; }
.banner .b-body { padding-right: 56px; }
.banner .b-ico { flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center; margin-top: 1px; }
.banner .b-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.banner .b-title { font-weight: 700; font-size: var(--fs-sm); line-height: var(--lh-snug); }
.banner .b-text { font-size: var(--fs-sm); color: var(--text-2); text-wrap: pretty; }
.banner .b-actions { display: flex; gap: var(--s2); margin-top: var(--s2); flex-wrap: wrap; }
.banner-danger { background: var(--danger-weak); border-color: color-mix(in oklch, var(--danger) 30%, transparent); }
.banner-danger .b-ico { color: var(--danger); }
.banner-warn { background: var(--warn-weak); border-color: color-mix(in oklch, var(--warn) 35%, transparent); }
.banner-warn .b-ico { color: var(--warn-text); }
.banner-info { background: var(--info-weak); border-color: color-mix(in oklch, var(--accent) 25%, transparent); }
.banner-info .b-ico { color: var(--accent-text); }
.banner-ok { background: var(--ok-weak); border-color: color-mix(in oklch, var(--ok) 30%, transparent); }
.banner-ok .b-ico { color: var(--ok-text); }

/* ---------------- Tables ---------------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; background: var(--surface); }
.table-toolbar { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); flex-wrap: wrap; background: var(--surface); }
.table-scroll { overflow: auto; max-height: var(--table-h, none); }
table.grid-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.grid-table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); letter-spacing: .02em;
  padding: 10px var(--s3); border-bottom: 1px solid var(--border-strong); white-space: nowrap; user-select: none;
}
.grid-table thead th.sortable { cursor: pointer; }
.grid-table thead th .th-in { display: inline-flex; align-items: center; gap: 5px; }
.grid-table thead th .sort { opacity: .4; }
.grid-table thead th.sorted .sort { opacity: 1; color: var(--accent-text); }
.grid-table tbody td { padding: var(--cell-py) var(--s3); border-bottom: 1px solid var(--border); height: var(--row-h); vertical-align: middle; }
.grid-table tbody tr { transition: background var(--dur); }
.grid-table tbody tr:hover { background: var(--surface-2); }
.grid-table tbody tr.sel { background: var(--accent-weak); }
.grid-table tbody tr:last-child td { border-bottom: 0; }
.grid-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-table .col-thumb { width: 44px; }
.cell-thumb { width: 34px; height: 34px; border-radius: var(--r-xs); object-fit: cover; background: var(--surface-3); }
.cell-sku { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-2); }
.cell-strong { font-weight: 600; color: var(--text); }
.cell-sub { font-size: var(--fs-xs); color: var(--text-3); }
.table-foot { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-2); background: var(--surface); flex-wrap: wrap; }

/* checkbox */
.ckbx { width: 17px; height: 17px; border-radius: 5px; border: 1.5px solid var(--border-strong); background: var(--surface); display: inline-grid; place-items: center; transition: all var(--dur); flex:0 0 auto; }
.ckbx.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); text-wrap: pretty; }
.field .req { color: var(--danger-text); }
.input, .select, .textarea {
  width: 100%; min-height: 40px; border-radius: var(--r-ctl); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); padding: 9px 12px; font-size: var(--fs-sm); font-family: inherit;
  transition: border var(--dur), box-shadow var(--dur);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.textarea { resize: vertical; line-height: 1.45; }
.input.mono { font-family: var(--font-mono); }
.input-wrap { position: relative; }
.input-wrap .suffix { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: var(--fs-xs); color: var(--text-3); }
.seg { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: var(--r-ctl); gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: calc(var(--r-ctl) - 2px); font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* toggle */
.switch { width: 38px; height: 22px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background var(--dur); border:0; flex:0 0 auto; }
.switch::after { content:""; position:absolute; top:2px; left:2px; width:18px; height:18px; border-radius:99px; background:#fff; box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(16px); }

/* ---------------- Provenance (provenienza valori) ---------------- */
.prov { display: inline-flex; align-items: center; gap: 6px; }
.prov .pv { font-weight: 600; font-variant-numeric: tabular-nums; }
.prov-tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-2xs); font-weight: 600;
  padding: 1px 7px 1px 6px; border-radius: var(--r-pill); cursor: help; border: 1px dashed transparent; position: relative;
}
.prov-tag .ico { width: 11px; height: 11px; }
.prov-rule { background: var(--accent-weak); color: var(--accent-text); border-color: color-mix(in oklch, var(--accent) 35%, transparent); }
.prov-feed { background: var(--surface-3); color: var(--text-2); border-color: var(--border-strong); }
.prov-tag:hover { filter: brightness(.97); }
.prov-tag[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface); font-size: var(--fs-2xs); font-weight: 500; line-height: 1.4;
  padding: 7px 10px; border-radius: var(--r-sm); width: max-content; max-width: 260px; white-space: normal; text-align: left;
  box-shadow: var(--shadow-pop); z-index: 50; pointer-events: none;
}
.prov-tag[data-tip]:hover::before {
  content:""; position:absolute; bottom: calc(100% + 2px); left:50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--text); z-index: 50;
}

/* compare eBay <-> DB */
.cmp { display: inline-flex; align-items: center; gap: var(--s2); font-variant-numeric: tabular-nums; }
.cmp .from { color: var(--text-3); text-decoration: line-through; text-decoration-thickness: 1px; }
.cmp .arr { color: var(--text-3); }
.cmp .to { font-weight: 700; }
.cmp.diff .to { color: var(--accent-text); }
.cmp.match .eq { color: var(--ok-text); font-weight: 600; }

/* ---------------- Empty / loading ---------------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--s10) var(--s6); gap: var(--s4); }
.empty .e-art { width: 76px; height: 76px; border-radius: var(--r-lg); background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); }
.empty h3 { font-size: var(--fs-lg); }
.empty p { color: var(--text-2); max-width: 44ch; text-wrap: pretty; }

.skel { background: linear-gradient(100deg, var(--surface-3) 30%, var(--surface-2) 50%, var(--surface-3) 70%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s var(--ease); }
.spinner { width: 16px; height: 16px; border-radius: 99px; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Modal / drawer ---------------- */
.scrim { position: fixed; inset: 0; background: oklch(0.2 0.02 270 / 0.42); backdrop-filter: blur(2px); z-index: 100; display: grid; place-items: center; padding: var(--s6); animation: fade var(--dur) var(--ease); }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-pop); width: min(560px, 100%); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); animation: pop var(--dur) var(--ease); }
.modal.lg { width: min(880px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s5) var(--s5) var(--s4); border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: var(--fs-lg); }
.modal-head .x { margin-left: auto; }
.modal-body { padding: var(--s5); overflow-y: auto; }
.modal-foot { display: flex; gap: var(--s2); justify-content: flex-end; padding: var(--s4) var(--s5); border-top: 1px solid var(--border); background: var(--surface-2); }

/* drawer */
.drawer-scrim { position: fixed; inset: 0; background: oklch(0.2 0.02 270 / 0.4); z-index: 100; animation: fade var(--dur) var(--ease); }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 94vw); background: var(--surface); box-shadow: var(--shadow-pop); z-index: 101; display: flex; flex-direction: column; animation: slidein var(--dur) var(--ease); border-left: 1px solid var(--border); }
@keyframes slidein { from { transform: translateX(100%); } }

/* ---------------- Toast ---------------- */
.toast-stack { position: fixed; bottom: var(--s6); right: var(--s6); z-index: 200; display: flex; flex-direction: column; gap: var(--s3); width: 360px; max-width: calc(100vw - 32px); }
.toast { display: flex; gap: var(--s3); padding: var(--s4); border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-pop); align-items: flex-start; animation: toastin .26s var(--ease); }
@keyframes toastin { from { opacity: 0; transform: translateY(12px); } }
.toast .t-ico { flex: 0 0 auto; width: 20px; height: 20px; }
.toast.ok .t-ico { color: var(--ok-text); }
.toast.err .t-ico { color: var(--danger-text); }
.toast .t-title { font-weight: 700; font-size: var(--fs-sm); }
.toast .t-text { font-size: var(--fs-xs); color: var(--text-2); margin-top: 2px; }

/* ---------------- misc ---------------- */
.divider { height: 1px; background: var(--border); margin: var(--s5) 0; }
.kv { display: grid; grid-template-columns: minmax(120px,auto) 1fr; gap: var(--s2) var(--s5); font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 500; }
.muted { color: var(--text-3); }
.mt2{margin-top:var(--s2)} .mt3{margin-top:var(--s3)} .mt4{margin-top:var(--s4)} .mt5{margin-top:var(--s5)} .mt6{margin-top:var(--s6)}
.row { display: flex; align-items: center; gap: var(--s3); }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.tooltip-help { color: var(--text-3); cursor: help; }
.help-line { display:flex; gap: 8px; align-items:flex-start; font-size: var(--fs-xs); color: var(--text-2); background: var(--info-weak); border:1px solid color-mix(in oklch, var(--accent) 18%, transparent); padding: 10px 12px; border-radius: var(--r-ctl); text-wrap: pretty; }
.help-line .ico { color: var(--accent-text); flex:0 0 auto; margin-top:1px; }

/* section step header */
.steps { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-bottom: var(--section-gap); }
.step { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-3); }
.step .n { width: 24px; height: 24px; border-radius: 99px; display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 700; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.step.on { color: var(--text); font-weight: 600; }
.step.on .n { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.step.done .n { background: var(--ok-weak); color: var(--ok-text); border-color: color-mix(in oklch, var(--ok) 30%, transparent); }
.step-sep { width: 22px; height: 1px; background: var(--border-strong); }

@media (max-width: 920px) {
  .sidebar { position: fixed; z-index: 80; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform var(--dur) var(--ease); }
  .sidebar.open { transform: none; }
  .page-inner { padding: var(--s5) var(--s4) var(--s9); }
}

/* ============================================================
   LAYOUT: RAIL (sidebar a sole icone)
   ============================================================ */
[data-layout="rail"] .sidebar { flex-basis: 68px; width: 68px; }
[data-layout="rail"] .sidebar .brand { justify-content: center; padding-left: 0; padding-right: 0; }
[data-layout="rail"] .brand-name { display: none; }
[data-layout="rail"] .nav-group-label { text-align: center; padding: 0 0 var(--s2); font-size: 0; height: 1px; background: var(--border); margin: var(--s3) 12px var(--s3); }
[data-layout="rail"] .nav { padding-left: var(--s2); padding-right: var(--s2); }
[data-layout="rail"] .nav-item { justify-content: center; padding: 10px; position: relative; }
[data-layout="rail"] .nav-item > .grow,
[data-layout="rail"] .nav-item .nav-badge,
[data-layout="rail"] .nav-item .soon,
[data-layout="rail"] .nav-item > .muted { display: none; }
[data-layout="rail"] .nav-item.has-alert::after { content: ""; position: absolute; top: 6px; right: 12px; width: 8px; height: 8px; border-radius: 99px; background: var(--danger); border: 2px solid var(--nav-bg); }
[data-layout="rail"] .acct { justify-content: center; padding: var(--s2); }
[data-layout="rail"] .acct .meta, [data-layout="rail"] .acct > .ico { display: none; }
/* tooltip on hover */
[data-layout="rail"] .nav-item[title]:hover::before {
  content: attr(title); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--text); color: var(--surface); font-size: var(--fs-xs); font-weight: 600; padding: 5px 9px; border-radius: var(--r-sm);
  white-space: nowrap; z-index: 90; box-shadow: var(--shadow-pop); pointer-events: none;
}

/* ============================================================
   LAYOUT: TOPNAV (navigazione orizzontale in alto)
   ============================================================ */
.topnav { display: flex; align-items: center; gap: var(--s4); height: 58px; flex: 0 0 auto;
  padding: 0 var(--s5); background: var(--nav-bg); color: var(--nav-fg);
  border-bottom: 1px solid var(--nav-border); position: relative; z-index: 40; }
.topnav .brand { display: flex; align-items: center; gap: var(--s3); height: auto; border: 0; padding: 0; flex: 0 0 auto; }
.topnav .brand-name { white-space: nowrap; }
.topnav-links { display: flex; align-items: center; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topnav-links::-webkit-scrollbar { display: none; }
.topnav-links .nav-item { width: auto; white-space: nowrap; padding: 7px 12px; flex: 0 0 auto; }
.topnav-links .nav-item .nav-badge { margin-left: 6px; }
.topnav-links .nav-item.has-alert { position: relative; }
.topnav-links .nav-item[title]:hover::before {
  content: attr(title); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface); font-size: var(--fs-2xs); font-weight: 600; padding: 4px 8px; border-radius: var(--r-sm);
  white-space: nowrap; z-index: 90; box-shadow: var(--shadow-pop); pointer-events: none;
}
.topnav-right { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; }
.topnav-right .search { margin: 0; width: 172px; }
[data-layout="topnav"] .main { width: 100%; }
