:root {
  --ink: #132130;
  --muted: #5a6b7d;
  --bg: #f2f4f7;
  --card: #ffffff;
  --line: #dbe2ea;
  --line-strong: #c3ccd6;
  --brand: #0a4f8f;
  --brand-ink: #073a69;
  --brand-soft: #e8f0f9;
  --accent: #e67e00;
  --accent-soft: #fff4e5;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --ok: #1d8a3c;
  --ok-soft: #e7f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(19, 33, 48, .06), 0 4px 16px rgba(19, 33, 48, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  padding-bottom: 96px;
}
[hidden] { display: none !important; }
h1, h2 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); }
h2 { font-size: 1.2rem; }
a { color: var(--brand); }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* Header */
.topbar { background: var(--brand-ink); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 1.05rem; letter-spacing: .01em; white-space: nowrap; }
.brand small { font-size: .78rem; opacity: .75; }
.session { display: flex; align-items: center; gap: 10px; font-size: .9rem; min-width: 0; }
.session > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; opacity: .9; }
.session .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.session .btn-ghost:hover { background: rgba(255,255,255,.1); }

.view { padding: 28px 0 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--brand); margin: 0 0 6px; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 46ch; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 0; }
.center { text-align: center; }
.req { color: var(--danger); }
.opt { color: var(--muted); font-weight: 400; font-size: .85em; }

/* Cards & form */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 0 0 16px;
}
fieldset.card { min-width: 0; }
legend {
  float: left; width: 100%;
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.08rem; margin-bottom: 8px; padding: 0;
}
legend + * { clear: both; }
.num {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: .85rem;
}
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; min-width: 0; }
label { font-weight: 600; font-size: .9rem; }
input, textarea, select {
  font: inherit; color: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(10, 79, 143, .2); border-color: var(--brand); }
input[readonly] { background: #f5f7fa; color: var(--muted); }
.invalid { border-color: var(--danger) !important; background: var(--danger-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-addr { display: grid; grid-template-columns: 110px 1fr 80px; gap: 0 12px; }

.error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 12px; font-size: .9rem; margin: 12px 0 0; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-ink); }
.btn-outline { background: #fff; color: var(--brand); border-color: var(--brand); }
.btn-outline:hover { background: var(--brand-soft); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line-strong); }
.btn-ghost:hover { background: #f1f4f7; color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-block { width: 100%; margin-top: 16px; padding: 12px; }
.danger { color: var(--danger); }
:focus-visible { outline: 3px solid rgba(10, 79, 143, .35); outline-offset: 2px; }

/* Login */
.login-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center; padding-top: 24px; }
.steps { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 14px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; color: var(--muted); font-size: .95rem; }
.steps strong { display: block; color: var(--ink); }
.steps span {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
}
.login-card { padding: 28px; }
.login-card input { font-size: 1.15rem; letter-spacing: .04em; padding: 12px 14px; margin-top: 6px; }

/* Address choices */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 12px; }
.choice {
  position: relative; display: block;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius);
  padding: 12px 14px 12px 40px; cursor: pointer; background: #fff;
  font-weight: 400; font-size: .9rem; color: var(--muted);
  transition: border-color .15s, background .15s;
}
.choice:hover { border-color: var(--brand); }
.choice input { position: absolute; left: 14px; top: 15px; width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.choice strong { display: block; color: var(--ink); font-size: .95rem; margin-bottom: 2px; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand) inset; }
.choice.self strong::after {
  content: "Spedisco io"; margin-left: 8px; font-size: .7rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--brand); background: #fff; border: 1px solid var(--brand);
  border-radius: 99px; padding: 1px 7px; vertical-align: 2px;
}
.choice-add {
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: transparent;
  color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; min-height: 76px;
}
.choice-add:hover { border-color: var(--brand); background: var(--brand-soft); }
.choice-grid.invalid-group .choice { border-color: var(--danger); }

/* Items */
.item { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 14px 0; background: #fbfcfd; }
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-num { font-weight: 700; color: var(--brand); }
.item-actions { display: flex; gap: 6px; }
.photos { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; align-items: stretch; }
.thumbs { display: contents; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #eef1f5; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { display: grid; place-items: center; height: 100%; font-size: .7rem; color: var(--muted); padding: 4px; text-align: center; word-break: break-all; }
.thumb button {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: rgba(19,33,48,.75); color: #fff; cursor: pointer; font-size: 15px; line-height: 1;
}
.dropzone {
  position: relative;
  display: flex; align-items: center; gap: 10px; min-height: 84px; padding: 10px 16px;
  border: 1.5px dashed var(--line-strong); border-radius: 8px; color: var(--brand); cursor: pointer;
  font-weight: 600; font-size: .9rem; background: #fff; flex: 1 1 220px;
}
.dropzone small { display: block; color: var(--muted); font-weight: 400; }
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; opacity: 0; }
.dropzone:focus-within { outline: 3px solid rgba(10, 79, 143, .35); }

/* Urgent toggle */
.urgent-toggle {
  position: relative;
  display: flex; gap: 14px; align-items: center; cursor: pointer; margin-top: 12px; background: #fff;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius); padding: 10px 14px; font-weight: 400;
}
.urgent-toggle strong { display: block; }
.urgent-toggle small { color: var(--muted); }
.urgent-toggle input { position: absolute; left: 16px; top: 50%; width: 1px; height: 1px; margin: 0; padding: 0; opacity: 0; }
.switch { flex: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line-strong); position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.urgent-toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.item:has(.urgent-toggle input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.item-num .tag-urgent { vertical-align: 1px; }
.urgent-toggle input:checked + .switch { background: var(--accent); }
.urgent-toggle input:checked + .switch::after { transform: translateX(18px); }
.urgent-toggle input:focus-visible + .switch { outline: 3px solid rgba(230, 126, 0, .4); outline-offset: 2px; }

/* Submit bar */
.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(19,33,48,.06);
}
.submit-inner { display: flex; align-items: center; gap: 16px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.submit-inner #summary { margin: 0; color: var(--muted); font-size: .9rem; flex: 1 1 auto; }
.submit-inner .error { margin: 0; flex-basis: 100%; order: -1; }
.privacy { text-align: center; }

/* Result */
.result-head { display: flex; gap: 16px; align-items: center; border-left: 4px solid var(--ok); }
.result-head p { margin: 0; color: var(--muted); }
.result-head h1 { margin-bottom: 4px; }
#res-number { white-space: nowrap; }
.check { flex: none; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); }
.table-wrap { overflow-x: auto; margin: 8px -4px 0; }
table.quote { width: 100%; border-collapse: collapse; font-size: .92rem; }
.quote th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 6px; border-bottom: 2px solid var(--line); }
.quote td { padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.quote td small { display: block; color: var(--muted); }
.quote .num-col { text-align: right; white-space: nowrap; }
.quote tfoot td { border: 0; padding: 6px; }
.quote tfoot .total td { font-size: 1.1rem; font-weight: 700; border-top: 2px solid var(--line); padding-top: 10px; }
.pending { display: inline-block; font-size: .8rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 2px 10px; white-space: normal; text-align: center; }
.tag-urgent { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--accent); color: #fff; border-radius: 99px; padding: 2px 9px; vertical-align: 4px; margin-left: 6px; }
.notice { border-radius: 8px; padding: 12px 14px; margin-top: 14px; font-size: .92rem; }
.notice.info { background: var(--brand-soft); }
.notice.warn { background: var(--accent-soft); }
.ship-box { border: 1px dashed var(--brand); border-radius: 8px; padding: 12px 14px; margin: 10px 0; background: var(--brand-soft); }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* Overlay */
.overlay { position: fixed; inset: 0; background: rgba(19,33,48,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.overlay-box { background: #fff; border-radius: 12px; padding: 28px 32px; max-width: 380px; text-align: center; box-shadow: var(--shadow); }
.overlay-box p { margin: 14px 0 0; }
.spinner { width: 40px; height: 40px; margin: 0 auto; border-radius: 50%; border: 4px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dialog */
dialog { border: 0; border-radius: 12px; padding: 22px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(19,33,48,.3); }
dialog::backdrop { background: rgba(19,33,48,.5); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 760px) {
  .login-grid { grid-template-columns: 1fr; gap: 20px; padding-top: 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-addr { grid-template-columns: 96px 1fr 64px; }
  .card { padding: 16px; }
  .submit-inner .btn { width: 100%; }
  .quote thead { display: none; }
  .quote tr { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .quote td { border: 0; padding: 3px 6px; }
  .quote td.desc, .quote td.lead-time { grid-column: 1 / -1; }
  .quote td.lead-time { color: var(--muted); font-size: .85rem; }
  .brand small { display: none; }
  .session > span { max-width: 38vw; }
  .result-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .result-head h1 { font-size: 1.5rem; }
  .quote tbody td:nth-child(1) { grid-column: 1; }
  .quote tbody td.num-col { grid-column: 2; grid-row: 1; }
  .quote tfoot tr { grid-template-columns: 1fr auto; }
  .quote tfoot td[colspan] { grid-column: 1; }
}

@media print {
  body { background: #fff; padding: 0; }
  .topbar, .no-print, .submit-bar, .overlay { display: none !important; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
