:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2b2018;
  --muted: #8a7d70;
  --line: #ece4d8;
  --brand: #7c2d12;
  --brand-soft: #fbeae0;
  --accent: #c2410c;
  --green: #2f7d32;
  --amber: #b7791f;
  --red: #c0392b;
  --shadow: 0 1px 3px rgba(60, 40, 20, .08), 0 6px 18px rgba(60, 40, 20, .06);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- Landing ---------- */
.landing { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.landing-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 32px 24px; max-width: 380px; width: 100%; text-align: center;
}
.landing .logo { font-size: 54px; }
.landing h1 { margin: 8px 0 4px; color: var(--brand); }
.landing p { color: var(--muted); margin: 8px 0 20px; }
.landing-card form { display: flex; flex-direction: column; gap: 10px; }
.landing-card input {
  padding: 14px 16px; border: 1.5px solid var(--line); border-radius: 12px; font-size: 17px;
}
.landing-card input:focus { outline: none; border-color: var(--accent); }
.landing-card button {
  padding: 14px; background: var(--brand); color: #fff; border-radius: 12px;
  font-size: 17px; font-weight: 600;
}
.hint { font-size: 13px; }
.hint code { background: var(--brand-soft); padding: 1px 6px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.link-btn { color: #fff; opacity: .85; text-decoration: underline; font-size: 14px; }

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg); padding: 12px 16px 6px;
  border-bottom: 1px solid var(--line);
}
.toolbar #search {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 16px; background: var(--card);
}
.toolbar #search:focus { outline: none; border-color: var(--accent); }
.toolbar-row { display: flex; gap: 8px; margin-top: 8px; }
.toolbar-row select {
  flex: 1; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: 10px; background: var(--card); font-size: 15px;
}
.chip {
  border: 1.5px solid var(--line); background: var(--card);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}
.chip.toggle.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.tag-filters { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; }
.tag-filters::-webkit-scrollbar { display: none; }
.tag-filters .chip { font-size: 13px; padding: 6px 12px; }
.tag-filters .chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Summary ---------- */
.summary { padding: 10px 16px 0; font-size: 13px; color: var(--muted); }
.summary b { color: var(--accent); }

/* ---------- List ---------- */
.list { padding: 12px 16px 96px; display: flex; flex-direction: column; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; border: 1px solid var(--line);
}
.card.low { border-color: #f0c9b0; }
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-title { flex: 1; min-width: 0; }
.card-title h3 { margin: 0; font-size: 17px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.cat { font-size: 12px; color: var(--muted); }
.edit-btn { color: var(--muted); font-size: 20px; padding: 0 4px; line-height: 1; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge.fresh   { background: #e3f2e4; color: var(--green); }
.badge.fading  { background: #fcf1da; color: var(--amber); }
.badge.stale   { background: #fbe3df; color: var(--red); }
.badge.unknown { background: #eee9e1; color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tags .t { font-size: 11px; background: var(--brand-soft); color: var(--brand);
  padding: 2px 8px; border-radius: 999px; }

/* Fullness control */
.fullness { display: flex; gap: 4px; margin-top: 12px; }
.fullness button {
  flex: 1; padding: 9px 0; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted);
  transition: background .12s, color .12s;
}
.fullness button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.fullness button.out.on { background: #6b7280; border-color: #6b7280; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; background: var(--brand);
  color: #fff; font-size: 32px; line-height: 1; box-shadow: var(--shadow); z-index: 30;
}

/* ---------- Sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(40, 25, 15, .45);
  z-index: 40; display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto; animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 99px; margin: 6px auto 10px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field > span em { font-weight: 400; font-style: normal; opacity: .8; }
.field input, .field select, .field textarea {
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 11px;
  font-size: 16px; background: var(--card);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.autocomplete-wrap { position: relative; }
.catalog-dropdown {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 200;
  background: var(--card); border: 1.5px solid var(--accent);
  border-radius: 11px; box-shadow: var(--shadow); max-height: 240px; overflow-y: auto;
}
.catalog-dropdown .ac-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; font-size: 16px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.catalog-dropdown .ac-item:last-child { border-bottom: none; }
.catalog-dropdown .ac-item:hover,
.catalog-dropdown .ac-item.focused { background: var(--brand-soft); }
.catalog-dropdown .ac-item .ac-cat { font-size: 12px; color: var(--muted); }

.tag-edit { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-edit:empty { display: none; }
.tag-edit .t {
  font-size: 13px; background: var(--brand-soft); color: var(--brand);
  padding: 4px 8px 4px 10px; border-radius: 999px; display: inline-flex; gap: 6px; align-items: center;
}
.tag-edit .t button { color: var(--brand); font-weight: 700; opacity: .7; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 5px; margin: 2px 0; }
.tag-suggest button {
  font-size: 12px; border: 1px dashed var(--line); color: var(--muted);
  padding: 4px 9px; border-radius: 999px;
}

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.sheet-actions .spacer { flex: 1; }
.sheet-actions button { padding: 12px 18px; border-radius: 11px; font-weight: 600; font-size: 15px; }
.primary { background: var(--brand); color: #fff; }
.ghost { color: var(--muted); }
.danger { color: var(--red); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 50; box-shadow: var(--shadow);
}
