:root {
  --ledger: #f3f6f5;
  --paper: #fcfefd;
  --ink: #17242c;
  --muted: #62716f;
  --verified: #007c68;
  --verified-dark: #006554;
  --verified-pale: #e1f1ed;
  --rank: #d69a23;
  --rank-pale: #fbf0d5;
  --trace: #3c6f8d;
  --trace-pale: #e7f0f4;
  --alert: #b94b42;
  --alert-pale: #f9e9e7;
  --line: #d5dedb;
  --line-strong: #aab8b4;
  --display-font: "Songti TC", "Noto Serif TC", Georgia, serif;
  --body-font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono-font: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--ledger);
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--ledger);
  color: var(--ink);
  font-family: var(--body-font);
  font-size: 15px;
  letter-spacing: 0;
}

button,
input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
input, button, .rank-rail-wrap { outline: none; }

input:focus-visible,
button:focus-visible,
.rank-rail-wrap:focus-visible,
a:focus-visible {
  box-shadow: 0 0 0 3px rgba(0, 124, 104, 0.2);
}

[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 1440px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 30px 20px;
}

.topbar {
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--ink);
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--ink);
  color: var(--verified);
  font-family: var(--mono-font);
  font-size: 13px;
  font-weight: 800;
}

.brand-copy { display: grid; gap: 1px; }
.brand-copy strong {
  font-family: var(--display-font);
  font-size: 21px;
  font-weight: 800;
  line-height: 1.05;
}
.brand-copy span { color: var(--muted); font-size: 11px; font-weight: 700; }

.service-state {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  text-align: right;
}
.service-state > span:last-child { display: grid; min-width: 0; gap: 2px; }
.service-state strong, .service-state small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-state strong { font-size: 12px; }
.service-state small { max-width: 240px; color: var(--muted); font-family: var(--mono-font); font-size: 10px; }

.service-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border: 2px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line-strong);
  background: var(--line-strong);
}
.service-dot.is-ready { background: var(--verified); box-shadow: 0 0 0 1px var(--verified); }
.service-dot.is-loading, .service-dot.is-checking { background: var(--rank); box-shadow: 0 0 0 1px var(--rank); }
.service-dot.is-error { background: var(--alert); box-shadow: 0 0 0 1px var(--alert); }

.search-band {
  display: grid;
  grid-template-columns: minmax(250px, 0.64fr) minmax(650px, 1.55fr);
  gap: 56px;
  align-items: end;
  padding: 50px 0 44px;
  border-bottom: 1px solid var(--line-strong);
}

.eyebrow {
  margin: 0;
  color: var(--verified);
  font-family: var(--mono-font);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.search-lead h1 {
  max-width: 500px;
  margin: 10px 0 0;
  font-family: var(--display-font);
  font-size: 42px;
  font-weight: 800;
  line-height: 1.14;
}
.lead-copy { max-width: 470px; margin: 16px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 154px;
  gap: 16px 14px;
  align-items: end;
}

.query-field, .condition-field, .top-k-field { display: grid; min-width: 0; gap: 7px; }
.query-field { grid-column: 1; }
.query-field > span:first-child,
.condition-field > label,
.top-k-field > span:first-child { font-size: 12px; font-weight: 800; }

input[type="search"], input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.query-field input { height: 52px; font-size: 17px; }
input::placeholder { color: #82908d; }
input[type="search"]:hover, input[type="number"]:hover { border-color: #748783; }
input[type="search"]:focus, input[type="number"]:focus { border-color: var(--verified); }
input[aria-invalid="true"] { border-color: var(--alert); background: #fffafa; }

.condition-grid {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 124px;
  gap: 14px;
  align-items: start;
}
.condition-field > small, .number-control > small { min-height: 16px; color: var(--muted); font-size: 10px; line-height: 1.45; }

.multi-combobox { position: relative; min-width: 0; }
.selected-chips { display: flex; min-height: 29px; flex-wrap: wrap; gap: 5px; padding: 0 0 6px; }
.selection-chip {
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border: 1px solid #9bc8bf;
  border-radius: 4px;
  background: var(--verified-pale);
  color: var(--ink);
  font-size: 11px;
  line-height: 1.3;
}
.selection-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selection-chip b { flex: 0 0 auto; color: var(--verified-dark); font-size: 14px; line-height: 1; }
.selection-chip:hover { border-color: var(--verified); }

.combobox-input-row { position: relative; }
.combobox-input-row input { padding-right: 38px; }
.multi-combobox.is-open .combobox-input-row input { border-color: var(--verified); box-shadow: 0 0 0 3px rgba(0, 124, 104, 0.12); }
.clear-control {
  position: absolute;
  top: 7px;
  right: 7px;
  display: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.clear-control.is-visible { display: block; }
.clear-control:hover { background: var(--trace-pale); color: var(--ink); }

.combobox-popup {
  position: absolute;
  z-index: 20;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  min-width: 280px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--paper);
  box-shadow: 0 12px 24px rgba(23, 36, 44, 0.14);
}
.option-status { margin: 0; padding: 8px 11px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.option-list { max-height: 296px; overflow-y: auto; overscroll-behavior: contain; }
.option-row {
  display: grid;
  min-height: 39px;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 7px 11px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}
.option-row:last-child { border-bottom: 0; }
.option-row:hover, .option-row.is-active { background: var(--trace-pale); }
.option-row[aria-selected="true"] { background: var(--verified-pale); }
.option-row input { width: 15px; height: 15px; margin: 0; accent-color: var(--verified); }
.option-row span { overflow-wrap: anywhere; }

.number-control { display: grid; gap: 7px; }
.top-k-field input { font-family: var(--mono-font); }

.search-button {
  display: inline-flex;
  width: 100%;
  height: 52px;
  grid-column: 2;
  grid-row: 1;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 16px;
  border: 1px solid var(--verified);
  border-radius: 4px;
  background: var(--verified);
  color: var(--paper);
  font-size: 14px;
  font-weight: 800;
  transition: border-color 140ms ease, background-color 140ms ease;
}
.search-button:hover:not(:disabled) { border-color: var(--verified-dark); background: var(--verified-dark); }
.search-button:disabled { border-color: var(--line-strong); background: var(--line-strong); }
.button-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: var(--paper);
  border-radius: 50%;
}
.search-button.is-loading .button-spinner { display: block; animation: spin 700ms linear infinite; }

.results-band { padding: 38px 0 26px; }
.results-header { display: flex; align-items: end; justify-content: space-between; gap: 28px; }
.results-header h2 { margin: 7px 0 0; font-family: var(--display-font); font-size: 28px; font-weight: 800; line-height: 1.2; }
.query-readout { max-width: 58%; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: right; overflow-wrap: anywhere; }

.rank-rail-wrap { margin-top: 22px; overflow-x: auto; scrollbar-width: thin; }
.rank-rail {
  display: grid;
  min-width: 760px;
  min-height: 100px;
  grid-template-columns: repeat(10, minmax(72px, 1fr));
  margin: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  list-style: none;
}
.rank-rail li { position: relative; display: grid; min-width: 0; align-content: space-between; gap: 8px; padding: 10px 9px 13px; background: var(--paper); }
.rank-rail li + li { border-left: 1px solid var(--line); }
.rank-rail li::after { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: var(--line); content: ""; }
.rank-rail li.is-filled { background: var(--verified-pale); }
.rank-rail li.is-filled::after { background: var(--verified); }
.rank-rail li:nth-child(10).is-filled { background: var(--rank-pale); }
.rank-rail li:nth-child(10).is-filled::after { background: var(--rank); }
.rank-rail span { color: var(--muted); font-family: var(--mono-font); font-size: 10px; font-weight: 800; }
.rank-rail strong {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  font-family: var(--body-font);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.result-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 18px 0 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-summary div { min-width: 0; padding: 10px 12px; }
.result-summary div + div { border-left: 1px solid var(--line); }
.result-summary dt, .result-summary dd { margin: 0; }
.result-summary dt { color: var(--muted); font-size: 10px; }
.result-summary dd { margin-top: 3px; overflow: hidden; font-family: var(--mono-font); font-size: 12px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

.results-state {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--trace);
  background: var(--trace-pale);
  font-size: 13px;
  line-height: 1.55;
}
.results-state.is-success { border-left-color: var(--verified); background: var(--verified-pale); }
.results-state.is-loading { border-left-color: var(--rank); background: var(--rank-pale); }
.results-state.is-error { border-left-color: var(--alert); background: var(--alert-pale); }
.text-button { flex: 0 0 auto; padding: 3px 0; border: 0; border-bottom: 1px solid currentColor; background: transparent; color: var(--alert); font-size: 11px; font-weight: 800; }

.results-list { display: grid; margin: 14px 0 0; padding: 0; list-style: none; }
.results-list > li { min-width: 0; }
.result-row {
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 88px;
  grid-template-columns: 58px minmax(0, 1fr) 28px;
  align-items: stretch;
  gap: 16px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.results-list > li:first-child .result-row { border-top: 1px solid var(--line); }
.result-row:hover { background: rgba(252, 254, 253, 0.72); }
.result-rank { display: grid; align-self: stretch; place-items: center; border-right: 1px solid var(--line-strong); color: var(--verified); font-family: var(--mono-font); font-size: 16px; font-weight: 800; }
.results-list > li:nth-child(10) .result-rank { color: #9a6b11; }
.result-content { display: grid; min-width: 0; align-content: center; gap: 4px; padding: 13px 0; }
.result-label { min-width: 0; font-family: var(--display-font); font-size: 17px; font-weight: 800; line-height: 1.35; overflow-wrap: anywhere; }
.result-note { color: var(--muted); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.job-id { color: var(--trace); font-family: var(--mono-font); font-size: 10px; font-weight: 800; overflow-wrap: anywhere; }
.result-open { display: grid; align-items: center; color: var(--muted); font-family: var(--display-font); font-size: 28px; }
.result-row:hover .result-open { color: var(--verified); }

.footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 0 0; border-top: 1px solid var(--ink); color: var(--muted); font-family: var(--mono-font); font-size: 10px; font-weight: 700; }

.job-dialog {
  width: min(680px, 92vw);
  max-width: none;
  height: 100vh;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
}
.job-dialog::backdrop { background: rgba(23, 36, 44, 0.42); }
.dialog-shell { display: flex; min-height: 100%; flex-direction: column; }
.dialog-header {
  position: sticky;
  z-index: 1;
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 30px 20px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}
.dialog-header h2 { margin: 7px 0 0; font-family: var(--display-font); font-size: 25px; line-height: 1.3; overflow-wrap: anywhere; }
.dialog-job-id { margin: 7px 0 0; color: var(--trace); font-family: var(--mono-font); font-size: 10px; font-weight: 800; }
.dialog-close { display: grid; width: 38px; height: 38px; flex: 0 0 auto; place-items: center; padding: 0; border: 1px solid var(--line-strong); border-radius: 4px; background: transparent; color: var(--ink); font-size: 25px; line-height: 1; }
.dialog-close:hover { border-color: var(--ink); background: var(--ledger); }
.dialog-state { margin: 24px 30px 0; padding: 12px; border-left: 3px solid var(--trace); background: var(--trace-pale); font-size: 13px; }
.dialog-state:empty { display: none; }
.dialog-state.is-loading { border-left-color: var(--rank); background: var(--rank-pale); }
.dialog-state.is-error { border-left-color: var(--alert); background: var(--alert-pale); }
.dialog-content { padding: 0 30px 40px; overflow-y: auto; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
.detail-field { min-width: 0; padding: 17px 12px 17px 0; border-bottom: 1px solid var(--line); }
.detail-field:nth-child(even):not(.wide) { padding-left: 12px; border-left: 1px solid var(--line); }
.detail-field.wide { grid-column: 1 / -1; padding-right: 0; }
.detail-field dt { color: var(--muted); font-size: 10px; font-weight: 800; }
.detail-field dd { margin: 6px 0 0; font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; white-space: pre-wrap; }
.detail-field.long-text dd { font-size: 14px; line-height: 1.85; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1080px) {
  .search-band { grid-template-columns: 1fr; gap: 30px; }
  .search-lead h1, .lead-copy { max-width: 660px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 0 18px 16px; }
  .topbar { min-height: 76px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-copy strong { font-size: 18px; }
  .service-state small { max-width: 120px; }
  .search-band { gap: 26px; padding: 34px 0 32px; }
  .search-lead h1 { font-size: 34px; }
  .search-form { grid-template-columns: 1fr; }
  .query-field, .search-button { grid-column: 1; }
  .search-button { grid-row: auto; }
  .condition-grid { grid-column: 1; grid-template-columns: 1fr 100px; }
  .condition-field { grid-column: 1 / -1; }
  .top-k-field { grid-column: 1; }
  .combobox-popup { min-width: 0; }
  .results-header { align-items: flex-start; flex-direction: column; gap: 10px; }
  .query-readout { max-width: 100%; text-align: left; }
  .result-summary div { padding: 9px 7px; }
  .result-summary dd { font-size: 10px; }
  .results-state { align-items: flex-start; flex-direction: column; gap: 8px; }
  .result-row { min-height: 96px; grid-template-columns: 46px minmax(0, 1fr) 22px; gap: 11px; }
  .result-label { font-size: 16px; }
  .footer { align-items: flex-start; flex-direction: column; gap: 5px; }
  .job-dialog { width: 100vw; height: 100dvh; border-left: 0; }
  .dialog-header { padding: 20px 18px 16px; }
  .dialog-header h2 { font-size: 21px; }
  .dialog-state { margin: 18px 18px 0; }
  .dialog-content { padding: 0 18px 30px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-field, .detail-field:nth-child(even):not(.wide) { grid-column: 1; padding: 15px 0; border-left: 0; }
}

@media (max-width: 390px) {
  .app-shell { padding-right: 14px; padding-left: 14px; }
  .brand-copy span, .service-state small { display: none; }
  .search-lead h1 { font-size: 31px; }
  .result-summary { grid-template-columns: 72px 88px minmax(0, 1fr); }
  .rank-rail { min-width: 700px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
