:root {
  color-scheme: light;
  --background: #f7f7f4;
  --surface: #ffffff;
  --text: #202124;
  --muted: #696d72;
  --line: #d8dadd;
  --accent: #176b5b;
  --accent-strong: #0e4d42;
  --low: #b42318;
  --low-bg: #fff1f0;
  --ok: #257a3e;
  --ok-bg: #edf8ef;
  --shadow: 0 1px 3px rgb(0 0 0 / 10%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-height: 64px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--accent-strong);
  font-size: 22px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.header-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--line);
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  min-width: max-content;
}

.header-nav {
  flex-wrap: wrap;
}

.nav a {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 650;
}

.nav a[aria-current="page"] {
  background: #e5f0ec;
  color: var(--accent-strong);
}

.button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.logout-form {
  margin: 0;
}

.text-button {
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.text-button:active,
.text-button:hover {
  color: var(--accent-strong);
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.page {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.refresh-state {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-list {
  display: grid;
  gap: 10px;
}

.category-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.category-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.category-panel summary::-webkit-details-marker {
  display: none;
}

.category-panel summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--accent-strong);
  font-weight: 900;
}

.category-panel[open] summary::before {
  content: "-";
}

.category-name {
  flex: 1;
  font-size: 18px;
  font-weight: 800;
}

.category-count {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.inventory-shell {
  overflow-x: auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

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

.inventory-table th,
.inventory-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.inventory-table th {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sort-heading {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-heading span {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: none;
}

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

.product-name {
  font-weight: 750;
}

.pending-sync {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 5px;
  border-radius: 5px;
  background: #fff7e6;
  color: #8a5a00;
  font-size: 11px;
  font-weight: 800;
  vertical-align: middle;
}

.product-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.stock-control {
  display: grid;
  grid-template-columns: 42px minmax(64px, 1fr) 42px;
  align-items: center;
  width: 160px;
}

.stock-count {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.stock-count-text {
  font-size: 13px;
  line-height: 1.1;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f4f6f5;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.icon-button:active {
  transform: translateY(1px);
}

.status {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 800;
}

.status-low {
  background: var(--low-bg);
  color: var(--low);
}

.status-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.is-low {
  background: #fffafa;
}

.is-inactive {
  color: var(--muted);
}

.table-link {
  color: var(--accent-strong);
  font-weight: 700;
}

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

.product-form {
  display: grid;
  gap: 18px;
  max-width: 760px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.landing {
  display: grid;
  gap: 14px;
  max-width: 520px;
  padding: 24px 0;
}

.landing p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.auth-form {
  max-width: 420px;
}

.form-error {
  padding: 10px 12px;
  border: 1px solid #f0b4ae;
  border-radius: 6px;
  background: var(--low-bg);
  color: var(--low);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
}

.form-actions {
  display: flex;
  gap: 10px;
}

@media (max-width: 700px) {
  .form-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 8px;
    padding: 10px 12px;
  }

  .nav {
    flex-wrap: wrap;
  }

  .brand-group {
    min-height: 32px;
  }

  .page {
    width: min(100vw - 20px, 1120px);
    padding-top: 18px;
  }

  h1 {
    font-size: 25px;
  }

  .category-panel summary {
    padding: 12px;
  }

  .category-name {
    font-size: 16px;
  }

  .category-count {
    font-size: 13px;
    text-align: right;
  }

  .inventory-shell {
    overflow-x: visible;
  }

  .inventory-table {
    min-width: 0;
  }

  .inventory-table thead {
    display: none;
  }

  .inventory-table,
  .inventory-table tbody,
  .inventory-table tr,
  .inventory-table td {
    display: block;
    width: 100%;
  }

  .inventory-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  .inventory-table tr:last-child {
    border-bottom: 0;
  }

  .inventory-table td {
    padding: 0;
    border-bottom: 0;
  }

  .inventory-table td:first-child {
    min-width: 0;
  }

  .inventory-table td:nth-child(2) {
    grid-row: span 2;
  }

  .inventory-table td[data-threshold] {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
  }

  .inventory-table td[data-threshold]::before {
    content: attr(data-label) ": ";
  }

  .inventory-table td:nth-child(4),
  .inventory-table td:nth-child(5) {
    align-self: center;
  }

  .stock-control {
    grid-template-columns: 36px minmax(66px, 1fr) 36px;
    width: 142px;
  }

  .stock-count {
    font-size: 18px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

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