:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --paper: #ffffff;
  --ink: #17201b;
  --muted: #66736b;
  --line: #dce2dc;
  --line-strong: #c7d1c8;
  --green: #1f7a4d;
  --green-soft: #e8f4ed;
  --red: #b3453d;
  --red-soft: #f8e9e7;
  --amber: #996916;
  --amber-soft: #fbf0d7;
  --blue: #2e657f;
  --shadow: 0 14px 34px rgba(29, 40, 34, 0.08);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 390px) minmax(280px, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}

.brand-lockup {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: #173b2a;
  color: #f6fff9;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.mark svg,
.topbar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand-lockup p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.brand-lockup a {
  color: var(--green);
  text-decoration: none;
  border-bottom: 1px solid rgba(31, 122, 77, 0.35);
}

.brand-lockup a:hover {
  border-bottom-color: currentColor;
}

.search-wrap {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f2f5f1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
}

.search-wrap svg {
  color: var(--muted);
  flex: 0 0 auto;
}

.search-wrap input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-text,
.text-btn {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  white-space: nowrap;
  font-size: 14px;
}

.icon-text svg {
  width: 18px;
  height: 18px;
}

.icon-text.primary {
  background: #173b2a;
  color: #fff;
  border-color: #173b2a;
}

.icon-text.is-active {
  border-color: #d9b45f;
  background: #fff8e4;
  color: #7d540d;
}

.icon-text.is-active svg {
  fill: currentColor;
}

.text-btn {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--green);
  background: transparent;
}

.text-btn:disabled {
  cursor: default;
  opacity: 0.45;
}

.workspace {
  display: grid;
  grid-template-columns: clamp(220px, 23vw, 292px) minmax(0, 1fr);
  gap: 16px;
  padding: 18px 20px 24px;
  flex: 1;
  min-height: 0;
}

.filters,
.table-wrap,
.stats-row article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters {
  align-self: start;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  padding: 14px;
}

.filter-section {
  border-bottom: 1px solid var(--line);
  padding: 0 0 14px;
  margin: 0 0 14px;
}

.filter-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.filter-section.compact {
  display: grid;
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 760;
  line-height: 1.25;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.range-row {
  display: grid;
  gap: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.number-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.number-pair label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.number-pair input,
.token-box input,
.sort-control select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 9px;
  background: #fbfcfb;
  color: var(--ink);
  outline: 0;
}

.risk-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.risk-btn,
.facet-item,
.token {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 9px;
  font-size: 13px;
}

.risk-btn[aria-pressed="true"] {
  border-color: rgba(31, 122, 77, 0.45);
  background: var(--green-soft);
  color: #17422d;
}

.risk-btn {
  width: auto;
  min-height: 30px;
  justify-content: center;
  gap: 5px;
  padding: 0 10px;
  font-size: calc(12px + var(--risk-weight, 0) * 4px);
}

.risk-btn small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78em;
}

.facet-list {
  display: grid;
  gap: 7px;
  max-height: 230px;
  overflow: auto;
  padding-right: 2px;
}

.facet-item {
  justify-content: flex-start;
}

.facet-item.selected {
  border-color: rgba(31, 122, 77, 0.38);
  background: var(--green-soft);
}

.facet-item input {
  accent-color: var(--green);
}

.facet-item strong {
  flex: 1;
  font-size: 13px;
  font-weight: 650;
}

.profile-hint {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(31, 122, 77, 0.24);
  color: var(--green);
  background: #fff;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
}

.facet-item span:last-child {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.token-box {
  display: grid;
  gap: 8px;
}

.tokens,
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.token,
.filter-pill {
  width: auto;
  min-height: 28px;
  padding: 0 8px;
  background: #eef3ee;
  border-color: #d4ddd5;
  font-size: 12px;
}

.token button,
.filter-pill button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  width: 18px;
  height: 18px;
}

.results-pane {
  min-width: 0;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stats-row article {
  min-height: 74px;
  padding: 13px 14px;
}

.stats-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stats-row strong {
  display: block;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.toolbar {
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sort-control select {
  min-width: 132px;
}

.content-grid {
  display: block;
}

.table-wrap {
  min-width: 0;
  overflow-x: auto;
}

.results-table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  table-layout: fixed;
}

.results-table th {
  height: 40px;
  padding: 0 10px;
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  background: #f9fbf9;
  border-bottom: 1px solid var(--line);
}

.results-table td {
  padding: 10px;
  border-bottom: 1px solid #edf1ed;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.45;
}

.results-table tr {
  transition: background 0.14s ease;
}

.results-table tr:hover,
.results-table tr.selected {
  background: #f5faf6;
}

.results-table tr:last-child td {
  border-bottom: 0;
}

.fav-col {
  width: 38px;
}

.results-table th:nth-child(2) {
  width: 64px;
}

.results-table th:nth-child(3) {
  width: 170px;
}

.results-table th:nth-child(4) {
  width: 108px;
}

.results-table th:nth-child(5) {
  width: 166px;
}

.results-table th:nth-child(6) {
  width: 244px;
}

.results-table th:nth-child(7) {
  width: 150px;
}

.fav-btn {
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  color: #9aa79f;
  display: grid;
  place-items: center;
  border-radius: 6px;
}

.fav-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.fav-btn.active {
  color: var(--amber);
}

.fav-btn.active svg {
  fill: currentColor;
}

.score-pill {
  min-width: 46px;
  min-height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 760;
  font-size: 13px;
}

.score-high {
  color: var(--green);
  background: var(--green-soft);
}

.score-mid {
  color: var(--amber);
  background: var(--amber-soft);
}

.score-low {
  color: var(--red);
  background: var(--red-soft);
}

.score-none {
  color: var(--muted);
  background: #eef1ee;
}

.dish-name {
  margin: 0 0 5px;
  font-size: 14px;
  font-weight: 760;
  line-height: 1.25;
}

.tier {
  color: var(--muted);
  font-size: 12px;
}

.brand-badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 9px;
  background: #fbfcfb;
  font-size: 12px;
  color: #314139;
}

.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted {
  color: var(--muted);
}

mark {
  background: #fff1a6;
  color: inherit;
  padding: 0 1px;
  border-radius: 3px;
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 30px);
  background: rgba(19, 27, 23, 0.42);
  backdrop-filter: blur(5px);
}

.detail-backdrop[hidden] {
  display: none;
}

.detail-dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 28px 80px rgba(20, 30, 24, 0.24);
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  display: grid;
  place-items: center;
}

.detail-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.detail-panel {
  min-height: 0;
  overflow: auto;
  padding: 20px 22px 22px;
}

.detail-header {
  display: grid;
  gap: 10px;
  padding: 2px 46px 14px 0;
  border-bottom: 1px solid var(--line);
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.detail-panel h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.detail-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.86fr);
  gap: 18px;
  align-items: start;
}

.detail-body.no-ocr {
  grid-template-columns: 1fr;
}

.detail-fields {
  min-width: 0;
}

.detail-ocr {
  min-width: 0;
  max-height: calc(min(86vh, 820px) - 128px);
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 18px;
  padding-top: 14px;
  border-left: 1px solid var(--line);
}

.detail-ocr h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.brand-profiles-panel {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 8px 22px rgba(29, 40, 34, 0.04);
}

.brand-profiles-panel[hidden] {
  display: none;
}

.brand-profiles-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 9px 12px;
  margin-bottom: 0;
}

.brand-profiles-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.brand-profiles-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.brand-profiles-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.brand-profiles-head button {
  min-height: 28px;
  border: 1px solid rgba(31, 122, 77, 0.28);
  border-radius: 999px;
  background: #fff;
  color: var(--green);
  padding: 0 10px;
  white-space: nowrap;
  font-size: 12px;
}

.profile-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px;
  padding: 0 12px 12px;
}

.profile-summary-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(31, 122, 77, 0.2);
  border-radius: var(--radius);
  background: #f8fbf8;
  box-shadow: 0 8px 22px rgba(29, 40, 34, 0.05);
}

.profile-summary-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.profile-summary-title h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}

.profile-summary-title button {
  min-height: 26px;
  border: 1px solid rgba(31, 122, 77, 0.28);
  border-radius: 999px;
  background: #fff;
  color: var(--green);
  padding: 0 8px;
  white-space: nowrap;
  font-size: 12px;
}

.profile-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.profile-facts span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid rgba(31, 122, 77, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  padding: 0 8px;
  color: #314139;
  font-size: 12px;
}

.profile-facts strong {
  color: #245b3f;
  font-weight: 760;
}

.profile-summary-card p {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.55;
}

.profile-summary-card p:first-of-type {
  margin-top: 0;
}

.profile-note {
  color: var(--muted);
}

.detail-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.detail-section:last-child {
  border-bottom: 0;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 760;
}

.detail-section p,
.source-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

.source-text {
  white-space: pre-wrap;
  padding: 10px;
  background: #f7f9f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 100%;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
}

.detail-ocr .source-text {
  flex: 1;
  min-height: 132px;
}

.match-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.match-chip {
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  background: #edf5f1;
  color: #245b3f;
  font-size: 12px;
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .icon-text {
    flex: 1;
  }

  .filters {
    position: static;
    max-height: none;
  }
}

@media (max-width: 780px) {
  .detail-body {
    grid-template-columns: 1fr;
  }

  .detail-ocr {
    max-height: 320px;
    position: static;
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 14px;
  }

  .detail-ocr .source-text {
    min-height: 96px;
  }
}

@media (max-width: 700px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .filters {
    position: static;
    max-height: none;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .sort-control {
    justify-content: space-between;
  }

  .results-table {
    min-width: 0;
  }

  .results-table,
  .results-table thead,
  .results-table tbody,
  .results-table tr,
  .results-table td {
    display: block;
  }

  .results-table thead {
    display: none;
  }

  .results-table tr {
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  .results-table td {
    border: 0;
    padding: 4px 0;
  }

  .results-table td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11px;
    margin-bottom: 2px;
  }

  .results-table td:first-child::before {
    content: "";
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
