:root {
  color-scheme: light dark;
  --border: #d7dde8;
  --accent: #1d4ed8;
  --accent-strong: #1e40af;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #475569;
}

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

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
  color: var(--text);
}

header, main {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
}

header {
  padding: 1rem 0 0.75rem;
}

main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  margin-bottom: 1.5rem;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}

header nav {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

header nav a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0 1.25rem;
  gap: 0.875rem;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-form input,
.search-form select,
.item-form input,
.item-form select,
.item-form textarea,
.item-form button,
.button,
.link-button {
  font: inherit;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 2.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus,
a:focus {
  outline: 3px solid rgba(29, 78, 216, 0.2);
  outline-offset: 2px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: var(--surface);
}

th, td {
  text-align: left;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.92rem;
  letter-spacing: 0.01em;
}

tbody tr:hover td {
  background: #f8fbff;
}

tr.low-stock td {
  background: #fef2f2;
  color: #991b1b;
}

tr.low-stock td:first-child::before {
  content: "Low stock";
  display: inline-block;
  margin-right: 0.5rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: #dc2626;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.actions {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  flex-wrap: wrap;
}

.item-name-cell {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.mobile-edit-button {
  display: none;
  align-self: flex-start;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: #e0edff;
  color: var(--accent-strong);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 700;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.button {
  display: inline-block;
  padding: 0.65rem 0.9rem;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  text-decoration: none;
  border-radius: 12px;
  border: none;
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.18);
  min-height: 2.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.button-secondary {
  padding: 0.5rem 0.75rem;
  min-height: 2rem;
  font-size: 0.9rem;
}

.button-upload-csv {
  align-self: flex-start;
  padding: 0.3rem 0.55rem;
  min-height: 1.75rem;
  font-size: 0.8rem;
  border-radius: 999px;
}

.search-form button {
  min-height: 3rem;
  padding: 0.9rem 1.15rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.18);
}

.destructive-link {
  color: #b91c1c;
}

.scan-page {
  max-width: 680px;
  margin: 0 auto;
}

.scan-heading {
  margin: 1rem 0 1.5rem;
}

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

.scan-heading h2 {
  margin: 0;
}

.scan-status {
  color: var(--text-muted);
}

.scan-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.scan-action {
  min-height: 7rem;
  padding: 1rem;
  border: 0;
  border-radius: 16px;
  color: white;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-action-checkout {
  background: #64748b;
  cursor: not-allowed;
  opacity: 0.72;
}

.scan-action-place {
  background: #15803d;
  box-shadow: 0 8px 18px rgba(21, 128, 61, 0.2);
}

.scanner-panel {
  max-width: 520px;
  margin: 1.5rem auto;
  text-align: center;
}

.scanner-panel h3 {
  margin-bottom: 0.35rem;
}

.scanner-panel p {
  color: var(--text-muted);
}

#qr-reader {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
}

#qr-reader video {
  border-radius: 15px;
}

.scanner-message {
  min-height: 1.5rem;
}

.scanner-file-label {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
  text-decoration: underline;
}

.scanner-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.scan-reset {
  display: block;
  margin: 2rem 0 0;
  color: var(--accent);
  text-align: center;
  font-weight: 700;
}

.item-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 560px;
}

.item-qr {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.item-qr h3 {
  margin: 0;
}

.item-qr img {
  display: block;
  width: 240px;
  height: 240px;
  max-width: 100%;
  border: 1px solid var(--border);
}

.item-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar-stack {
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  justify-content: flex-start;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.flashes li {
  background: #fff7ed;
  color: #9a3412;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 0.65rem;
  border: 1px solid #fed7aa;
}

@media (max-width: 720px) {
  header, main {
    width: calc(100% - 1rem);
  }

  header h1 {
    font-size: 1.45rem;
  }

  main {
    padding: 1rem;
    border-radius: 16px;
  }

  .scan-actions {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin: 1.5rem 0;
  }

  .scan-action {
    min-height: 5.5rem;
    font-size: 1.25rem;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > * {
    width: 100%;
  }

  .search-form {
    width: 100%;
  }

  .search-form input,
  .search-form select,
  .search-form button,
  .toolbar .button {
    width: 100%;
  }

  .toolbar .button {
    min-height: 2.5rem;
    padding: 0.6rem 0.85rem;
  }

  .toolbar .button-secondary {
    min-height: 2.05rem;
    padding: 0.45rem 0.7rem;
    font-size: 0.88rem;
  }

  .search-form button {
    min-height: 3.2rem;
    padding: 0.95rem 1rem;
  }

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

  table {
    min-width: 0;
    table-layout: fixed;
  }

  .inventory-table th:nth-child(2),
  .inventory-table td:nth-child(2),
  .inventory-table th:nth-child(3),
  .inventory-table td:nth-child(3),
  .inventory-table th:nth-child(4),
  .inventory-table td:nth-child(4),
  .inventory-table th:nth-child(5),
  .inventory-table td:nth-child(5),
  .inventory-table th:nth-child(6),
  .inventory-table td:nth-child(6),
  .inventory-table th:nth-child(7),
  .inventory-table td:nth-child(7),
  .inventory-table th:nth-child(10),
  .inventory-table td:nth-child(10) {
    display: none;
  }

  .inventory-table th:nth-child(1),
  .inventory-table td:nth-child(1) {
    width: 44%;
  }

  .inventory-table th:nth-child(8),
  .inventory-table td:nth-child(8) {
    width: 20%;
    text-align: center;
  }

  .inventory-table th:nth-child(9),
  .inventory-table td:nth-child(9) {
    width: 36%;
  }

  .locations-table th:nth-child(1),
  .locations-table td:nth-child(1) {
    width: 34%;
  }

  .locations-table th:nth-child(2),
  .locations-table td:nth-child(2) {
    width: 34%;
  }

  .locations-table th:nth-child(3),
  .locations-table td:nth-child(3) {
    width: 32%;
  }

  .locations-table img {
    width: min(120px, 100%);
    height: auto;
  }

  .mobile-edit-button {
    display: inline-flex;
  }

  th, td {
    padding: 0.55rem 0.4rem;
    font-size: 0.88rem;
  }

  tr.low-stock td:first-child::before {
    margin-right: 0.3rem;
    padding: 0.1rem 0.3rem;
    font-size: 0.66rem;
  }

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

  .danger-actions {
    margin-top: 0.75rem;
  }

  .form-actions > * {
    width: 100%;
  }

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