:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #1b1d1f;
  --muted: #6d747c;
  --line: #dce1de;
  --green: #0f7b5f;
  --blue: #2d65c4;
  --amber: #ad6b00;
  --red: #b13a3a;
  --shadow: 0 1px 2px rgba(24, 31, 28, 0.08);
  --focus: 0 0 0 3px rgba(45, 101, 196, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: var(--focus);
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
  font-weight: 760;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

#scope {
  color: var(--muted);
  font-size: 14px;
  margin-top: 5px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control-drawer {
  position: relative;
}

.control-drawer summary {
  height: 40px;
  min-width: 92px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}

.control-drawer summary::-webkit-details-marker {
  display: none;
}

.control-drawer summary svg {
  width: 18px;
  height: 18px;
}

.control-drawer[open] summary {
  border-color: #b7c4bd;
  box-shadow: var(--shadow);
}

.control-drawer .toolbar {
  position: absolute;
  z-index: 10;
  right: 0;
  top: calc(100% + 8px);
  width: min(360px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(24, 31, 28, 0.12);
}

.field {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #f9faf8;
  border-radius: 8px;
  color: var(--muted);
}

.field input {
  width: 52px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}

.icon-button {
  height: 40px;
  min-width: 112px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover {
  border-color: #b7c4bd;
  box-shadow: var(--shadow);
}

.icon-button:active,
.feedback:active,
.segmented button:active {
  transform: translateY(1px);
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  padding: 24px 28px max(40px, env(safe-area-inset-bottom));
}

.panel {
  align-self: start;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric.wide,
.segmented {
  grid-column: 1 / -1;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.15;
}

.metric.wide strong {
  font-size: 14px;
  line-height: 1.35;
  word-break: keep-all;
}

.segmented {
  height: 42px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button.active {
  background: #e7efe9;
  color: var(--green);
  font-weight: 720;
}

.results {
  min-width: 0;
}

.result-head {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.helper {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

#statusText {
  color: var(--muted);
  font-size: 14px;
}

.cards {
  display: grid;
  gap: 12px;
}

.listing-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 182px;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.listing-main {
  min-width: 0;
}

.listing-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.listing-title a {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
  font-weight: 760;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.listing-title a:hover {
  color: var(--blue);
}

.score {
  min-width: 66px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #e9f2ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 780;
}

.trade-badge {
  min-width: 44px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #f1f3f0;
  color: #41484d;
  font-size: 12px;
  font-weight: 780;
}

.trade-A1 {
  background: #eef3ff;
  color: var(--blue);
}

.trade-B1 {
  background: #fff3da;
  color: var(--amber);
}

.trade-B2 {
  background: #e9f2ef;
  color: var(--green);
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.facts,
.reasons,
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.pill {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f1f3f0;
  color: #41484d;
  font-size: 12px;
  line-height: 1.25;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
}

.pill.good {
  background: #e5f3ed;
  color: var(--green);
}

.pill.warn {
  background: #fff3da;
  color: var(--amber);
}

.pill.bad {
  background: #faeaea;
  color: var(--red);
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-content: start;
}

.feedback,
.detail-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
}

.feedback svg,
.detail-link svg {
  width: 17px;
  height: 17px;
}

.detail-link {
  background: #eff5ff;
  border-color: #bfd0ef;
  color: var(--blue);
  font-weight: 720;
}

.feedback.good {
  color: var(--green);
}

.feedback.hold {
  color: var(--amber);
}

.feedback.bad {
  color: var(--red);
}

.detail-link:hover,
.feedback:hover,
.feedback.active {
  border-color: currentColor;
  background: #ffffff;
}

.feedback.good.active {
  background: #e5f3ed;
  border-color: var(--green);
  color: var(--green);
  font-weight: 760;
}

.feedback.hold.active {
  background: #fff3da;
  border-color: var(--amber);
  color: var(--amber);
  font-weight: 760;
}

.listing-card[data-feedback="good"] {
  border-color: #b8dccc;
}

.listing-card[data-feedback="hold"] {
  border-color: #e2c88e;
}

.feedback:disabled {
  cursor: wait;
  opacity: 0.55;
}

.listing-card.dismissing {
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

@media (pointer: coarse) {
  .icon-button,
  .field,
  .segmented,
  .feedback,
  .detail-link,
  .empty-action {
    min-height: 44px;
  }

  .segmented button {
    min-height: 36px;
  }
}

.empty {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 24px;
  border: 1px dashed #bac4be;
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
  text-align: center;
}

.empty strong {
  font-size: 16px;
  line-height: 1.3;
}

.empty span {
  max-width: 32ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.empty small {
  max-width: 34ch;
  color: #566068;
  font-size: 12px;
  line-height: 1.35;
}

.empty-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.empty-action {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.empty-action:hover {
  border-color: #b7c4bd;
}

.empty-action svg {
  width: 17px;
  height: 17px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .control-drawer {
    width: 100%;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .panel {
    grid-template-columns: 1fr 1fr;
    order: 2;
  }

  .results {
    order: 1;
  }

  .listing-card {
    grid-template-columns: 1fr;
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .detail-link {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: max(16px, env(safe-area-inset-top)) 16px 16px;
    gap: 8px;
  }

  .control-drawer,
  .panel {
    display: none;
  }

  .feedback {
    min-height: 44px;
  }

  .listing-card {
    padding: 14px;
    gap: 12px;
  }

  .listing-title {
    align-items: flex-start;
  }

  .listing-title a {
    flex: 1 1 100%;
    font-size: 17px;
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .feedback {
    gap: 5px;
    padding: 0 6px;
  }

  .facts,
  .reasons,
  .tags {
    gap: 6px;
    margin-top: 10px;
  }

  .empty {
    min-height: 180px;
  }
}

@media (max-width: 360px) {
  .layout {
    gap: 16px;
  }

  .result-head {
    margin-bottom: 10px;
  }

  .helper {
    font-size: 13px;
  }

  .layout {
    padding-inline: 12px;
  }

  .topbar {
    padding-inline: 12px;
  }

  .icon-button {
    min-width: 0;
  }
}

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

  .icon-button:active,
  .feedback:active,
  .segmented button:active {
    transform: none;
  }
}
