:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e2dfd8;
  --text: #1d1b18;
  --muted: #6d6860;
  --accent: #c8143c;
  --accent-soft: rgba(200, 20, 60, 0.08);
  --accent-text: #ffffff;
  --sel: #fff3f5;
  --good: #2f7d4f;
  --warn: #b26a00;
  --bar: #e7e3dc;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1c1b19;
    --surface-2: #252320;
    --border: #34312d;
    --text: #ece9e4;
    --muted: #a19b92;
    --accent: #ff4d6d;
    --accent-soft: rgba(255, 77, 109, 0.12);
    --accent-text: #1a0007;
    --sel: #2a1c1f;
    --good: #5cc28a;
    --warn: #f0a54a;
    --bar: #2f2c28;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141312; --surface: #1c1b19; --surface-2: #252320; --border: #34312d;
  --text: #ece9e4; --muted: #a19b92; --accent: #ff4d6d; --accent-soft: rgba(255,77,109,.12);
  --accent-text: #1a0007; --sel: #2a1c1f; --good: #5cc28a; --warn: #f0a54a; --bar: #2f2c28;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
input[type="number"], input[type="search"], input[type="text"], select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Header */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.logo {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: 13px;
}
.weeknav { display: flex; align-items: center; gap: 6px; margin: 0 auto; }
.weeklabel { display: flex; flex-direction: column; align-items: center; min-width: 150px; line-height: 1.2; }
.weeklabel span { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.progress { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.progress::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-weight: 500; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.wide { width: 100%; text-align: center; }
.btn small { display: block; font-size: 11.5px; font-weight: 400; opacity: .85; }
.cline.via { opacity: .7; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 28px; height: 28px; font-size: 14px; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 12px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px 20px 40px;
  align-items: start;
}
.filters, .cart {
  position: sticky; top: calc(var(--hdr, 57px) + 14px);
  max-height: calc(100vh - var(--hdr, 57px) - 30px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filters details { padding: 12px 14px 14px; }
.filters summary { font-weight: 650; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.filters summary::-webkit-details-marker { display: none; }
.pill { background: var(--accent); color: var(--accent-text); border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.fgroup { margin-top: 14px; }
.fgroup > input[type="search"], .fgroup > input[type="text"] { width: 100%; }
.flabel { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 99px;
  padding: 3px 9px; font-size: 12px; cursor: pointer; white-space: nowrap; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.off { text-decoration: line-through; background: var(--surface-2); color: var(--muted); }
.chip .n { opacity: .6; margin-left: 3px; }
.ranges { display: grid; gap: 6px 28px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.ranges label { display: flex; align-items: center; gap: 6px; font-size: 13px; justify-content: space-between; }
.ranges input { width: 70px; padding: 4px 6px; }
.checks { display: grid; gap: 6px; font-size: 13px; }
.checks label { display: flex; gap: 7px; align-items: center; cursor: pointer; }
.hint { margin: 6px 0 0; font-size: 11px; color: var(--muted); }

/* Day tabs */
.daybar {
  position: sticky; top: var(--hdr, 57px); z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 0 0 10px; margin-top: -2px; background: var(--bg);
}
.daybar .icon-btn:disabled { opacity: .35; cursor: default; }
.daytabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: thin; padding: 2px; }
.daytab {
  flex: 1 1 0; min-width: 92px; display: grid; gap: 1px; text-align: left;
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; line-height: 1.25;
}
.daytab:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.daytab.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.daytab .dn { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daytab .dd { font-weight: 400; color: var(--muted); font-size: 12px; }
.daytab .dm { font-size: 12px; color: var(--muted); }
.daytab .picked { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.cday-h { cursor: pointer; }
.cday.cur .cday-h span:first-child { color: var(--accent); }

/* Table */
.tablebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.sortsel { display: flex; align-items: center; gap: 6px; }
.status { padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 8px; font-size: 13px; }
.tablewrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table.menu { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.menu th {
  position: sticky; top: calc(var(--hdr, 57px) + var(--tabs, 0px)); background: var(--surface); z-index: 2;
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 9px 6px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.menu th.sortable { cursor: pointer; user-select: none; }
.menu th.sortable:hover { color: var(--text); }
.menu th.sorted { color: var(--accent); }
.menu th.sorted::after { content: " ↓"; }
.menu th.sorted.asc::after { content: " ↑"; }
.menu td { padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.menu .num { text-align: right; white-space: nowrap; }
.menu td.num { font-size: 13px; }
.menu td.num.dim { color: var(--muted); }
.menu td.num.hi { font-weight: 650; }
.c-img { width: 120px; }
.thumb { position: relative; width: 108px; height: 90px; }
.thumb img, .thumb .noimg { position: absolute; left: 10px; top: 1px; width: 88px; height: 88px; border-radius: 10px; object-fit: cover; display: block; background: var(--surface-2); }
/* Menus: soup and main course, overlapping like two cards */
.thumb.pair img { width: 70px; height: 70px; }
.thumb.pair img:first-child { left: 0; top: 0; }
.thumb.pair img:last-child { left: 38px; top: 20px; box-shadow: 0 0 0 2px var(--surface); }
tr.sel .thumb.pair img:last-child { box-shadow: 0 0 0 2px var(--sel); }
.c-name { min-width: 190px; }
.mname { font-weight: 550; cursor: pointer; }
.mname:hover { color: var(--accent); }
.msub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.code { font-weight: 600; color: var(--text); }
.tag { font-size: 10.5px; padding: 0 6px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.tag.loading { opacity: .6; }
tr.sel td { background: var(--sel); }
tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.closed .mname { color: var(--muted); }
tr.dayhead td {
  background: var(--surface-2); font-weight: 650; font-size: 13px; padding: 8px 10px;
  position: sticky; top: calc(var(--hdr, 57px) + var(--tabs, 0px) + 34px); z-index: 1;
}
tr.dayhead .dsum { font-weight: 400; color: var(--muted); margin-left: 10px; font-size: 12px; }
tr.detail td { background: var(--surface-2); font-size: 12.5px; padding: 10px 14px 12px 60px; }
.detail h4 { margin: 0 0 2px; font-size: 13px; }
.detail p { margin: 0 0 8px; color: var(--muted); }
.detail .alg { color: var(--warn); }
.c-qty { width: 96px; text-align: center; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.qty button { width: 28px; height: 28px; border: 0; background: transparent; cursor: pointer; font-size: 15px; }
.qty button:hover { background: var(--surface-2); }
.qty span { min-width: 22px; text-align: center; font-weight: 600; }
.qty.zero span { color: var(--muted); font-weight: 400; }
.add { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; height: 30px; padding: 0 12px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.add:hover { border-color: var(--accent); color: var(--accent); }
.mmac { display: none; gap: 10px; font-size: 12.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.mmac span { color: var(--muted); }
.mmac b { color: var(--text); font-weight: 600; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Cart */
.cart { display: flex; flex-direction: column; }
.cart-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px; }
.cart-head h2 { margin: 0; font-size: 15px; }
.targets { display: flex; gap: 8px; padding: 0 14px 8px; font-size: 11px; color: var(--muted); }
.targets label { display: grid; gap: 3px; flex: 1; }
.targets input { width: 100%; padding: 4px 6px; font-size: 13px; }
.cart-body { padding: 0 14px; }
.cday { border-top: 1px solid var(--border); padding: 10px 0; }
.cday-h { display: flex; justify-content: space-between; font-weight: 650; font-size: 13px; }
.cday-h span:last-child { font-weight: 500; color: var(--muted); }
.cline { display: grid; grid-template-columns: auto minmax(0, 1fr) auto 22px; gap: 6px; font-size: 12.5px; padding: 2px 0; align-items: center; }
.cq { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.cq button { width: 20px; height: 20px; border: 0; background: transparent; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; color: var(--muted); }
.cq button:hover { background: var(--surface-2); color: var(--text); }
.cq b { min-width: 16px; text-align: center; color: var(--accent); font-weight: 650; }
.cline .del { width: 22px; height: 22px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 0; }
.cline .del:hover { background: var(--accent-soft); color: var(--accent); }
.cline.via .q { text-align: center; min-width: 58px; }
.cline .q { color: var(--accent); font-weight: 650; }
.cline .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cline .pr { color: var(--muted); white-space: nowrap; }
.macros { display: flex; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.macros b { color: var(--text); font-weight: 600; }
.meter { margin-top: 5px; display: grid; gap: 3px; }
.meter div { display: grid; grid-template-columns: 54px 1fr 64px; gap: 6px; align-items: center; font-size: 11px; color: var(--muted); }
.meter i { display: block; height: 5px; border-radius: 3px; background: var(--bar); overflow: hidden; }
.meter i b { display: block; height: 100%; background: var(--good); }
.meter i b.over { background: var(--warn); }
.meter em { font-style: normal; text-align: right; font-variant-numeric: tabular-nums; }
.cart-empty { color: var(--muted); font-size: 13px; padding: 16px 0; border-top: 1px solid var(--border); }
.cart-foot { padding: 12px 14px 14px; border-top: 1px solid var(--border); margin-top: 8px; display: grid; gap: 10px; }
.cart-total { display: grid; gap: 4px; }
.cart-total .big { display: flex; justify-content: space-between; font-size: 16px; font-weight: 700; }
.howto { font-size: 12.5px; color: var(--muted); }
.howto summary { cursor: pointer; }
.howto ol { padding-left: 18px; margin: 8px 0 0; display: grid; gap: 6px; }
.bookmarklet {
  display: inline-block; margin: 4px 6px 2px 0; padding: 4px 10px; border-radius: 7px;
  background: var(--accent); color: var(--accent-text); text-decoration: none; font-weight: 600; cursor: grab;
}

.thumb[data-preview] { cursor: zoom-in; }
.preview {
  position: fixed; z-index: 60; pointer-events: none;
  display: flex; gap: 10px; padding: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
.preview figure { margin: 0; width: min(340px, calc((100vw - 60px) / 2)); }
.preview:not(.pair) figure { width: min(380px, calc(100vw - 40px)); }
.preview img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.preview figcaption { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.3; }

.mobilebar { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px);
}

@media (max-width: 1440px) {
  .layout { grid-template-columns: 230px minmax(0, 1fr); }
  .cart { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .filters { position: static; max-height: none; }
}
@media (max-width: 860px) {
  .top { padding: 8px 16px; gap: 8px; flex-wrap: wrap; }
  .brand span:last-child { display: none; }
  .weeknav { margin: 0; flex: 1; justify-content: center; }
  .weeklabel { min-width: 0; }
  .progress { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 80px; gap: 12px; }
  .filters { position: static; max-height: none; }
  .filters details:not([open]) { padding-bottom: 12px; }
  /* Rows become cards */
  .menu thead { display: none; }
  .menu, .menu tbody { display: block; }
  tr.dayhead { display: block; position: sticky; top: calc(var(--hdr, 57px) + var(--tabs, 0px)); z-index: 1; }
  .daybar { gap: 6px; }
  .daybar .icon-btn { display: none; }
  .daytab { min-width: 88px; padding: 6px 10px; }
  tr.dayhead td { display: block; position: static; }
  tr[data-id] {
    display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 2px 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--border); align-items: start;
  }
  tr[data-id] td { padding: 0; border: 0; background: none !important; box-shadow: none !important; }
  tr.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
  .c-img { grid-row: 1 / span 3; width: auto; }
  .c-name { min-width: 0; grid-column: 2 / 4; }
  .menu td.num { display: none; }
  .mmac { display: flex !important; }
  tr[data-id] { grid-template-areas: "img name name" "img price qty"; }
  .c-img { grid-area: img; }
  .c-name { grid-area: name; }
  .thumb { width: 84px; height: 72px; }
  .thumb img, .thumb .noimg { left: 6px; width: 72px; height: 72px; }
  .thumb.pair img { width: 56px; height: 56px; }
  .thumb.pair img:last-child { left: 26px; top: 16px; }
  .menu td.c-price { display: block; grid-area: price; align-self: center; text-align: left; font-weight: 600; }
  .c-qty { grid-area: qty; width: auto; text-align: right; }
  tr.detail { display: block; }
  tr.detail td { display: block; padding: 10px 14px; }
  .mobilebar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--border);
    font-size: 13px;
  }
}
