:root {
  --bg: #16120e;
  --surface: #211b15;
  --surface-2: #2b241c;
  --border: #3a3027;
  --text: #f3ebe1;
  --muted: #b3a491;
  --faint: #7d6f60;
  --accent: #e0a44a;
  --accent-ink: #1b1309;
  --good: #7fc28a;
  --good-bg: rgba(127, 194, 138, .14);
  --bad: #e5806f;
  --bad-bg: rgba(229, 128, 111, .14);
  --warn: #e3c065;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 24px; background: rgba(22, 18, 14, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font: 600 20px var(--serif); }
.brand-mark { font-size: 22px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs a {
  padding: 7px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap;
}
.tabs a:hover { color: var(--text); background: var(--surface); }
.tabs a.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.view { max-width: 1240px; margin: 0 auto; padding: 24px; }
h1 { font: 600 28px/1.2 var(--serif); margin: 0 0 4px; }
h2 { font: 600 20px/1.3 var(--serif); margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ---------- controls ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .grow { flex: 1 1 220px; }
input[type=text], input[type=search], input[type=url], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 0 4px; }
.link-btn:hover { color: var(--bad); }

.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: transparent; cursor: pointer; color: var(--muted);
}
.pill.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.pill .n { color: var(--faint); margin-left: 4px; }

/* ---------- inventory grid ---------- */
.summary { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); margin-bottom: 14px; font-size: 14px; }
.summary b { color: var(--text); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform .12s, border-color .12s; display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-2px); border-color: var(--faint); }
.card.empty { opacity: .55; }
.card-photo { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; font-size: 46px; overflow: hidden; }
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.card-title { font-weight: 600; line-height: 1.25; }
.card-meta { font-size: 13px; color: var(--muted); }
.fill { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.fill > span { display: block; height: 100%; background: var(--accent); }
.fill.low > span { background: var(--bad); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: rgba(227, 192, 101, .14); color: var(--warn); }

.category-heading { grid-column: 1 / -1; margin: 10px 0 -4px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- stars ---------- */
.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: 0; padding: 0 1px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--faint); }
.stars button.on { color: var(--accent); }
.stars.readonly { font-size: 13px; color: var(--accent); letter-spacing: 1px; }

/* ---------- recipes ---------- */
.recipe-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.recipe-card { padding: 14px 16px; display: grid; gap: 8px; }
.recipe-card header { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.recipe-card .name { font: 600 18px/1.25 var(--serif); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; border: 1px solid transparent; }
.chip.have { background: var(--good-bg); color: var(--good); }
.chip.similar { background: rgba(227, 192, 101, .12); color: var(--warn); }
.chip.missing { background: var(--bad-bg); color: var(--bad); }
.chip.optional { background: transparent; border-color: var(--border); color: var(--faint); }
.status-line { font-size: 13px; }
.status-line.ok { color: var(--good); }
.status-line.no { color: var(--bad); }
.heart { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--faint); padding: 0; }
.heart.on { color: var(--bad); }
.thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; }

/* ---------- modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-root[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.modal {
  position: relative; width: min(920px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 24px;
}
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; font-size: 28px; color: var(--muted); cursor: pointer; }
.detail { display: grid; grid-template-columns: 280px 1fr; gap: 24px; }
.detail-photo { border-radius: var(--radius); overflow: hidden; background: var(--surface-2); aspect-ratio: 3 / 4; display: grid; place-items: center; font-size: 80px; }
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.actions .spacer { flex: 1; }

.ing-table { width: 100%; border-collapse: collapse; }
.ing-table td { padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ing-table td.amt { color: var(--muted); white-space: nowrap; width: 1%; }
.ing-table td.state { width: 1%; white-space: nowrap; font-size: 13px; }
.ing-table .ok { color: var(--good); }
.ing-table .no { color: var(--bad); }
.ing-table .sim { color: var(--warn); }
.instructions { white-space: pre-wrap; line-height: 1.6; }

.comments { display: grid; gap: 8px; }
.comment { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.comment .when { font-size: 12px; color: var(--faint); display: flex; justify-content: space-between; }
.comment-form { display: flex; gap: 8px; margin-top: 8px; }
.comment-form textarea { min-height: 42px; }

.ing-rows { display: grid; gap: 8px; }
.ing-row { display: grid; grid-template-columns: 2fr 1fr auto auto; gap: 8px; align-items: center; }
.ing-row label { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; }

/* ---------- import ---------- */
.dropzone {
  display: block;
  border: 2px dashed var(--border); border-radius: 16px; padding: 36px 20px; text-align: center; background: var(--surface);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.dropzone.drag { border-color: var(--accent); background: var(--surface-2); }
.dropzone .big { font-size: 44px; }
.notice { background: var(--surface-2); border-left: 3px solid var(--warn); padding: 10px 14px; border-radius: 8px; margin: 14px 0; color: var(--muted); }
.notice.err { border-left-color: var(--bad); }
.import-photo { display: grid; grid-template-columns: 180px 1fr; gap: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-top: 14px; }
.import-photo img { border-radius: 10px; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.import-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.import-table th { text-align: left; font-weight: 500; color: var(--faint); font-size: 12px; padding: 0 4px 4px; }
.import-table td { padding: 3px 4px; vertical-align: middle; }
.import-table input, .import-table select { padding: 6px 8px; font-size: 14px; }
.import-table .num { width: 78px; }
.conf { font-size: 11px; }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 20px 0 8px; display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- discover / shopping ---------- */
.online-card { display: flex; gap: 12px; padding: 12px; align-items: flex-start; }
.shop-list { display: grid; gap: 10px; }
.shop-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; }
.shop-item .ing { font-weight: 600; font-size: 16px; }
.shop-item .count { font: 600 22px var(--serif); color: var(--accent); text-align: right; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .big { font-size: 52px; }
.loading { color: var(--muted); padding: 30px; text-align: center; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); font-weight: 500;
}
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .view { padding: 16px; }
  .detail { grid-template-columns: 1fr; }
  .detail-photo { aspect-ratio: 4 / 3; max-height: 260px; }
  .form-grid { grid-template-columns: 1fr; }
  .import-photo { grid-template-columns: 1fr; }
  .import-photo img { aspect-ratio: 4 / 3; }
  .import-table thead { display: none; }
  .import-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .import-table td { padding: 0; }
  .import-table td.wide { grid-column: 1 / -1; }
  .import-table .num { width: 100%; }
  .ing-row { grid-template-columns: 1fr 1fr; }
  .recipe-list { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
