:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #6a6f73;
  --line: #ded9cf;
  --accent: #176b52;
  --accent-ink: #ffffff;
  --warn: #b7352d;
  --warn-bg: #fff0ed;
  --ok-bg: #edf8f2;
}

* {
  box-sizing: border-box;
}

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

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

button,
input,
select,
textarea {
  font: inherit;
}

button,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 36px;
}

button {
  background: #ffffff;
  color: var(--ink);
  padding: 0 11px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  background: #ffffff;
  padding: 7px 9px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 7px 10px;
  background: rgba(246, 244, 239, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  font-size: 18px;
  font-weight: 800;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  flex: 1;
}

.tabs.list-tabs {
  grid-template-columns: 1fr;
}

.tabs a {
  display: grid;
  place-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  font-size: 12px;
  font-weight: 750;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  min-width: 42px;
  min-height: 34px;
  padding: 0 8px;
}

.shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 8px;
}

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.section-head h1 {
  margin: 0;
  font-size: 15px;
}

.section-head a,
.section-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.section-head form {
  margin: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 8px;
}

.metric {
  display: grid;
  gap: 2px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span {
  font-size: 24px;
  line-height: 1;
  font-weight: 850;
}

.metric small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.metric.danger span,
.bad,
.danger-text {
  color: var(--warn);
}

.actions {
  margin-bottom: 8px;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.full {
  width: 100%;
}

.ghost {
  min-width: 34px;
  padding: 0 8px;
  background: transparent;
}

.row,
.shop-row {
  display: grid;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}

.row:last-child,
.shop-row:last-child {
  border-bottom: 0;
}

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

.stock-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.shop-row {
  grid-template-columns: 34px minmax(0, 1fr) auto 34px;
}

.link-row {
  min-height: 54px;
}

.main {
  min-width: 0;
}

.main strong,
.main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main strong {
  font-size: 14px;
  line-height: 1.2;
}

.main span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.qty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

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

.last-changed {
  background: #fff7d6;
  box-shadow: inset 4px 0 0 #d69516;
}

.done {
  opacity: 0.58;
}

.done .main strong {
  text-decoration: line-through;
}

.check-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 7px;
  color: var(--accent);
  font-size: 18px;
}

.stepper {
  display: grid;
  grid-template-columns: 34px 54px 34px;
  gap: 3px;
}

.stepper button,
.stepper input {
  min-height: 34px;
  padding: 0;
  text-align: center;
}

.mini-form {
  display: grid;
  grid-template-columns: 52px 52px 16px;
  gap: 3px;
  align-items: center;
}

.mini-form input,
.mini-form button {
  min-height: 34px;
  padding: 0;
  text-align: center;
}

.save-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}

.autosave-form.saving .save-dot,
.autosave-form.saving + .save-dot {
  background: #d69516;
}

.autosave-form.saved .save-dot {
  background: var(--accent);
}

.autosave-form.error .save-dot {
  background: var(--warn);
}

.autosave-form.saving input {
  border-color: #d69516;
}

.autosave-form.saved input {
  border-color: #8ab9a8;
}

.autosave-form.error input {
  border-color: var(--warn);
}

.grid-form,
.stack-form {
  display: grid;
  gap: 7px;
  padding: 10px;
}

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

.grid-form input:first-child,
.grid-form button {
  grid-column: 1 / -1;
}

.two,
.three {
  display: grid;
  gap: 7px;
}

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

.three {
  grid-template-columns: repeat(3, 1fr);
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.quick-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 42px;
  gap: 5px;
  padding: 8px;
}

.product-add {
  grid-template-columns: minmax(0, 1fr) 56px 68px 42px;
}

.product-line,
.shop-buy-row,
.bought-row {
  display: grid;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.product-line {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.product-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px 66px 12px;
  gap: 5px;
  align-items: center;
}

.product-inline input,
.product-inline select {
  min-height: 34px;
}

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

.product-target {
  text-align: center;
}

.detail-btn {
  display: grid;
  place-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.shop-buy-row {
  grid-template-columns: minmax(0, 1fr) 100px 34px;
}

.buy-form {
  display: grid;
  grid-template-columns: 44px 48px;
  gap: 4px;
}

.buy-form input,
.buy-form button {
  min-height: 34px;
  padding: 0 5px;
  text-align: center;
}

.bought-row {
  grid-template-columns: minmax(0, 1fr) 72px;
  opacity: 0.72;
}

.bought-row button {
  width: 100%;
  min-height: 34px;
  padding: 0 6px;
}

.split-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 0 8px 8px;
}

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

.store-head {
  margin: 0;
  padding: 8px 10px 5px;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  background: #f7fbf8;
  font-size: 12px;
  text-transform: uppercase;
}

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

.flash {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

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

.flash.error {
  background: var(--warn-bg);
}

.empty {
  margin: 0;
  padding: 12px 10px;
  color: var(--muted);
}

.sticky-actions {
  position: sticky;
  top: 58px;
  z-index: 10;
  padding: 8px;
}

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

.login-shell {
  width: min(360px, 100%);
  padding: 16px;
}

.login-panel {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-panel h1 {
  margin: 0;
  font-size: 22px;
}

@media (min-width: 720px) {
  body {
    font-size: 15px;
  }

  .shell {
    padding: 14px;
  }

  .topbar {
    justify-content: center;
  }

  .tabs {
    max-width: 420px;
    flex: 0 1 420px;
  }
}
