:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-strong: #eef4ff;
  --ink: #17202a;
  --muted: #647285;
  --line: #d9e2ec;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --blue: #1d4ed8;
  --danger: #b42318;
  --warning: #a15c07;
  --success: #167044;
  --shadow: 0 18px 50px rgba(20, 35, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  line-height: 1.45;
}

a {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 13px 22px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar-main,
.brand,
.nav,
.logout {
  display: flex;
  align-items: center;
}

.topbar-main {
  gap: 12px;
}

.brand {
  gap: 10px;
  color: var(--ink);
  font-size: 17px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
}

.nav-panel {
  min-width: 0;
}

.nav {
  gap: 6px;
  overflow-x: auto;
}

.nav a {
  flex: 0 0 auto;
  padding: 9px 11px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
}

.nav a.active,
.nav a:hover {
  background: #eaf1ff;
  color: var(--accent-strong);
}

.menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  padding: 0;
  background: #edf4ff;
  border: 1px solid #c8d9fb;
  border-radius: 8px;
  color: var(--accent-strong);
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.menu-toggle span + span {
  margin-top: 4px;
}

.menu-toggle.is-open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.menu-toggle.is-open span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.is-open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.logout {
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.page-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 54px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
}

.page-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lede,
.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.card,
.metric-card,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card {
  padding: 18px;
  margin-bottom: 18px;
}

.form-sections {
  display: grid;
  gap: 16px;
}

.form-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.form-section legend {
  padding: 0 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(6px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid #cbdcff;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
  padding: 20px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 34px;
  width: 34px;
  padding: 0;
  background: #edf4ff;
  color: var(--accent-strong);
}

.modal-form {
  display: grid;
  gap: 13px;
  margin-top: 16px;
}

.scan-summary {
  display: grid;
  gap: 9px;
  padding: 12px;
  background: #f6f9ff;
  border: 1px solid #d7e5ff;
  border-radius: 8px;
}

.scan-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.scan-list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 9px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
}

.scan-list-row span {
  overflow-wrap: anywhere;
}

.login-panel {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  padding: 30px;
}

.form-card {
  box-shadow: none;
  margin: 0;
}

.metric-grid,
.split-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 22px;
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.split-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.form-grid,
.scan-grid,
.search {
  display: grid;
  gap: 12px;
  align-items: end;
}

.form-grid,
.scan-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.search {
  grid-template-columns: minmax(220px, 1fr) auto;
}

.scan-card {
  border-color: #bfdbfe;
  background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
}

label {
  display: grid;
  gap: 6px;
  color: #425066;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
button,
.button {
  min-height: 42px;
  border-radius: 7px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
}

.scan-input {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

button,
.button {
  border: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  font-weight: 800;
}

.secondary {
  background: var(--blue);
}

.ghost {
  background: #edf2f7;
  color: #263548;
}

.danger {
  background: var(--danger);
}

.compact {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 8px;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.actions-cell {
  display: flex;
  gap: 8px;
  align-items: start;
  flex-wrap: wrap;
}

.wide {
  grid-column: span 2;
}

.table-wrap {
  overflow-x: auto;
  max-height: 620px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: var(--panel-strong);
  color: #344256;
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf2f7;
  color: #344256;
  font-size: 12px;
  font-weight: 800;
}

.status.large {
  min-height: 36px;
  font-size: 14px;
}

.status.pending {
  background: #fff4d6;
  color: var(--warning);
}

.status.relabeled {
  background: #dbeafe;
  color: var(--blue);
}

.status.shipped {
  background: #dcfce7;
  color: var(--success);
}

.status.cancelled {
  background: #fee4e2;
  color: var(--danger);
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  border-radius: 8px;
  padding: 11px 13px;
  background: #e8f3ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}

.flash.success {
  background: #ecfdf3;
  border-color: #bbf7d0;
  color: var(--success);
}

.flash.error {
  background: #fff1f2;
  border-color: #fecdd3;
  color: var(--danger);
}

.error-card {
  max-width: 680px;
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 10px;
  }

  .topbar-main {
    justify-content: space-between;
  }

  .menu-toggle {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .nav-panel {
    grid-column: 1 / -1;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.22s ease, opacity 0.18s ease;
  }

  .topbar.nav-open .nav-panel {
    max-height: 360px;
    opacity: 1;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding-top: 10px;
    overflow: visible;
  }

  .nav a {
    background: #f3f7ff;
    border: 1px solid #dbe7ff;
  }

  .logout {
    justify-content: space-between;
    grid-column: 1 / -1;
  }

  .metric-grid,
  .split-grid,
  .login-panel {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .scan-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 25px;
  }

  .page-shell {
    padding: 18px 12px 42px;
  }

  .page-head,
  .search {
    display: grid;
    grid-template-columns: 1fr;
  }

  .page-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .form-grid,
  .scan-grid,
  .wide {
    grid-template-columns: 1fr;
    grid-column: auto;
  }

  .card,
  .login-panel {
    padding: 15px;
  }

  .table-wrap {
    max-height: none;
    overflow-y: visible;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .actions-cell {
    display: flex;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 10px;
    border-bottom: 1px solid var(--line);
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
  }

  td.empty {
    display: block;
  }

  td.empty::before {
    content: "";
  }
}
