:root {
  color-scheme: light;
  --ink: #26312d;
  --muted: #67736d;
  --brand: #c85f35;
  --brand-dark: #9b4326;
  --brand-soft: #fff1e9;
  --green: #39735d;
  --green-soft: #e8f4ee;
  --pediatric: #49699a;
  --pediatric-soft: #edf3ff;
  --warn: #9a6815;
  --warn-soft: #fff4d8;
  --line: #dedfd9;
  --paper: #fffefb;
  --surface: #f5f3ed;
  --shadow: 0 10px 30px rgb(47 54 49 / 8%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgb(255 222 203 / 58%), transparent 28rem),
    var(--surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.65;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 72px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.brand-heading { display: flex; align-items: center; gap: 14px; }
.brand-icon { width: 58px; height: 58px; object-fit: contain; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: clamp(1.55rem, 3vw, 2.15rem); line-height: 1.3; }
.app-subtitle { margin-bottom: 0; color: var(--muted); }
.status { margin: 0; color: var(--green); font-weight: 700; white-space: nowrap; }

.intro-card,
.filter-panel,
.results-panel {
  border: 1px solid rgb(202 199 190 / 80%);
  border-radius: 22px;
  background: rgb(255 254 251 / 94%);
  box-shadow: var(--shadow);
}

.intro-card { margin-bottom: 18px; padding: 17px 22px; }
.intro-card p { margin: 0; color: #58625d; font-size: .86rem; line-height: 1.75; }
.intro-card .data-date-note { margin-top: 7px; color: #7a675d; font-size: .78rem; }
.workspace { display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); gap: 20px; align-items: start; }
.filter-panel { padding: 24px; }
.results-panel { min-height: 520px; padding: 24px; }

.filter-heading,
.result-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--brand);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.filter-heading h2,
.result-heading h2 { margin-bottom: 0; line-height: 1.25; }
.result-heading h2 { font-size: 2.15rem; color: var(--brand-dark); }
.result-heading h2 small { margin-left: 5px; font-size: .9rem; color: var(--muted); }

.reset-button {
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reset-button:disabled { color: #a2a5a0; cursor: default; text-decoration: none; }

.status-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 9px 0 4px;
  padding: 14px;
  border: 1px solid #efc7ae;
  border-radius: 15px;
  background: var(--brand-soft);
  cursor: pointer;
}

.status-toggle:first-of-type { margin-top: 21px; }
.status-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; flex: 0 0 42px; width: 42px; height: 24px; border-radius: 20px; background: #bcbdb8; transition: .2s; }
.toggle-track span { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: .2s; }
.status-toggle input:checked + .toggle-track { background: var(--brand); }
.status-toggle input:checked + .toggle-track span { transform: translateX(18px); }
.status-toggle input:focus-visible + .toggle-track { outline: 3px solid rgb(200 95 53 / 32%); outline-offset: 2px; }
.pediatric-toggle { border-color: #c8d7ef; background: var(--pediatric-soft); }
.pediatric-toggle input:checked + .toggle-track { background: var(--pediatric); }
.status-toggle-secondary { border-color: #d7d5cf; background: #f3f2ee; }
.status-toggle-secondary input:checked + .toggle-track { background: #777b77; }
.status-toggle strong, .status-toggle small { display: block; }
.status-toggle strong { font-size: .91rem; }
.status-toggle small { color: var(--muted); font-size: .76rem; line-height: 1.45; }

.product-search { display: grid; gap: 7px; margin-top: 17px; }
.product-search span { font-size: .88rem; font-weight: 800; }
.product-search input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  outline: none;
}
.product-search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(200 95 53 / 14%); }
.product-search input::placeholder { color: #969d98; }

.filter-section { margin: 24px 0 0; padding: 22px 0 0; border: 0; border-top: 1px solid var(--line); }
.filter-section legend,
.filter-section h3 { margin: 0 0 9px; padding: 0; font-size: 1rem; font-weight: 800; }
.section-help { margin: -3px 0 12px; color: var(--muted); font-size: .8rem; }
.category-checks { display: grid; gap: 7px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; padding: 7px 8px; border-radius: 9px; cursor: pointer; }
.check-row:hover { background: #f8f5ef; }
.check-row input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--brand); }
.check-row span { font-size: .87rem; }

.ingredient-accordions { display: grid; gap: 8px; }
.ingredient-group { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: white; }
.ingredient-group summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 13px; cursor: pointer; font-size: .85rem; font-weight: 800; list-style: none; }
.ingredient-group summary::-webkit-details-marker { display: none; }
.ingredient-group summary::after { content: "+"; color: var(--brand); font-size: 1.2rem; }
.ingredient-group[open] summary::after { content: "−"; }
.group-count { margin-left: auto; color: var(--muted); font-size: .73rem; font-weight: 600; }
.ingredient-options { display: grid; gap: 2px; max-height: 275px; overflow-y: auto; padding: 3px 8px 10px; border-top: 1px solid #eeeae2; }
.ingredient-choice-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: center; padding: 7px 5px; border-radius: 9px; }
.ingredient-choice-row:hover { background: #f8f5ef; }
.ingredient-choice-name { min-width: 0; font-size: .8rem; overflow-wrap: anywhere; }
.ingredient-choice-buttons { display: flex; gap: 5px; }
.ingredient-choice { padding: 4px 7px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--muted); font-size: .69rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.ingredient-choice:hover { border-color: #d69a7b; }
.include-choice.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); box-shadow: inset 0 0 0 1px var(--brand); }
.exclude-choice.is-active { border-color: #8b7770; background: #eee8e5; color: #674d43; box-shadow: inset 0 0 0 1px #8b7770; }
.ingredient-choice:focus-visible { outline: 3px solid rgb(200 95 53 / 20%); outline-offset: 1px; }

.result-sticky { margin-bottom: 16px; }
.visible-summary { margin: 10px 0 0; color: var(--muted); font-size: .84rem; }
.active-filters { display: flex; flex-wrap: wrap; gap: 7px; min-height: 0; margin-top: 12px; }
.filter-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid #efc5ae; border-radius: 999px; padding: 5px 8px 5px 10px; background: var(--brand-soft); color: var(--brand-dark); font-size: .76rem; font-weight: 700; cursor: pointer; }
.filter-chip:hover { border-color: var(--brand); background: #ffe8dc; }
.filter-chip:focus-visible { outline: 3px solid rgb(200 95 53 / 22%); outline-offset: 2px; }
.chip-remove { font-size: 1rem; line-height: 1; }
.filter-chip.pediatric-chip { border-color: #b8cae7; background: var(--pediatric-soft); color: #395783; }
.filter-chip.status-chip { border-color: #e6cc8a; background: var(--warn-soft); color: #76500e; }
.filter-chip.discontinued-chip { border-color: #ccccc8; background: #eeeeeb; color: #626662; }
.filter-chip.exclude-chip { border-color: #bda9a1; background: #f0e9e6; color: #674d43; }
.no-filter-note { color: var(--muted); font-size: .8rem; }

.product-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.product-card { display: flex; flex-direction: column; align-self: start; min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.product-card.is-unconfirmed { border-color: #e8d29d; background: #fffdf7; }
.product-card.is-discontinued { border-color: #d7d5cf; background: #f7f7f5; }
.product-card.is-pediatric { box-shadow: inset 0 3px 0 #8ba9d8; }
.product-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.product-name { margin: 0; font-size: 1rem; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-line; }
.product-badges { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.status-pill,
.pediatric-pill { border-radius: 999px; padding: 4px 8px; font-size: .68rem; font-weight: 800; white-space: nowrap; }
.status-pill { background: var(--green-soft); color: var(--green); }
.status-pill.is-unconfirmed { background: var(--warn-soft); color: var(--warn); }
.status-pill.is-discontinued { background: #e9e9e6; color: #666a66; }
.pediatric-pill { background: var(--pediatric-soft); color: var(--pediatric); }
.meta-list { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 13px; }
.meta-pill { display: inline-flex; gap: 4px; border-radius: 7px; padding: 3px 7px; background: #f1f1ed; color: #5f6964; font-size: .7rem; }
.meta-pill small { color: #89908c; font-size: inherit; }
.product-dose-note { margin: -3px 0 12px; padding: 8px 10px; border-left: 3px solid #8ba9d8; border-radius: 7px; background: var(--pediatric-soft); color: #3d5478; font-size: .76rem; font-weight: 700; }
.product-dose-note span { display: block; color: #7488a8; font-size: .67rem; font-weight: 600; }
.ingredient-list { display: grid; gap: 6px; margin: 0; padding: 11px 0 0; border-top: 1px solid #ece9e2; list-style: none; }
.ingredient-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: start; padding: 5px; border-left: 3px solid transparent; border-radius: 7px; font-size: .78rem; }
.ingredient-item.is-match { border-left-color: var(--brand); background: var(--brand-soft); }
.ingredient-name { overflow-wrap: anywhere; }
.ingredient-category { display: block; color: #8a918d; font-size: .67rem; }
.ingredient-amount { color: var(--brand-dark); font-weight: 750; text-align: right; white-space: nowrap; }
.ingredient-amount small { display: block; color: #929994; font-size: .62rem; font-weight: 600; }
.ingredient-note { grid-column: 1 / -1; color: #68726d; font-size: .7rem; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.article-link { align-self: flex-start; margin-top: 14px; border-radius: 10px; padding: 8px 11px; background: var(--brand-soft); color: var(--brand-dark); font-size: .76rem; font-weight: 800; text-decoration: none; }
.article-link:hover { background: #ffe5d7; text-decoration: underline; text-underline-offset: 2px; }
.article-link:focus-visible { outline: 3px solid rgb(200 95 53 / 24%); outline-offset: 2px; }

.more-button { display: block; width: min(360px, 100%); margin: 22px auto 0; padding: 12px 18px; border: 0; border-radius: 12px; background: var(--brand); color: white; font-weight: 800; cursor: pointer; box-shadow: 0 6px 16px rgb(155 67 38 / 20%); }
.more-button:hover { background: var(--brand-dark); }
.empty-state { margin-top: 18px; padding: 34px 18px; border: 1px dashed #d5d3cc; border-radius: 16px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state p { margin: 5px 0 0; }
.is-hidden { display: none !important; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .product-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .app-shell { width: min(100% - 20px, 620px); padding: 20px 0 48px; }
  .app-header { align-items: flex-start; }
  .brand-icon { width: 48px; height: 48px; }
  .status { display: none; }
  .intro-card, .filter-panel, .results-panel { border-radius: 17px; }
  .filter-panel, .results-panel { padding: 18px; }
  .product-list { grid-template-columns: 1fr; }
  .ingredient-item { grid-template-columns: minmax(0, 1fr) minmax(78px, auto); }
}

@media (max-width: 430px) {
  .ingredient-choice-row { grid-template-columns: 1fr; }
  .ingredient-choice-buttons { justify-content: flex-start; }
  .product-top { display: block; }
  .product-badges { justify-content: flex-start; margin-top: 7px; }
}

.filter-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-disclosure > summary {
  margin: 0 0 9px;
  padding: 0;
  font-size: 1rem;
  font-weight: 800;
  list-style: none;
}

.filter-disclosure > summary::-webkit-details-marker { display: none; }
.filter-disclosure-content { display: block; }
.result-heading-actions { text-align: right; }

.filter-backdrop,
.mobile-filter-close,
.mobile-filter-count,
.mobile-filter-action,
.mobile-condition-button {
  display: none;
}

.mobile-filter-scroll { display: contents; }

@media (min-width: 641px) {
  .filter-disclosure > summary {
    pointer-events: none;
  }
}

@media (max-width: 640px) {
  body.mobile-filters-open { overflow: hidden; }

  .workspace { display: block; }

  .filter-backdrop {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: block;
    visibility: hidden;
    background: rgb(38 49 45 / 48%);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
  }

  body.mobile-filters-open .filter-backdrop {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  .filter-panel {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform: translateY(100%);
    visibility: hidden;
    transition: transform .22s ease, visibility .22s ease;
  }

  body.mobile-filters-open .filter-panel {
    transform: translateY(0);
    visibility: visible;
  }

  .mobile-filter-scroll {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 18px 16px 24px;
    overscroll-behavior: contain;
  }

  .filter-heading {
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }

  .filter-heading-actions { gap: 12px; }

  .mobile-filter-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 6px 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: white;
    color: var(--ink);
    font-size: .82rem;
    font-weight: 800;
    cursor: pointer;
  }

  .mobile-filter-count {
    display: block;
    margin: 14px 0 4px;
    color: var(--muted);
    font-size: .86rem;
  }

  .mobile-filter-count strong {
    margin-right: 4px;
    color: var(--brand-dark);
    font-size: 1.45rem;
  }

  .filter-disclosure {
    margin-top: 14px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
    overflow: hidden;
  }

  .filter-disclosure > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0;
    padding: 13px 14px;
    cursor: pointer;
  }

  .filter-disclosure > summary::after {
    content: "+";
    color: var(--brand);
    font-size: 1.2rem;
  }

  .filter-disclosure[open] > summary::after { content: "−"; }

  .filter-disclosure-content {
    padding: 1px 12px 13px;
    border-top: 1px solid #eeeae2;
  }

  .filter-disclosure-content .section-help { margin-top: 10px; }

  .ingredient-options {
    max-height: none;
    overflow-y: visible;
  }

  .result-heading { align-items: flex-end; }
  .result-heading-actions {
    display: grid;
    justify-items: end;
    gap: 7px;
  }

  .visible-summary { margin: 0; }

  .mobile-condition-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid #d89978;
    border-radius: 10px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-size: .8rem;
    font-weight: 800;
    cursor: pointer;
  }

  .mobile-condition-button:focus-visible,
  .mobile-filter-close:focus-visible {
    outline: 3px solid rgb(200 95 53 / 24%);
    outline-offset: 2px;
  }

  .mobile-filter-action {
    position: static;
    flex: 0 0 auto;
    display: none;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid #d8d7d1;
    background: rgb(255 254 251 / 96%);
    box-shadow: 0 -7px 22px rgb(47 54 49 / 12%);
    backdrop-filter: blur(8px);
  }

  body.mobile-filters-open .mobile-filter-action { display: block; }

  .mobile-filter-action button {
    display: block;
    width: min(520px, 100%);
    min-height: 50px;
    margin: 0 auto;
    border: 0;
    border-radius: 12px;
    background: var(--brand);
    color: white;
    font-size: .94rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 16px rgb(155 67 38 / 24%);
  }

  .mobile-filter-action button:focus-visible {
    outline: 3px solid rgb(200 95 53 / 30%);
    outline-offset: 2px;
  }

  .results-panel { scroll-margin-top: 10px; }
}