:root {
  color-scheme: light;
  --bg: #f7f7f7;
  --panel: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #f97316;
  --accent-strong: #fe7200;
  --danger: #b42318;
  --ok: #167445;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:disabled,
input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
}

a {
  color: var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.04);
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border-radius: 3px;
  background: var(--accent);
}

.userbar {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
}

.link-button {
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--accent);
}

.page {
  width: min(980px, calc(100% - 32px));
  margin: 20px auto;
}

.auth-panel {
  width: min(420px, 100%);
  margin: 80px auto 0;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.form,
.inline-form {
  display: grid;
  gap: 14px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 17px;
}

p {
  margin-top: 4px;
  color: var(--muted);
}

.status-panel {
  display: grid;
  justify-items: end;
  gap: 4px;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(249, 115, 22, 0.25);
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(249, 115, 22, 0.08);
  color: #9a4a06;
}

.table-wrap,
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.04);
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

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

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

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 6px;
  background: #fff;
}

.flash.error {
  border: 1px solid var(--danger);
  color: var(--danger);
}

.flash.success {
  border: 1px solid var(--ok);
  color: var(--ok);
}

.items {
  display: grid;
  gap: 8px;
}

.item {
  padding: 12px;
}

.item-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.progress-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.progress-line strong {
  color: var(--accent-strong);
}

.inline-form {
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.non-marked-form {
  align-items: center;
}

.qty-editor {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  gap: 6px;
  align-items: center;
}

.qty-input {
  text-align: center;
}

.qty-step {
  min-height: 40px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: #1a1a1a;
}

.qty {
  flex: 0 0 auto;
  min-width: 96px;
  text-align: right;
  color: var(--accent-strong);
}

.actions-row {
  display: grid;
  grid-template-columns: 132px 1fr;
  align-items: start;
  gap: 8px;
}

.camera-button {
  width: 100%;
  background: #1a1a1a;
}

.manual-code {
  min-height: 40px;
}

.manual-code summary,
.codes-details summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  cursor: pointer;
}

.manual-code .inline-form {
  margin-top: 6px;
}

.secondary-button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.nav-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.scanner-dialog {
  width: min(560px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 16px;
  background: #fff;
  color: var(--text);
}

.scanner-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.scanner-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

#scanner-reader {
  overflow: hidden;
  border-radius: 8px;
  background: #111;
  border: 1px solid var(--line);
}

#scanner-reader video {
  width: 100% !important;
}

.scanner-note {
  font-size: 14px;
}

.codes {
  overflow-wrap: anywhere;
}

.compact-codes {
  margin: 6px 0 0;
  padding-left: 16px;
  max-height: 130px;
  overflow: auto;
  font-size: 12px;
  color: var(--muted);
}

.compact-codes li {
  margin: 2px 0;
}

.compact-codes li span {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scanner-status {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 13px;
}

.scanner-status.error {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.35);
  background: rgba(180, 35, 24, 0.06);
}

.scanner-status.info {
  color: var(--muted);
}

.complete-form {
  display: flex;
  justify-content: flex-end;
}

.complete-form button {
  min-width: 220px;
}

.actions-bottom {
  position: sticky;
  bottom: 0;
  margin-top: 14px;
  padding: 10px 0;
  background: linear-gradient(180deg, rgba(247, 247, 247, 0), var(--bg) 32%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

@media (max-width: 680px) {
  .topbar,
  .section-head,
  .item-main {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .status-panel {
    justify-items: start;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .non-marked-form {
    grid-template-columns: 1fr auto;
    align-items: stretch;
  }

  .page {
    width: min(100% - 16px, 980px);
    margin: 12px auto;
  }

  .auth-panel,
  .item {
    padding: 10px;
  }

  h1 {
    font-size: 21px;
  }

  h2 {
    font-size: 15px;
  }

  p {
    font-size: 13px;
  }

  .qty {
    min-width: 0;
    text-align: left;
  }

  .actions-row {
    grid-template-columns: 112px 1fr;
  }

  .topbar {
    min-height: 50px;
    padding: 0 12px;
  }

  .complete-form button {
    width: 100%;
  }

  .actions-bottom {
    flex-direction: column;
    align-items: stretch;
  }

  .page-nav {
    position: sticky;
    top: 6px;
    z-index: 3;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .page-nav .secondary-button,
  .page-nav .nav-link,
  .section-head form,
  .section-head form button {
    width: 100%;
  }

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

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

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 8px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
  }

  td {
    border: 0;
    padding: 4px 0;
    min-height: 24px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    text-align: right;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    text-align: left;
  }

  .status {
    min-height: 24px;
    font-size: 13px;
  }

  .empty {
    text-align: left;
  }
}
