:root {
  --bg: #111111;
  --surface: #171717;
  --surface-2: #1e1e1e;
  --surface-3: #232529;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #ffffff;
  --muted: #999999;
  --accent: #afaf03;
  --accent-hover: #c4c40a;
  --on-accent: #111111;
  --danger: #ff6b5e;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --font-heading: "Instrument Sans", "DM Sans", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2 { font-family: var(--font-heading); font-weight: 600; letter-spacing: -0.02em; margin: 0; }

.site-header { padding: 24px 32px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.logo img { height: 34px; display: block; }

.container { max-width: 1200px; margin: 0 auto; padding: 48px 32px 96px; }

.hero { margin-bottom: 36px; }
.hero h1 { font-size: clamp(32px, 5vw, 56px); line-height: 1.1; font-weight: 500; }
.accent { color: var(--accent); }
.lead { color: var(--muted); font-size: 18px; margin: 14px 0 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px;
}

/* ---- Partenza / Destinazione ---- */
.locations { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.location h2, .parcels-title { font-size: 20px; margin-bottom: 14px; }

.location-box {
  display: flex;
  align-items: stretch;
  height: 64px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition: border-color .2s;
}
.location-box:focus-within { border-color: var(--accent); }

.country {
  position: relative;
  flex: 0 0 50%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 0 18px;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.flag { width: 26px; height: 18px; object-fit: cover; border-radius: 2px; flex: none; }
.country-name { flex: 1; text-transform: uppercase; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clear-country {
  background: none; border: 0; color: var(--muted); font-size: 24px; line-height: 1; padding: 4px; position: relative; z-index: 2;
}
.clear-country:hover { color: var(--text); }
.country-select {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%;
  background: var(--surface-3); color: var(--text);
}

.place { position: relative; flex: 1; display: flex; align-items: center; min-width: 0; }
.place-input {
  width: 100%; height: 100%; border: 0; background: transparent; outline: none;
  padding: 0 44px 0 18px; font-size: 17px;
}
.place-input::placeholder, .dims input::placeholder { color: var(--muted); }
.chevron { width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.place .chevron { position: absolute; right: 16px; }

.suggestions {
  position: absolute; top: calc(100% + 6px); left: -1px; right: -1px; z-index: 20;
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--radius);
  max-height: 300px; overflow-y: auto; box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.suggestions li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; }
.suggestions li .zip { color: var(--accent); font-variant-numeric: tabular-nums; min-width: 50px; }
.suggestions li .prov { color: var(--muted); margin-left: auto; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: rgba(255,255,255,.07); }

.link {
  background: none; border: 0; padding: 0; margin-top: 10px; color: var(--text);
  font-size: 15px; text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 4px;
}
.link:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ---- Colli ---- */
.parcels-title { margin-top: 40px; }
.parcel { display: grid; grid-template-columns: 300px 1fr auto; gap: 24px; align-items: center; margin-bottom: 14px; }

.parcel-type {
  position: relative; display: flex; align-items: center; gap: 16px; height: 72px;
  padding: 0 16px 0 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
}
.parcel-type:focus-within { border-color: var(--accent); }
.box-icon { width: 34px; height: 34px; fill: none; stroke: var(--text); stroke-width: 1.4; stroke-linejoin: round; flex: none; }
.type-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.type-text small { text-transform: uppercase; font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.type-select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; outline: none;
  font-size: 17px; padding: 0; cursor: pointer; width: 100%;
}
.type-select::after { content: none; }
.type-select:focus { outline: none; }
.type-select option { background: var(--surface-3); }
.parcel-type::after { content: ""; position: absolute; inset: 0; pointer-events: none; }

.dims {
  display: grid; grid-template-columns: repeat(4, 1fr); height: 72px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); overflow: hidden;
}
.dims input {
  border: 0; border-left: 1px solid var(--border); background: transparent; outline: none;
  padding: 0 18px; font-size: 17px; min-width: 0;
}
.dims input:first-child { border-left: 0; }
.dims input:focus { background: rgba(175,175,3,.08); }
.dims input.invalid { background: rgba(255,107,94,.1); }

.parcel-action {
  display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0;
  font-size: 22px; white-space: nowrap;
}
.parcel-action .circle {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--accent); color: var(--accent);
  display: grid; place-items: center; font-size: 22px; line-height: 1; transition: background .2s, color .2s;
}
.parcel-action:hover .circle { background: var(--accent); color: var(--on-accent); }
.parcel-action.remove .circle { border-color: var(--border-strong); color: var(--muted); }
.parcel-action.remove:hover .circle { background: var(--danger); border-color: var(--danger); color: var(--text); }
.parcel-action.remove .txt { font-size: 16px; color: var(--muted); }

.form-error { color: var(--danger); margin: 18px 0 0; }

/* ---- Bottone principale (stile .rr-btn axislab) ---- */
.btn-primary {
  position: relative; overflow: hidden; width: 100%; margin-top: 32px; height: 76px;
  border: 1px solid var(--accent); border-radius: 100px; background: var(--accent); color: var(--on-accent);
  font-size: 22px; font-weight: 500; letter-spacing: -0.02em; z-index: 0;
}
.btn-primary::before {
  content: ""; position: absolute; inset: 0; background: var(--text); transform: translateY(101%);
  transition: transform .5s cubic-bezier(.2,.7,.2,1); z-index: -1;
}
.btn-primary:hover::before { transform: translateY(0); }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-primary:disabled::before { transform: translateY(101%); }
.spinner {
  display: inline-block; width: 20px; height: 20px; margin-right: 10px; vertical-align: -3px;
  border: 2.5px solid rgba(17,17,17,.3); border-top-color: var(--on-accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Risultati ---- */
.results { margin-top: 56px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.results-head h2 { font-size: 30px; font-weight: 500; }
.sort { display: flex; gap: 8px; }
.chip {
  border: 1px solid var(--border-strong); background: transparent; border-radius: 100px; padding: 8px 18px; font-size: 15px;
}
.chip:hover { border-color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.provider-status { display: flex; gap: 10px; flex-wrap: wrap; margin: 20px 0 24px; }
.status {
  background: transparent;
  display: inline-flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 100px; color: var(--muted);
}
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.ok::before { background: var(--accent); }
.status.error::before { background: var(--danger); }
.status strong { color: var(--text); font-weight: 500; }
.status.off { cursor: pointer; }
.status.filtered { opacity: .45; text-decoration: line-through; }

.offers { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.offer {
  display: grid; grid-template-columns: 56px 1fr auto auto; gap: 20px; align-items: center;
  padding: 20px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  transition: border-color .2s;
}
.offer:hover { border-color: var(--border-strong); }
.offer.best { border-color: var(--accent); }
.carrier-logo {
  width: 56px; height: 56px; border-radius: 12px; background: var(--surface-3); display: grid; place-items: center;
  font-family: var(--font-heading); font-weight: 700; font-size: 15px; overflow: hidden; color: var(--text);
}
.carrier-logo img { max-width: 84%; max-height: 70%; object-fit: contain; }
/* Molti loghi hanno testo scuro su fondo trasparente: su tema scuro serve un fondo chiaro */
.carrier-logo.has-img { background: #ffffff; }
.offer-main { min-width: 0; }
.offer-title { font-size: 18px; font-weight: 500; }
.offer-title .service { color: var(--muted); font-weight: 400; }
.offer-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 4px; font-size: 14px; color: var(--muted); }
.offer-meta .via { color: var(--text); }
.badges { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.badge { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 3px 10px; border-radius: 100px; background: rgba(175,175,3,.15); color: var(--accent); }
.badge.demo { background: rgba(255,255,255,.08); color: var(--muted); }
.offer-time { text-align: right; color: var(--muted); font-size: 14px; white-space: nowrap; }
.offer-time strong { display: block; color: var(--text); font-size: 16px; font-weight: 500; }
.offer-price { text-align: right; min-width: 110px; }
.offer-price .amount { font-family: var(--font-heading); font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.offer-price small { display: block; color: var(--muted); font-size: 12px; }

.empty { color: var(--muted); padding: 32px; text-align: center; border: 1px dashed var(--border-strong); border-radius: 16px; }

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .parcel { grid-template-columns: 1fr; gap: 10px; margin-bottom: 24px; }
  .parcel-action { justify-self: start; font-size: 18px; }
}
@media (max-width: 820px) {
  .locations { grid-template-columns: 1fr; gap: 24px; }
  .offer { grid-template-columns: 48px 1fr auto; }
  .carrier-logo { width: 48px; height: 48px; }
  .offer-time { grid-column: 2; text-align: left; }
  .offer-time strong { display: inline; margin-right: 6px; }
  .offer-price { grid-row: 1; grid-column: 3; }
}
@media (max-width: 600px) {
  .site-header { padding: 18px 16px; }
  .container { padding: 32px 16px 64px; }
  .card { padding: 20px 16px; border-radius: 16px; }
  .location-box { flex-direction: column; height: auto; }
  .country { flex: none; height: 56px; border-right: 0; border-bottom: 1px solid var(--border); }
  .place { flex: none; height: 56px; }
  .dims { grid-template-columns: 1fr 1fr; height: auto; }
  .dims input { height: 56px; font-size: 16px; }
  .dims input:nth-child(3) { border-left: 0; }
  .dims input:nth-child(n+3) { border-top: 1px solid var(--border); }
  .btn-primary { height: 64px; font-size: 18px; }
  .offer { padding: 16px; gap: 12px; }
  .offer-price .amount { font-size: 22px; }
  .offer-price { min-width: 0; }
}
.location-box:has(.invalid) { border-color: var(--danger); }
.hint { margin: 8px 0 0; font-size: 14px; color: var(--accent); }

.quick-filters { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: -8px 0 24px; }
.filter-group { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.filter-label { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-right: 4px; }
.chip.filter { display: inline-flex; align-items: center; gap: 8px; }
.chip.filter .count { font-size: 12px; min-width: 20px; padding: 1px 6px; border-radius: 100px; background: rgba(255,255,255,.08); color: var(--muted); }
.chip.filter.active .count { background: rgba(17,17,17,.15); color: var(--on-accent); }
.chip.filter:disabled { opacity: .35; cursor: not-allowed; }
@media (max-width: 600px) {
  .filter-group { width: 100%; }
  .filter-label { width: 100%; }
}

/* ---- Utente e login ---- */
.user-box { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-box[hidden] { display: none; }
.user-email { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.login-wrap { min-height: calc(100vh - 90px); display: grid; place-items: center; padding: 32px 16px; }
.login-card { width: 100%; max-width: 460px; text-align: center; }
.login-card h1 { font-size: 34px; font-weight: 500; line-height: 1.15; }
.google-button { display: flex; justify-content: center; margin-top: 28px; min-height: 44px; }
@media (max-width: 600px) { .user-email { display: none; } }
