:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ee;
  --border: #e0dfda;
  --text: #1c1b19;
  --muted: #6b6a66;
  --accent: #35654d;
  --accent-text: #ffffff;
  --danger: #a3341f;
  --warn: #8a5a12;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2124;
    --surface-2: #272a2e;
    --border: #34383d;
    --text: #ececea;
    --muted: #9a9a96;
    --accent: #6fae8c;
    --accent-text: #10221a;
    --danger: #e0846e;
    --warn: #d9ab62;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-right: 4px;
}

.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }

.nav button {
  background: none;
  border: 0;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 550; }

.whoami { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.pill {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  text-transform: capitalize;
}

main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
}

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 720px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- forms ---------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
textarea { resize: vertical; min-height: 68px; }

.field { flex: 1 1 150px; min-width: 0; }

.check { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text); }
.check input { width: auto; }

button.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 520;
  cursor: pointer;
  white-space: nowrap;
}
button.btn:hover { filter: brightness(1.07); }
button.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

button.btn.ghost { background: none; border-color: var(--border); color: var(--text); }
button.btn.ghost:hover { background: var(--surface-2); filter: none; }
button.btn.danger { background: none; border-color: var(--border); color: var(--danger); }
button.btn.danger:hover { background: var(--surface-2); }
button.btn.sm { padding: 4px 9px; font-size: 13px; }

/* ---------- item cards ---------- */

.item {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.item .thumb {
  aspect-ratio: 4 / 3;
  max-width: 100%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
}
.item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item .body { padding: 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.item .name { font-weight: 550; line-height: 1.3; }
.item .price { font-variant-numeric: tabular-nums; }
.item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.item .actions { margin-top: auto; padding-top: 8px; display: flex; gap: 6px; }

.hero-img {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 550; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
code.id { font-size: 12px; color: var(--muted); }

/* ---------- misc ---------- */

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.low { color: var(--warn); }
.tag.out { color: var(--danger); }

.empty { padding: 36px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(360px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast.err { border-left-color: var(--danger); }

.stars { color: var(--warn); letter-spacing: 1px; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
