:root {
  --blue: #061ab1;
  --blue-dark: #04107a;
  --blue-light: #c9d3f5;
  --link: #2f6fe4;
  --yellow: #ffd100;
  --yellow-soft: #fbe58c;
  --bg: #eef1f7;
  --card: #fff;
  --text: #1c2233;
  --muted: #6b7489;
  --line: #e2e6ef;
  --row-alt: #f6f8fc;
  --red: #d93636;
  --green: #1f9d55;
  --amber: #d9a400;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(10, 20, 60, .08), 0 4px 16px rgba(10, 20, 60, .06);
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px; background: var(--blue); color: #fff;
  display: flex; align-items: center; padding: 0 28px; gap: 32px;
  position: sticky; top: 0; z-index: 20;
}
.brand { color: #fff; font-weight: 700; font-size: 20px; letter-spacing: .2px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-sub { font-size: 12px; font-weight: 400; opacity: .8; margin-left: 10px; }
.mainnav { display: flex; align-items: stretch; height: 100%; margin-left: auto; gap: 4px; }
.mainnav a {
  color: #fff; display: flex; align-items: center; padding: 0 16px; font-size: 16px;
  border-radius: 0 0 4px 4px;
}
.mainnav a:hover { text-decoration: none; background: rgba(255, 255, 255, .1); }
.mainnav a.active { background: #fff; color: var(--blue); }
.nav-sep { width: 1px; background: rgba(255, 255, 255, .3); margin: 12px 12px; }
.account { margin-left: auto; font-size: 15px; white-space: nowrap; }

/* ---------- sub bar ---------- */
.subbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 28px;
  background: #f2f4f8; border-bottom: 1px solid var(--line);
}
.select-box {
  min-width: 260px; padding: 9px 14px; border: 1px solid #ccd3e0; border-radius: 4px; background: #fff;
  font-weight: 600; color: var(--blue-dark); position: relative;
}
.select-box::after { content: "▾"; position: absolute; right: 12px; color: var(--blue); }
.select-box.wide { min-width: 300px; }
.subbar-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 6px; }
.icon-btn {
  width: 42px; height: 38px; border: 1px solid #ccd3e0; background: #fff; border-radius: 4px;
  display: grid; place-items: center;
}
.icon-btn svg { width: 20px; height: 20px; fill: var(--blue); }
.icon-btn:hover { background: #eef2ff; }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
.btn-outline {
  padding: 8px 18px; border: 1px solid #ccd3e0; background: #fff; border-radius: 4px; color: var(--blue-dark);
}
.btn-outline:hover { background: #eef2ff; }
.actions-btn { background: none; border: 0; color: var(--blue); font-size: 20px; font-weight: 600; padding: 6px 12px; }
.caret { font-size: 14px; }

.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 280px; background: #fff;
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 0; z-index: 30; border: 1px solid var(--line);
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 16px; color: var(--text);
}
.dropdown-menu button:hover { background: #eef2ff; }
.dropdown-menu button.danger { color: var(--red); }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.banner {
  margin: 14px 28px 0; padding: 10px 16px; border-radius: var(--radius);
  background: #fff4cc; border: 1px solid #f0d36b; color: #6b5300;
}

main { padding: 18px 28px 40px; }

/* ---------- channel card + stepper ---------- */
.channel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 6px solid var(--blue);
}
.channel-head { display: flex; align-items: center; gap: 22px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.carrier-box {
  width: 96px; height: 96px; background: var(--blue); border-radius: 4px; display: grid; place-items: center;
  outline: 3px solid #fff; outline-offset: -8px;
}
.carrier-box svg { width: 54px; height: 54px; fill: var(--yellow); }
.channel-title h1 { margin: 0 0 6px; font-size: 30px; font-weight: 600; letter-spacing: .3px; }
.channel-title small { color: var(--muted); }

.step-wrap { --gap: 150px; display: flex; gap: var(--gap); margin-left: auto; }
.step { display: flex; flex-direction: column; align-items: center; width: 130px; background: none; border: 0; padding: 0; position: relative; }
.step + .step::before {
  content: ""; position: absolute; top: 32px; right: 50%; width: calc(100% + var(--gap)); height: 2px; background: var(--line); z-index: 0;
}
.step-circle {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; border: 2px solid var(--line); transition: all .2s; position: relative; z-index: 1;
}
.step.active .step-circle { border-color: var(--blue); background: var(--blue-light); }
.step.done .step-circle { background: var(--blue); border-color: var(--blue); color: #fff; }
.step-label { margin-top: 10px; font-size: 14px; font-weight: 600; text-align: center; color: var(--muted); }
.step.active .step-label { color: var(--blue-dark); }
.step.done .step-label { color: var(--blue); }

.items { width: 100%; border-collapse: collapse; margin-top: 4px; }
.items td, .items th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.warn-list { margin: 0 0 16px; padding: 10px 14px 10px 30px; border-radius: var(--radius); background: #fff6f6; border: 1px solid #f6caca; }
.warn-list li.soft { color: #806200; }
.address-suggestions { margin: 0 0 16px; padding: 12px; border: 1px solid #e8c85c; border-radius: var(--radius); background: #fffaf0; }
.address-suggestions h4 { margin: 0 0 6px; color: var(--blue-dark); }
.address-suggestions p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.address-suggestions-list { display: grid; gap: 8px; }
.address-suggestion { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; }
.address-suggestion span { min-width: 0; overflow-wrap: anywhere; }
.section-label { grid-column: span 6; font-weight: 700; color: var(--blue-dark); margin-top: 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }

/* ---------- toast / loader ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 70; max-width: 420px; }
.toast { background: #1d2440; color: #fff; padding: 12px 16px; border-radius: 6px; box-shadow: var(--shadow); animation: slidein .2s ease-out; white-space: pre-line; }
.toast.ok { background: #136c3b; }
.toast.err { background: #a62626; }
#loader { position: fixed; inset: 0; background: rgba(255, 255, 255, .6); z-index: 60; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--blue-dark); font-weight: 600; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--blue-light); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }

/* ---------- account switcher ---------- */
button.select-box { text-align: left; cursor: default; font: inherit; font-weight: 600; }
.account-dd.switchable button.select-box { cursor: pointer; }
.account-dd.switchable button.select-box:hover { border-color: var(--blue); }
.account-dd:not(.switchable) button.select-box::after { content: ""; }
.account-menu { min-width: 320px; max-height: 70vh; overflow: auto; }
.account-menu input { width: calc(100% - 20px); margin: 6px 10px 6px; padding: 8px 10px; border: 1px solid #ccd3e0; border-radius: 4px; }
.account-menu .acc-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.account-menu .acc-item.current { background: #eef2ff; font-weight: 600; }
.account-menu .acc-item small { color: var(--muted); font-weight: 400; }
.banner.warn { background: #fdecec; border-color: #f2b8b8; color: #8a1f1f; }
.banner a { font-weight: 600; }
.pw-set { color: var(--green); font-size: 12px; font-weight: 600; }

/* ---------- user menu ---------- */
.account { margin-left: auto; }
.user-dd { margin-left: 18px; }
.user-btn {
  display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .25);
  color: #fff; border-radius: 20px; padding: 4px 12px 4px 4px;
}
.user-btn:hover { background: rgba(255, 255, 255, .2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--yellow); color: var(--blue-dark); display: grid; place-items: center; font-weight: 700; font-size: 13px; text-transform: uppercase; }
.dropdown-menu.right { left: auto; right: 0; min-width: 220px; }
.dd-info { padding: 8px 16px; color: var(--text); }
.dd-info b { display: block; }
.dd-info span { color: var(--muted); font-size: 12px; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--blue) 0%, var(--blue-dark) 55%, #020a4a 100%); }
.login-wrap { width: min(400px, 92vw); }
.login-brand { display: flex; align-items: center; gap: 16px; color: #fff; margin-bottom: 22px; }
.carrier-box.small { width: 60px; height: 60px; outline-offset: -6px; outline-width: 2px; border: 0; }
.carrier-box.small svg { width: 34px; height: 34px; }
.login-title { font-size: 26px; font-weight: 700; }
.login-sub { opacity: .8; }
.login-card { background: #fff; border-radius: 10px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { margin: 0; font-size: 22px; color: var(--blue-dark); }
.login-card .field input { padding: 11px 12px; font-size: 15px; }
.login-btn { padding: 12px; font-size: 16px; }
.login-error { background: #fde2e2; color: var(--red); border-radius: 4px; padding: 9px 12px; font-size: 13px; }
.login-note { margin: 0; text-align: center; }

/* ---------- utenti ---------- */
.users-table td, .users-table th { padding: 10px 12px; }
.users-table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.users-table .actions .btn { padding: 5px 10px; font-size: 13px; }
.you { font-size: 11px; color: var(--muted); margin-left: 6px; }
.readonly-note { background: #eef2ff; border: 1px solid #cfd8ff; color: var(--blue-dark); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
  display: grid; place-content: center; z-index: 100;
}
.modal {
  background: #fff; border-radius: var(--radius); width: min(600px, 94vw);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.modal.sm { width: min(450px, 94vw); }
.modal-head {
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 18px; color: var(--blue-dark); }
.modal-close { background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px 24px; max-height: 60vh; overflow: auto; }
.modal-foot {
  padding: 12px 24px; border-top: 1px solid var(--line);
  background: #f9fafb; display: flex; justify-content: flex-end; gap: 8px;
}

/* ---------- buttons ---------- */
.btn {
  padding: 8px 16px; border-radius: 4px; font-weight: 600; border: 1px solid transparent; cursor: pointer;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn:hover { opacity: 0.9; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.s6 { flex: 0 0 100%; }
.field label { font-weight: 600; font-size: 14px; color: var(--text); }
.field input { padding: 8px 12px; border: 1px solid #ccd3e0; border-radius: 4px; }
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }
.hint { font-size: 12px; color: var(--muted); }

@media (max-width: 1200px) {
  .channel-head { flex-wrap: wrap; }
  .step-wrap { --gap: 40px; }
  .main-action { margin-left: auto; }
}

/* ---------- channel main action ---------- */
.main-action {
  padding: 8px 16px; background: var(--blue); color: #fff; border-radius: 4px; font-weight: 600; border: 0;
}

/* ---------- etichette filters ---------- */
.filters {
  display: flex; align-items: center; gap: 8px; padding: 12px 28px; background: #f8fafc; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.search { flex: 1; min-width: 200px; position: relative; display: grid; place-items: center; }
.search svg { position: absolute; left: 10px; fill: var(--muted); width: 16px; height: 16px; }
.search input { width: 100%; padding: 7px 12px 7px 36px; border: 1px solid #ccd3e0; border-radius: 4px; background: #fff; }
.chip-btn { padding: 6px 12px; border: 1px solid #ccd3e0; background: #fff; border-radius: 4px; font-size: 13px; color: var(--muted); }
.chip-btn:hover { background: #eef2ff; }
.count { font-size: 13px; color: var(--muted); margin-left: auto; }

/* ---------- grid (table) ---------- */
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th { text-align: left; padding: 10px 12px; background: #f9fafb; border-bottom: 2px solid var(--line); color: var(--text); }
.grid td { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.grid tr:hover { background: var(--row-alt); }
.grid tr.selected { background: #eef2ff; }
.grid .sort { font-size: 10px; margin-left: 4px; color: var(--muted); }
.grid .num { font-family: monospace; text-align: right; }
.grid .center { text-align: center; }
.grid .origin { color: var(--muted); font-size: 18px; }
.grid .cell-input { padding: 4px 8px; border: 1px solid var(--blue-light); border-radius: 4px; width: 100%; }
.grid .row-chk { width: 16px; height: 16px; margin: 0; }

.warn-ico { width: 18px; height: 18px; display: inline-grid; place-items: center; border-radius: 50%; font-size: 12px; font-weight: 700; }
.warn-ico.block { background: var(--red); color: #fff; }
.warn-ico.soft { background: var(--amber); color: #fff; }

/* ---------- badges & info ---------- */
.badge { padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge.blue { background: var(--blue-light); color: var(--blue-dark); }
.badge.green { background: #e6ffed; color: var(--green); }
.badge.red { background: #ffebee; color: var(--red); }
.badge.grey { background: #f0f0f0; color: var(--muted); }
.badge.amber { background: #fff4e6; color: var(--amber); }

/* ---------- impostazioni components ---------- */
.settings-page { max-width: 1440px; margin: 0 auto; }
.settings-page .page-title { margin: 0 0 20px; color: var(--blue-dark); font-size: 24px; }
.settings-page .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; align-items: start; }
.settings-page .card { min-width: 0; padding: 22px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.settings-page > .card { margin-bottom: 18px; }
.settings-page .card h2 { margin: 0 0 16px; color: var(--blue-dark); font-size: 19px; }
.settings-page .card p { line-height: 1.5; }
.settings-page .form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.settings-page .field { min-width: 0; grid-column: span 6; }
.settings-page .field.s1 { grid-column: span 1; }
.settings-page .field.s2 { grid-column: span 2; }
.settings-page .field.s3 { grid-column: span 3; }
.settings-page .field.s4 { grid-column: span 4; }
.settings-page .field.s6 { grid-column: span 6; }
.settings-page .field input, .settings-page .field select { width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid #ccd3e0; border-radius: 4px; background: #fff; }
.settings-page .field select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }
.settings-page .field :disabled { background: #f3f5f8; color: #596275; }
.settings-page .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.settings-page .row input { min-width: 0; }
.settings-page .check { grid-column: 1 / -1; display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
.settings-page .check input { margin: 3px 0 0; }
.settings-page .section-label { grid-column: 1 / -1; }
.settings-page .kv { grid-template-columns: minmax(75px, 120px) minmax(0, 1fr); }
.settings-page .kv dd { min-width: 0; overflow-wrap: anywhere; }
.settings-page .hint { line-height: 1.4; }
.settings-page .muted { color: var(--muted); }
.settings-page .small { font-size: 12px; }
.settings-page .btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
@media (max-width: 1100px) {
  .settings-page .cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .settings-page .card { padding: 16px; }
  .settings-page .form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-page .field.s1 { grid-column: span 1; }
  .settings-page .field.s2, .settings-page .field.s3, .settings-page .field.s4, .settings-page .field.s6 { grid-column: 1 / -1; }
  .settings-page .form > .row { grid-column: 1 / -1 !important; }
  .settings-page .field .row { flex-wrap: wrap !important; }
  .settings-page .field .row input { flex-basis: 100% !important; }
}
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px; margin: 16px 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; font-weight: 600; }
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: grid; place-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 20px; border-radius: 4px;
  color: #fff; font-weight: 500; z-index: 1000; box-shadow: var(--shadow);
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* ---------- extra utilities ---------- */
.order-link { color: var(--link); text-decoration: none; }
.order-link:hover { text-decoration: underline; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { background: var(--line); }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; background: rgba(255,255,255,0.7);
  display: grid; place-content: center; z-index: 1000;
}
#loader-text { font-weight: 600; color: var(--blue-dark); }

/* ---------- step refinements ---------- */
.step.active { background: #f0f4ff; border-radius: 4px; }
.step.has .step-circle { border: 2px solid var(--blue); }

/* ---------- pagina etichette ---------- */
.channel { min-width: 0; overflow: hidden; }
.channel-head { flex-wrap: wrap; gap: 16px 22px; }
.channel-head .carrier-box { flex: 0 0 72px; width: 72px; height: 72px; }
.channel-head .carrier-box svg { width: 42px; height: 42px; }
.channel-title { min-width: 0; }
.channel-title h1 { font-size: 24px; overflow-wrap: anywhere; }
.step-wrap { --gap: clamp(12px, 3vw, 48px); flex: 1 1 350px; justify-content: center; min-width: 0; margin-left: auto; }
.step { flex: 0 1 110px; min-width: 70px; padding: 4px; border-radius: 4px; }
.step-circle { width: 50px; height: 50px; font-size: 18px; font-weight: 700; }
.step + .step::before { top: 29px; }
.step-label { margin-top: 6px; }
.step:focus-visible, .main-action:focus-visible, .chip-btn:focus-visible { outline: 3px solid #8296ed; outline-offset: 2px; }
.main-action { min-width: 150px; line-height: 1.35; }
.main-action:disabled { background: #aeb9d3; cursor: not-allowed; }
.filters select { min-width: 110px; max-width: 100%; padding: 7px 28px 7px 10px; border: 1px solid #ccd3e0; border-radius: 4px; background: #fff; color: var(--text); font: inherit; }
.search { min-width: min(200px, 100%); }
.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.channel .grid { min-width: 1200px; }
.channel .grid th { white-space: nowrap; }
.channel .grid td { vertical-align: middle; }
.channel .grid .origin svg { display: block; width: 20px; height: 20px; fill: currentColor; }
.channel .grid .cell-input { min-width: 64px; }
.channel .grid .contract { min-width: 90px; }
.channel .grid .cliente { min-width: 140px; }
.channel .grid .empty { padding: 36px 20px; white-space: normal; }
.channel .grid .empty b { display: block; margin-bottom: 8px; color: var(--text); }
.channel .small { font-size: 12px; }
.channel .muted { color: var(--muted); }
@media (max-width: 900px) {
  .topbar { height: auto; min-height: 56px; flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .mainnav { order: 3; flex: 1 1 100%; height: auto; overflow-x: auto; }
  .mainnav a { padding: 9px 12px; font-size: 14px; white-space: nowrap; border-radius: 4px; }
  .nav-sep { margin: 4px; }
  .account { margin-left: auto; }
  .user-dd { margin-left: 0; }
  .subbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .subbar .select-box, .subbar .select-box.wide { min-width: 0; }
  .subbar .account-dd { flex: 1 1 200px; }
  .subbar .account-dd .select-box { width: 100%; }
  .subbar-sep { display: none; }
  main { padding: 16px 16px 32px; }
  .banner { margin: 12px 16px 0; }
}
@media (max-width: 640px) {
  .channel-head { padding: 16px; }
  .channel-title { flex: 1 1 180px; }
  .channel-title h1 { font-size: 20px; }
  .step-wrap { order: 3; flex-basis: 100%; --gap: 12px; }
  .main-action { order: 4; width: 100%; }
  .filters { padding: 12px 16px; }
  .search { flex-basis: 100%; }
  .filters select { flex: 1 1 110px; }
  .count { flex-basis: 100%; margin-left: 0; }
}
