:root {
  color-scheme: light;
  --ink: #111a2f;
  --muted: #68738a;
  --line: #dbe1eb;
  --soft: #f3f6fa;
  --white: #ffffff;
  --blue: #245eea;
  --blue-dark: #1648c6;
  --green: #159560;
  --green-soft: #e7f7ef;
  --amber: #c87808;
  --amber-soft: #fff4dc;
  --red: #d93c45;
  --red-soft: #fff0f1;
  --shadow: 0 12px 36px rgba(17, 26, 47, .09);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #edf1f7; color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 16px; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }

.topbar { min-height: 82px; padding: 16px clamp(18px, 3vw, 40px); background: var(--ink); color: var(--white); display: flex; align-items: center; gap: 15px; box-shadow: 0 5px 20px rgba(17,26,47,.16); }
.topbar h1 { margin: 1px 0 0; font-size: clamp(1.2rem, 2.5vw, 1.55rem); line-height: 1.1; }
.eyebrow { margin: 0; font-size: .76rem; font-weight: 800; letter-spacing: .11em; color: #8090ac; }
.topbar .eyebrow { color: #aebbd1; }
.brand-mark { width: 42px; height: 42px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; transform: skew(-8deg); }
.brand-mark span { border-radius: 3px; background: var(--blue); }
.brand-mark span:nth-child(2) { background: #4b7bf0; transform: translateY(5px); }
.brand-mark span:nth-child(3) { background: #84a5ff; transform: translateY(10px); }
.connection-badge { margin-left: auto; padding: 7px 12px; border: 1px solid rgba(255,255,255,.18); border-radius: 99px; color: #cbd5e6; font-size: .8rem; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: clamp(18px, 3vw, 38px); }
.upload-view { min-height: calc(100vh - 155px); display: grid; place-content: center; gap: 18px; }
.upload-card { width: min(620px, calc(100vw - 36px)); background: var(--white); border: 1px solid var(--line); border-radius: 22px; padding: clamp(30px, 6vw, 58px); text-align: center; box-shadow: var(--shadow); }
.upload-icon { width: 70px; height: 70px; margin: 0 auto 22px; display: grid; place-items: center; color: var(--blue); background: #edf3ff; border-radius: 20px; }
.upload-icon svg { width: 36px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.step-label { margin: 0 0 8px; color: var(--blue); font-size: .78rem; font-weight: 850; letter-spacing: .12em; }
.upload-card h2 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.15rem); }
.upload-card > p:not(.step-label):not(.inline-error) { max-width: 440px; margin: 14px auto 28px; color: var(--muted); line-height: 1.55; }
.file-button input { display: none; }
.primary-button, .finish-button { border: 0; border-radius: 11px; background: var(--blue); color: var(--white); font-weight: 800; padding: 14px 22px; display: inline-flex; justify-content: center; align-items: center; min-height: 50px; }
.primary-button:hover, .finish-button:hover { background: var(--blue-dark); }
.inline-error { color: var(--red); min-height: 1.25em; margin: 15px 0 0; font-weight: 700; }
.privacy-note { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: .84rem; }
.privacy-note svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.verify-view { display: grid; gap: 20px; }
.order-header { display: flex; align-items: stretch; justify-content: space-between; gap: 20px; }
.order-identifiers { display: flex; flex: 1; gap: 12px; }
.order-identity-card, .destination-card { min-height: 86px; padding: 15px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--white); box-shadow: 0 6px 18px rgba(17,26,47,.045); }
.order-identity-card { min-width: 265px; }
.destination-card { flex: 1; min-width: 260px; }
.order-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 4px; }
.order-title-row h2 { margin: 0; font-size: clamp(1.65rem, 4vw, 2.25rem); }
.store-name { margin: 8px 0 0; color: var(--ink); font-size: 1.12rem; font-weight: 850; line-height: 1.25; }
.status-pill { border-radius: 99px; padding: 6px 10px; font-size: .78rem; font-weight: 800; }
.status-pill.pending { color: #8a5900; background: var(--amber-soft); }
.status-pill.done { color: #086a43; background: var(--green-soft); }
.order-actions { display: flex; align-items: center; gap: 10px; }
.ghost-button { border: 0; background: transparent; color: var(--blue); font-weight: 800; padding: 10px 2px; }
.pdf-button, .sort-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #aab7ca; border-radius: 10px; background: var(--white); color: var(--ink); font-weight: 800; }
.pdf-button { min-height: 48px; padding: 0 16px; }
.pdf-button svg, .sort-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pdf-button:hover, .sort-button:hover, .sort-button[aria-pressed="true"] { border-color: var(--blue); color: var(--blue); background: #edf3ff; }

.summary-grid { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 18px; }
.progress-card, .scan-card, .items-panel { background: var(--white); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 24px rgba(17,26,47,.055); }
.progress-card { padding: 22px; }
.metric-label { margin: 0 0 5px; color: var(--muted); font-size: .76rem; letter-spacing: .1em; font-weight: 850; }
.progress-copy { display: flex; justify-content: space-between; align-items: center; }
.progress-number { margin: 0; font-size: 2rem; font-weight: 850; }
.progress-number small { color: var(--muted); font-size: 1rem; font-weight: 700; }
.progress-percent { font-size: 1.5rem; font-weight: 850; color: var(--blue); }
.progress-track { height: 10px; margin: 18px 0 14px; overflow: hidden; border-radius: 99px; background: #e7ebf2; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--blue); transition: width .18s ease, background .18s ease; }
.progress-footer { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font-size: .86rem; }
.progress-footer strong { color: var(--ink); }
.scan-card { min-height: 160px; padding: 22px; display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: center; gap: 16px; border: 2px solid #b9cdfd; transition: border-color .15s, background .15s; }
.scan-card.success { border-color: #68c59b; background: #fbfffd; }
.scan-card.error { border-color: #ef8990; background: #fffafa; }
.scan-card.warning { border-color: #e6bd6c; background: #fffdf7; }
.scan-indicator { width: 58px; height: 58px; position: relative; border-radius: 12px; background: #edf3ff; }
.scan-indicator span { position: absolute; width: 15px; height: 15px; border-color: var(--blue); border-style: solid; }
.scan-indicator span:nth-child(1) { left: 10px; top: 10px; border-width: 3px 0 0 3px; }
.scan-indicator span:nth-child(2) { right: 10px; top: 10px; border-width: 3px 3px 0 0; }
.scan-indicator span:nth-child(3) { left: 10px; bottom: 10px; border-width: 0 0 3px 3px; }
.scan-indicator span:nth-child(4) { right: 10px; bottom: 10px; border-width: 0 3px 3px 0; }
.scan-copy p:not(.metric-label) { margin: 0; font-size: 1.1rem; font-weight: 800; }
.scan-copy small { display: block; margin-top: 5px; color: var(--muted); }
#scanForm { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
#scanForm label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#scanInput { min-width: 0; height: 46px; border: 1px solid #aab7ca; border-radius: 9px; padding: 0 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1rem; text-transform: uppercase; }
#scanInput:focus { outline: 3px solid rgba(36,94,234,.16); border-color: var(--blue); }
#scanForm button { border: 0; border-radius: 9px; padding: 0 17px; background: var(--ink); color: var(--white); font-weight: 800; }

.alert-banner { border-radius: 11px; padding: 12px 15px; font-weight: 750; }
.alert-banner.error { color: #9e1822; background: var(--red-soft); border: 1px solid #f5c1c5; }
.alert-banner.warning { color: #7c4b00; background: var(--amber-soft); border: 1px solid #edd198; }
.alert-banner.success { color: #086a43; background: var(--green-soft); border: 1px solid #b6e4ce; }

.items-panel { overflow: hidden; }
.panel-heading { padding: 20px 22px 15px; display: flex; justify-content: space-between; align-items: end; gap: 20px; border-bottom: 1px solid var(--line); }
.panel-heading h3 { margin: 3px 0 0; font-size: 1.22rem; }
.panel-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.sort-button { min-height: 42px; padding: 0 14px; }
.legend { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; color: var(--muted); font-size: .78rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-left: 8px; }
.pending-dot { background: var(--amber); }.done-dot { background: var(--green); }.excess-dot { background: var(--red); }
.table-wrap { overflow: auto; max-height: min(52vh, 620px); }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
thead { position: sticky; top: 0; z-index: 1; background: #f6f8fb; }
th { color: #58647a; font-size: .78rem; letter-spacing: .055em; text-transform: uppercase; text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
td { padding: 13px 16px; border-bottom: 1px solid #e8ecf2; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.done { background: #fbfefc; }
tbody tr.excess { background: #fffafa; }
.state-cell { width: 86px; }
.row-state { display: inline-flex; align-items: center; gap: 7px; font-weight: 800; font-size: .78rem; }
.row-state::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--amber); }
tr.done .row-state { color: var(--green); }.done .row-state::before { background: var(--green); }
tr.excess .row-state { color: var(--red); }.excess .row-state::before { background: var(--red); }
.sku { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 850; color: var(--blue); white-space: nowrap; }
.description { color: var(--ink); font-size: .95rem; font-weight: 650; line-height: 1.35; }
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.scanned-number { font-weight: 900; font-size: 1.1rem; }
.diff-negative { color: var(--amber); font-weight: 850; }.diff-zero { color: var(--green); font-weight: 850; }.diff-positive { color: var(--red); font-weight: 850; }
.action-bar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.94); backdrop-filter: blur(12px); box-shadow: 0 -8px 26px rgba(17,26,47,.07); }
.secondary-button, .danger-button { min-height: 48px; border-radius: 10px; padding: 0 18px; font-weight: 800; }
.secondary-button { border: 1px solid #b7c1d0; background: var(--white); color: var(--ink); }
.secondary-button svg { width: 19px; margin-right: 7px; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.finish-button { min-width: 220px; }
.danger-button { border: 0; background: var(--red); color: var(--white); }

dialog { border: 0; border-radius: 20px; box-shadow: 0 24px 80px rgba(17,26,47,.28); color: var(--ink); }
dialog::backdrop { background: rgba(12,18,33,.66); backdrop-filter: blur(3px); }
.success-dialog { width: min(520px, calc(100vw - 32px)); padding: 38px; text-align: center; }
.success-dialog h2 { margin: 6px 0 10px; font-size: 2rem; }
.success-dialog p:not(.step-label) { color: var(--muted); line-height: 1.5; }
.success-dialog .primary-button { width: 100%; margin-top: 16px; }
.success-check { width: 72px; height: 72px; margin: 0 auto 20px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); }
.success-check svg { width: 42px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.confirm-dialog { width: min(460px, calc(100vw - 32px)); padding: 30px; }
.confirm-dialog h2 { margin: 0 0 8px; }.confirm-dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.scan-overlay { position: fixed; inset: 0; z-index: 100; pointer-events: none; display: grid; place-items: center; padding: 0; opacity: 0; visibility: hidden; }
.scan-overlay::before { content: ""; position: absolute; inset: 0; background: transparent; backdrop-filter: blur(0); }
.scan-overlay-card { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 28px; border: 0; background: transparent; color: #171313; text-align: center; transform: scale(.82); }
.scan-overlay-symbol { width: clamp(180px, 30vw, 310px); height: clamp(180px, 30vw, 310px); display: grid; place-items: center; border: clamp(10px, 1.8vw, 18px) solid currentColor; border-radius: 50%; }
.scan-overlay-symbol svg { grid-area: 1 / 1; width: 68%; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; display: none; }
.scan-overlay strong { font-size: clamp(2.2rem, 7vw, 5.2rem); line-height: .95; letter-spacing: -.025em; }
.scan-overlay span { max-width: min(760px, 88vw); font-size: clamp(1.05rem, 3.2vw, 1.8rem); font-weight: 850; line-height: 1.25; }
.scan-overlay.show-success, .scan-overlay.show-error, .scan-overlay.show-warning { visibility: visible; animation: scan-overlay-life 1.05s ease both; }
.scan-overlay.show-success { color: #171313; }
.scan-overlay.show-success::before { background: rgba(0,194,100,.60); }
.scan-overlay.show-success .overlay-check { display: block; }
.scan-overlay.show-error { color: #171313; animation-duration: 1.55s; }
.scan-overlay.show-error::before { background: rgba(245,0,8,.60); animation: error-pulse .32s ease 3; }
.scan-overlay.show-error .scan-overlay-card { animation: error-shake .38s ease 2; }
.scan-overlay.show-error .overlay-cross { display: block; }
.scan-overlay.show-warning { color: #171313; animation-duration: 1.45s; }
.scan-overlay.show-warning::before { background: rgba(255,133,55,.60); }
.scan-overlay.show-warning .scan-overlay-symbol { border: 0; border-radius: 0; }
.scan-overlay.show-warning .scan-overlay-symbol svg { width: 100%; stroke-width: 2.5; }
.scan-overlay.show-warning .overlay-warning { display: block; }
@keyframes scan-overlay-life { 0% { opacity: 0; } 12% { opacity: 1; } 78% { opacity: 1; } 100% { opacity: 0; } }
@keyframes error-pulse { 0%,100% { opacity: .72; } 50% { opacity: 1; } }
@keyframes error-shake { 0%,100% { transform: translateX(0) scale(1); } 25% { transform: translateX(-13px) scale(1.02); } 75% { transform: translateX(13px) scale(1.02); } }
.scan-overlay.show-success .scan-overlay-card, .scan-overlay.show-warning .scan-overlay-card { animation: overlay-card-pop .32s cubic-bezier(.2,.9,.2,1.25) forwards; }
@keyframes overlay-card-pop { from { transform: scale(.78); } to { transform: scale(1); } }
.pdf-dialog { width: min(1120px, calc(100vw - 24px)); height: min(94vh, 1100px); max-width: none; max-height: none; padding: 0; overflow: hidden; background: #dbe1e9; }
.pdf-dialog-header { position: sticky; top: 0; z-index: 3; min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 13px 18px; color: var(--white); background: var(--ink); box-shadow: 0 4px 16px rgba(17,26,47,.2); }
.pdf-dialog-header .eyebrow { color: #aebbd1; }
.pdf-dialog-header h2 { margin: 2px 0 0; font-size: 1.2rem; }
.close-button { width: 44px; height: 44px; flex: 0 0 44px; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: rgba(255,255,255,.08); color: var(--white); font-size: 2rem; line-height: 1; }
.pdf-loading { padding: 40px; text-align: center; color: #536077; font-weight: 750; }
.pdf-pages { height: calc(100% - 72px); overflow: auto; padding: 18px; display: grid; justify-items: center; gap: 18px; }
.pdf-page { display: block; max-width: 100%; height: auto; background: var(--white); box-shadow: 0 8px 28px rgba(17,26,47,.18); }

@media (max-width: 800px) {
  .app-shell { padding: 18px 12px 28px; }
  .summary-grid { grid-template-columns: 1fr; }
  .order-header { align-items: start; }
  .order-identifiers { flex-direction: column; }
  .order-identity-card, .destination-card { width: 100%; min-width: 0; }
  .order-actions { flex-direction: column; align-items: stretch; }
  .connection-badge { display: none; }
  .panel-heading { align-items: start; flex-direction: column; }
  .panel-controls { width: 100%; align-items: stretch; }
  .sort-button { width: 100%; }
  .legend { justify-content: flex-start; }
  .action-bar { flex-direction: column-reverse; }
  .action-bar button { width: 100%; }
}

@media (max-width: 520px) {
  .topbar { min-height: 70px; padding: 12px 15px; }
  .brand-mark { width: 34px; height: 34px; }
  .topbar h1 { font-size: 1.05rem; }
  .topbar .eyebrow { font-size: .65rem; }
  .order-header { flex-direction: column; gap: 10px; }
  .order-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .ghost-button { align-self: flex-start; }
  .scan-card { grid-template-columns: 48px minmax(0,1fr); padding: 16px; }
  .scan-indicator { width: 48px; height: 48px; }
  #scanForm { grid-template-columns: 1fr; }
  #scanForm button { height: 44px; }
  .progress-card { padding: 18px; }
  .pdf-dialog { width: 100vw; height: 100dvh; border-radius: 0; }
  .pdf-pages { padding: 10px; }
}
