*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  background: var(--bg-canvas);
  color: var(--fg-primary);
}

header {
  background: var(--bg-inverse);
  color: var(--fg-inverse);
  padding: 1rem 2rem;
  border-bottom: 3px solid var(--erpb-teal);
}

header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  color: var(--fg-inverse);
  line-height: var(--lh-tight);
}

main {
  max-width: 740px;
  margin: 2rem auto;
  padding: 0 1rem;
}

section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

/* ── instructions ──────────────────────────────────────────────────────── */

.instructions {
  margin: 0 0 0.75rem;
  color: var(--fg-muted);
}

.format-hint {
  font-size: var(--fs-small);
  color: var(--fg-muted);
  background: var(--bg-sunken);
  border-left: 3px solid var(--border-strong);
  padding: 0.5rem 0.75rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 1.25rem;
}

/* ── drop zone ─────────────────────────────────────────────────────────── */

#drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-md);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  color: var(--fg-muted);
  transition: border-color var(--dur-base) var(--ease-standard), background var(--dur-base) var(--ease-standard), color var(--dur-base) var(--ease-standard);
  margin-bottom: 1rem;
  user-select: none;
}

#drop-zone:hover,
#drop-zone.dragging {
  border-color: var(--erpb-teal);
  background: var(--erpb-teal-50);
  color: var(--erpb-teal-700);
}

#drop-zone:focus-within {
  outline: none;
  box-shadow: var(--shadow-focus);
}

#drop-zone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

#drop-icon {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.75;
}

#file-name-display {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  font-weight: var(--fw-medium);
  color: var(--fg-title);
}

/* ── buttons ───────────────────────────────────────────────────────────── */

button {
  display: inline-block;
  font-family: var(--font-display);
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), opacity var(--dur-fast) var(--ease-standard);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

#check-btn {
  background: var(--erpb-blue);
  color: var(--fg-inverse);
}

#check-btn:not(:disabled):hover {
  background: var(--erpb-blue-700);
}

#submit-btn {
  display: block;
  margin-top: 1.25rem;
  background: var(--erpb-teal);
  color: var(--fg-inverse);
}

#submit-btn:not(:disabled):hover {
  background: var(--erpb-teal-700);
}

#new-upload-btn {
  display: inline-block;
  margin-top: 1rem;
  background: var(--bg-surface);
  color: var(--fg-title);
  border-color: var(--erpb-blue);
}

#new-upload-btn:hover {
  background: var(--erpb-blue-50);
}

/* ── spinner ───────────────────────────────────────────────────────────── */

#spinner {
  text-align: center;
  padding: 1rem;
  color: var(--fg-muted);
  font-style: italic;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

/* ── alerts (system error, result panels, confirmation) ───────────────── */

#error-msg,
#detected-box,
#errors-box,
#warnings-box,
#valid-box,
#confirm-box {
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
}

#error-msg {
  background: var(--erpb-red-50);
  border-left-color: var(--erpb-red);
  color: var(--erpb-red);
  border-radius: var(--radius-md);
}

#detected-box {
  background: var(--erpb-blue-50);
  border-left-color: var(--erpb-blue);
}

#errors-box {
  background: var(--erpb-red-50);
  border-left-color: var(--erpb-red);
  padding: 1rem 1.1rem;
}

#warnings-box {
  background: var(--erpb-amber-50);
  border-left-color: var(--erpb-amber);
  padding: 1rem 1.1rem;
}

#valid-box,
#confirm-box {
  background: var(--erpb-green-50);
  border-left-color: var(--erpb-green);
  color: var(--erpb-green-700);
}

#confirm-box.is-error {
  background: var(--erpb-red-50);
  border-left-color: var(--erpb-red);
  color: var(--erpb-red);
}

/* ── shared ────────────────────────────────────────────────────────────── */

ul {
  margin: 0.5rem 0 0;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.3rem;
}

p { margin: 0.4rem 0; }

/* ── customer match ────────────────────────────────────────────────────── */

.customer-match-box {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  margin-top: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
}

.customer-match-box svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  margin-top: 1px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cm-title {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}

.cm-company {
  font-size: 0.9rem;
  font-weight: var(--fw-semibold);
  color: var(--fg-primary);
}

.cm-pct {
  font-weight: var(--fw-regular);
}

.cm-meta,
.cm-desc {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-top: 0.15rem;
}

.cm-ok {
  background: var(--erpb-green-50);
  border-color: var(--erpb-green);
  color: var(--erpb-green-700);
}

.cm-warn {
  background: var(--erpb-amber-50);
  border-color: var(--erpb-amber);
  color: #8A5A12;
}

.cm-none {
  border-width: 1.5px;
  box-shadow: var(--shadow-sm);
}

.cm-unavailable {
  background: var(--bg-sunken);
  border-color: var(--border-default);
  color: var(--fg-muted);
}

.code-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--erpb-blue-50);
  color: var(--erpb-blue-900);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-xs);
  margin-left: 0.35em;
  white-space: nowrap;
}

/* ── issue lists (errors / warnings) ──────────────────────────────────── */

.issue-header {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}

.issue-header svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  margin-top: 1px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#errors-box .issue-header { color: var(--erpb-red); }
#warnings-box .issue-header { color: #8A5A12; }

.issue-title {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: 0.95rem;
  line-height: var(--lh-snug);
}

.issue-subtitle {
  font-size: 0.82rem;
  font-weight: var(--fw-regular);
  color: var(--fg-muted);
  margin-top: 0.1rem;
}

.issue-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.issue-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  column-gap: 0.6rem;
  row-gap: 0.2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
}

.issue-main {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.5rem;
}

.issue-loc {
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  font-size: 0.78rem;
  padding: 0.1em 0.5em;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.issue-error .issue-loc {
  background: var(--erpb-red-50);
  color: var(--erpb-red);
}

.issue-warning .issue-loc {
  background: var(--erpb-amber-50);
  color: #8A5A12;
}

.issue-message {
  color: var(--fg-primary);
  font-size: 0.9rem;
}

.issue-code {
  flex: 0 0 auto;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--fg-subtle);
  white-space: nowrap;
}

/* ── product match ─────────────────────────────────────────────────────── */

.product-match-list {
  margin-top: 0.75rem;
}

.pm-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: 0.85rem;
  color: var(--erpb-red);
}

.pm-title svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.pm-lines {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.pm-line {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.4rem;
  background: var(--erpb-red-50);
  border-left: 3px solid var(--erpb-red);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.85rem;
}

.pm-row {
  font-weight: var(--fw-semibold);
  color: var(--fg-title);
}

.pm-desc {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.pm-reason {
  color: var(--erpb-red);
  font-size: 0.8rem;
}

/* ── login page ────────────────────────────────────────────────────────── */

.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 4.5rem);
  margin-top: 0;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.field-label {
  display: block;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--fg-title);
  margin: 0.85rem 0 0.3rem;
}

.login-card input[type="text"],
.login-card input[type="password"] {
  display: block;
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--fg-primary);
}

.login-card input[type="text"]:focus,
.login-card input[type="password"]:focus {
  outline: none;
  border-color: var(--erpb-blue);
  box-shadow: var(--shadow-focus);
}

#login-btn {
  display: block;
  width: 100%;
  margin-top: 1.25rem;
  background: var(--erpb-blue);
  color: var(--fg-inverse);
}

#login-btn:hover {
  background: var(--erpb-blue-700);
}

.login-error {
  background: var(--erpb-red-50);
  border-left: 3px solid var(--erpb-red);
  color: var(--erpb-red);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
}

/* ── responsive ────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  header { padding: 0.75rem 1rem; }
  header h1 { font-size: 1.1rem; }
  section { padding: 1rem; }
  #drop-zone { padding: 1.5rem 1rem; }
}
