:root {
  --ink: #14202e;
  --navy: #1b3a57;
  --navy-2: #123047;
  --paper: #efeae0;
  --card: #fbf7f0;
  --line: #d4cdc0;
  --terra: #b85a2a;
  --muted: #6b6258;
  --green: #c6efce;
  --amber: #ffeb9c;
  --red: #ffc7ce;
  --head: #1b4f72;
  --sticky: #f4efe6;
  --freeze-w1: 128px;
  --freeze-w2: 168px;
  --freeze-w3: 180px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background: var(--paper);
  font: 13px/1.45 "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 20px 0;
  background: var(--navy-2);
  color: #f4efe6;
}
.brand-block h1 {
  margin: 0 0 12px;
  font: 22px/1.2 "Iowan Old Style", Palatino, "Songti SC", serif;
  font-weight: 600;
}
.tabs { display: flex; gap: 2px; }
.tab {
  border: 0;
  background: transparent;
  color: #c9c0b3;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  font: inherit;
}
.tab.is-on { background: var(--paper); color: var(--ink); font-weight: 600; }

.cat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: end;
  padding: 10px 20px;
  background: #e7e0d4;
  border-bottom: 1px solid var(--line);
}
.cat-bar label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}
.cat-bar input,
.cat-bar select {
  font: inherit;
  color: var(--ink);
  background: #fff8c8;
  border: 1px solid #d9c56a;
  border-radius: 3px;
  padding: 4px 6px;
  min-width: 84px;
}
.kcal-chip {
  margin-left: auto;
  align-self: center;
  background: var(--navy);
  color: #f4efe6;
  padding: 6px 12px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.fdshare-hint {
  flex: 1 0 100%;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 10px 20px;
}
.search {
  flex: 1;
  min-width: 220px;
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card);
}
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.meat-bar {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.meat-bar .lab {
  color: var(--muted);
  font-size: 11px;
  margin-right: 2px;
}
.pill.meat { background: #fff; }
.pill.meat.is-on { background: var(--terra); color: #fff; border-color: var(--terra); }
.pill {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}
.pill.is-on { background: var(--navy); color: #f4efe6; }
.pill.is-on.c-green, td.c-green, .legend .c-green { background: var(--green); color: var(--ink); }
.pill.is-on.c-amber, td.c-amber, .legend .c-amber { background: var(--amber); color: var(--ink); }
.pill.is-on.c-red, td.c-red, .legend .c-red { background: var(--red); color: var(--ink); }
[hidden] { display: none !important; }
.check { color: var(--muted); font-size: 12px; display: flex; gap: 4px; align-items: center; }
.count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.table-wrap {
  flex: 1;
  overflow: auto;
  background: var(--card);
  border-top: 1px solid var(--line);
}
table#grid {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
  font-variant-numeric: tabular-nums;
}
#grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--head);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 0;
  border-right: 1px solid #163e5c;
  white-space: nowrap;
}
#grid th .h {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px;
  min-height: 38px;
}
#grid th button.sort {
  all: unset;
  cursor: pointer;
  display: block;
  white-space: nowrap;
}
#grid th .filter {
  all: unset;
  cursor: pointer;
  opacity: 0.85;
  width: 16px;
  height: 16px;
  text-align: center;
  font-size: 10px;
}
#grid th .filter.is-on { color: #ffeb9c; }
#grid td {
  padding: 5px 8px;
  border-bottom: 1px solid #ece6db;
  border-right: 1px solid #ece6db;
  vertical-align: top;
  background: var(--card);
  max-width: 220px;
}
#grid tbody tr:hover td { filter: brightness(0.97); }
#grid tbody tr.is-open td { outline: 1px solid var(--terra); }
#grid .num { text-align: right; }
#grid .na { color: #a3988c; }
#grid .clip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#grid a { color: var(--terra); }
#grid td.freeze, #grid th.freeze {
  position: sticky;
  z-index: 2;
  background: var(--sticky);
}
#grid thead th.freeze { z-index: 4; background: var(--head); }
#grid td.freeze-1, #grid th.freeze-1 { left: 0; width: var(--freeze-w1); min-width: var(--freeze-w1); max-width: var(--freeze-w1); }
#grid td.freeze-2, #grid th.freeze-2 { left: var(--freeze-w1); width: var(--freeze-w2); min-width: var(--freeze-w2); max-width: var(--freeze-w2); }
#grid td.freeze-3, #grid th.freeze-3 { left: calc(var(--freeze-w1) + var(--freeze-w2)); width: var(--freeze-w3); min-width: var(--freeze-w3); max-width: var(--freeze-w3); }
#grid:not(:has(.freeze-3)) td.freeze-2,
#grid:not(:has(.freeze-3)) th.freeze-2,
#grid td.freeze-3,
#grid th.freeze-3 { box-shadow: 4px 0 0 #d8cfc2; }
#grid td.c-green { background: var(--green); }
#grid td.c-amber { background: var(--amber); }
#grid td.c-red { background: var(--red); }
#grid td.freeze.c-green { background: var(--green); }
#grid td.freeze.c-amber { background: var(--amber); }
#grid td.freeze.c-red { background: var(--red); }

.pair { padding: 12px 20px 28px; overflow: auto; flex: 1; }
.pair-lead { margin: 0 0 12px; }
.pair-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}
.pair-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}
.pair-card .side {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: start;
}
.pair-card .kind {
  font-size: 11px;
  color: #fff;
  background: var(--navy);
  border-radius: 4px;
  padding: 2px 6px;
  text-align: center;
  align-self: start;
}
.pair-card .kind.fd { background: var(--terra); }
.pair-card .name { font-weight: 600; overflow-wrap: anywhere; }
.pair-card .sub { color: var(--muted); font-size: 12px; }
.pair-card .grams {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 600;
}
.pair-card .mix {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
  font-variant-numeric: tabular-nums;
}
.pair-card .badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.meat-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.meat-tags span {
  font-size: 11px;
  background: #efe6d8;
  padding: 1px 6px;
  border-radius: 999px;
}

.std { padding: 20px; overflow: auto; flex: 1; }
.std-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.9fr;
  gap: 20px;
}
.std h2 {
  margin: 0 0 8px;
  font: 18px/1.3 "Iowan Old Style", Palatino, "Songti SC", serif;
}
.note { color: var(--muted); font-size: 12px; white-space: pre-line; }
.plain { width: 100%; border-collapse: collapse; background: var(--card); }
.plain th, .plain td { border: 1px solid var(--line); padding: 7px 8px; text-align: left; }
.plain th { background: var(--head); color: #fff; }
.legend { display: flex; gap: 8px; margin-top: 18px; }
.legend span { padding: 4px 10px; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--line);
  z-index: 8;
  overflow: auto;
  padding: 20px 20px 40px;
}
.drawer h3 { margin: 0 12px 8px 0; font: 18px/1.3 "Iowan Old Style", Palatino, "Songti SC", serif; }
.drawer dl { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; overflow-wrap: anywhere; }
.drawer-x {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
}
.scrim {
  position: fixed;
  inset: 0;
  background: rgb(20 32 46 / 0.28);
  z-index: 7;
}
.filter-pop {
  position: fixed;
  z-index: 9;
  width: 240px;
  max-height: 360px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--navy);
  padding: 8px;
}
.filter-pop input[type="search"] {
  width: 100%;
  margin-bottom: 6px;
  font: inherit;
}
.filter-pop .opts { display: flex; flex-direction: column; gap: 3px; max-height: 240px; overflow: auto; }
.filter-pop .row { display: flex; gap: 6px; align-items: center; font-size: 12px; }
.filter-pop .actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.filter-pop button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--navy);
  color: #fff;
  padding: 4px 10px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .std-grid { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: stretch; }
  #grid td.freeze-2, #grid th.freeze-2,
  #grid td.freeze-3, #grid th.freeze-3 { box-shadow: none; }
  .pair-grid { grid-template-columns: 1fr; }
}
