:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #65758b;
  --line: #d9e0e8;
  --brand: #166534;
  --brand-dark: #14532d;
  --warn: #fff7ed;
  --warn-line: #fdba74;
  --review: #fefce8;
  --low-stock: #fff1f2;
  --low-stock-line: #fb7185;
  --error: #b91c1c;
}

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f6f7f9;
  color: #1f2933;
  line-height: 1.4;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.05rem;
}

p {
  margin: 0.35rem 0;
}

a {
  color: #166534;
}

.topbar {
  display: block;
  display: -webkit-box;
  -webkit-box-align: center;
  -webkit-box-pack: justify;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #d9e0e8;
}

.top-actions {
  display: block;
  display: -webkit-box;
  -webkit-box-align: center;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.topbar p,
.muted {
  color: #65758b;
  font-size: 0.875rem;
}

.shell {
  width: auto;
  max-width: 1180px;
  margin: 1rem auto 3rem;
  padding: 0 1rem;
  display: block;
  display: grid;
  gap: 1rem;
}

.panel {
  background: #ffffff;
  border: 1px solid #d9e0e8;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.section-head,
.controls,
.actions {
  display: block;
  display: -webkit-box;
  -webkit-box-align: center;
  -webkit-box-pack: justify;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filters,
.controls {
  display: block;
  display: -webkit-box;
  -webkit-box-align: end;
  display: flex;
  gap: 0.5rem;
  align-items: end;
  flex-wrap: wrap;
}

.filters.one-line {
  flex-wrap: nowrap;
}

.filters.one-line input {
  min-width: 280px;
  min-width: min(32vw, 360px);
}

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

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

.add-item-top-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
}

.add-item-detail-grid {
  grid-template-columns: minmax(220px, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
}

.mini-grid {
  display: block;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

label {
  display: block;
  display: grid;
  gap: 0.35rem;
  color: #65758b;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
}

.field-group {
  display: block;
  display: grid;
  gap: 0.35rem;
}

.field-label {
  color: #65758b;
  font-size: 0.875rem;
  font-weight: 600;
}

.segmented-control {
  display: inline-block;
  display: inline-flex;
  margin-bottom: 0.35rem;
  overflow: hidden;
  border: 1px solid #d9e0e8;
  border-radius: 6px;
  background: #fff;
}

.segmented-control label {
  display: inline-block;
  display: inline-flex;
  color: #1f2933;
  font-weight: 700;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label > span {
  display: inline-block;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.4rem;
  padding: 0.55rem 0.8rem;
  border-right: 1px solid #d9e0e8;
  cursor: pointer;
}

.segmented-control label:last-child > span {
  border-right: 0;
}

.segmented-control input[value="subtract"]:checked + span {
  background: #b91c1c;
  color: #fff;
}

.segmented-control input[value="add"]:checked + span {
  background: #166534;
  color: #fff;
}

input,
select,
textarea {
  appearance: none;
  -webkit-appearance: none;
  -webkit-border-radius: 6px;
  width: 100%;
  border: 1px solid #d9e0e8;
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  color: #1f2933;
  background: #fff;
  font: inherit;
  min-height: 2.55rem;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

button,
.button {
  appearance: none;
  -webkit-appearance: none;
  -webkit-border-radius: 6px;
  display: inline-block;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  border: 0;
  border-radius: 6px;
  padding: 0.55rem 0.9rem;
  background: #166534;
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  gap: 0.4rem;
}

button:hover,
.button:hover {
  background: #14532d;
}

button:disabled,
button:disabled:hover {
  background: #cbd5e1;
  color: #64748b;
  cursor: not-allowed;
}

.secondary {
  background: #eef2f6;
  color: #1f2933;
}

.secondary:hover {
  background: #dfe6ee;
}

.danger {
  background: #b91c1c;
  color: #fff;
}

.danger:hover {
  background: #991b1b;
}

.compact {
  min-height: 2rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.875rem;
}

.icon {
  display: inline-block;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  line-height: 1;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 0.65rem;
  border-bottom: 1px solid #d9e0e8;
  text-align: left;
  vertical-align: top;
}

th {
  color: #65758b;
  font-size: 0.78rem;
  text-transform: uppercase;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty {
  color: #65758b;
  text-align: center;
}

.error {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
  border-radius: 6px;
  padding: 0.75rem;
}

.success {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #166534;
  border-radius: 6px;
  padding: 0.75rem;
}

.backup-card {
  display: block;
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.status {
  display: inline-block;
  display: inline-flex;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  background: #eef2f6;
  font-weight: 700;
}

.status-exact,
.status-likely {
  background: #fee2e2;
  color: #991b1b;
}

.status-possible {
  background: #fef3c7;
  color: #92400e;
}

.status-none {
  background: #dcfce7;
  color: #166534;
}

.warn-row {
  background: #fff7ed;
}

.review-row {
  background: #fefce8;
}

.muted-row {
  color: #65758b;
  background: #f8fafc;
}

.group-row th {
  background: #eef2f6;
  color: #1f2933;
  font-size: 0.82rem;
  letter-spacing: 0;
  text-transform: none;
}

.low-stock-row {
  background: #fff1f2;
}

.low-stock-row td:first-child {
  border-left: 4px solid #fb7185;
}

.item-name-link {
  color: #166534;
  text-decoration: none;
}

.item-name-link:hover {
  text-decoration: underline;
}

.check {
  display: inline-block;
  display: inline-flex;
  align-items: center;
  grid-template-columns: auto 1fr;
  gap: 0.4rem;
  color: #1f2933;
}

input[type="checkbox"] {
  appearance: auto;
  -webkit-appearance: checkbox;
  width: auto;
  min-height: auto;
  padding: 0;
  border: none;
  background: none;
}

.check input {
  width: auto;
}

.inline-form {
  display: block;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: end;
  margin-top: 1rem;
}

.inline-control {
  display: block;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: stretch;
}

.icon-button {
  min-width: 2.4rem;
  padding: 0.55rem;
}

.conversion-form {
  display: block;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 0.8fr 1.5fr auto;
  gap: 0.75rem;
  align-items: end;
  margin-top: 1rem;
}

.conversion-row {
  display: block;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 0.8fr 1.5fr auto;
  gap: 0.5rem;
  align-items: center;
}

.row-actions {
  display: inline-block;
  display: inline-flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.alias-list {
  display: block;
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.alias-row {
  display: block;
  display: -webkit-box;
  -webkit-box-align: center;
  -webkit-box-pack: justify;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid #d9e0e8;
  border-radius: 6px;
  padding: 0.65rem;
}

.danger-panel {
  border-color: #fecaca;
  background: #fff7f7;
}

.new-item-fields {
  display: block;
  display: grid;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #d9e0e8;
}

.hidden {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: block;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-panel {
  width: 420px;
  max-width: 100%;
  background: #fff;
  border: 1px solid #d9e0e8;
  border-radius: 8px;
  padding: 1.25rem;
}

.login-panel form {
  display: block;
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

@media (max-width: 760px) {
  body {
    background: #edf2f7;
  }

  h1 {
    font-size: 1.25rem;
  }

  h2 {
    font-size: 1rem;
  }

  .shell {
    margin: 0;
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .panel {
    border-radius: 7px;
    padding: 0.85rem;
    margin-bottom: 0.75rem;
  }

  .split,
  .grid,
  .add-item-top-grid,
  .add-item-detail-grid,
  .mini-grid,
  .inline-form,
  .conversion-form,
  .conversion-row {
    grid-template-columns: 1fr;
  }

  .section-head,
  .controls,
  .actions,
  .filters,
  .top-actions,
  .alias-row {
    align-items: stretch;
    flex-direction: column;
    -webkit-box-orient: vertical;
    gap: 0.6rem;
  }

  .controls button,
  .actions button,
  .actions .button,
  .top-actions button,
  .top-actions .button,
  .filters button,
  .backup-card .button {
    width: 100%;
  }

  .top-actions form,
  .filters label {
    width: 100%;
  }

  .filters.one-line {
    flex-wrap: wrap;
  }

  .filters.one-line input {
    min-width: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    -webkit-box-orient: vertical;
    gap: 0.75rem;
    padding: 0.85rem;
    position: static;
  }

  .topbar > div,
  .topbar > nav,
  .topbar > form,
  .topbar > a {
    width: 100%;
  }

  .topbar > a.button {
    width: auto;
    align-self: flex-start;
  }

  .topbar p {
    margin-top: 0.15rem;
  }

  .segmented-control {
    display: block;
    display: flex;
    width: 100%;
  }

  .segmented-control label {
    display: block;
    display: flex;
    flex: 1 1 0;
    margin: 0;
  }

  .segmented-control label > span {
    width: 100%;
    justify-content: center;
    min-height: 2.75rem;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
    text-align: center;
  }

  .input-panel textarea {
    min-height: 16rem;
    font-size: 1rem;
  }

  button,
  .button {
    min-height: 2.75rem;
    padding: 0.7rem 0.9rem;
  }

  .compact {
    min-height: 2.45rem;
  }

  label {
    margin-bottom: 0.55rem;
  }

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

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

  table {
    min-width: 0;
    border-collapse: separate;
  }

  thead {
    display: none;
  }

  tbody {
    display: block;
  }

  tr {
    margin: 0.75rem 0;
    border: 1px solid #d9e0e8;
    border-radius: 7px;
    background: #fff;
    overflow: hidden;
  }

  td,
  th {
    border-bottom: 1px solid #e5ebf2;
    padding: 0.7rem 0.75rem;
  }

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

  td[data-label]:before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.2rem;
    color: #65758b;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  .group-row {
    margin: 1rem 0 0.45rem;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .group-row th {
    display: block;
    border: 0;
    border-left: 4px solid #166534;
    border-radius: 6px;
  }

  .low-stock-row td:first-child {
    border-left: 0;
    box-shadow: inset 4px 0 0 #fb7185;
  }

  .review-row,
  .warn-row,
  .muted-row,
  .low-stock-row {
    background: #fff;
  }

  .review-row {
    box-shadow: inset 4px 0 0 #facc15;
  }

  .warn-row {
    box-shadow: inset 4px 0 0 #fb923c;
  }

  .muted-row {
    background: #f8fafc;
  }

  .status {
    display: block;
    width: 100%;
    border-radius: 6px;
    text-align: center;
  }

  .conversion-row {
    padding: 0;
  }

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

  .row-actions button {
    width: 100%;
  }

  .alias-row {
    align-items: stretch;
    -webkit-box-orient: vertical;
  }

  .alias-row form,
  .alias-row button {
    width: 100%;
  }

  .login-page {
    display: block;
    padding: 0.75rem;
  }

  .login-panel {
    margin-top: 12vh;
    padding: 1rem;
  }
}
