:root {
  color-scheme: light;
  --bg: #eff4f8;
  --card: #ffffff;
  --line: #dbe4ee;
  --text: #102030;
  --muted: #627284;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --good: #0f766e;
  --warn: #b45309;
  --bad: #b91c1c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #111827;
  --line: #273247;
  --text: #e5edf8;
  --muted: #9eb0c9;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.14);
  --good: #34d399;
  --warn: #f59e0b;
  --bad: #f87171;
}

* { box-sizing: border-box; }
html,
body {
  background-color: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background-image: linear-gradient(180deg, #f8fbfe 0%, var(--bg) 100%);
  background-repeat: no-repeat;
}

button, input, select { font: inherit; }
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

:root[data-theme="dark"] html,
:root[data-theme="dark"] body {
  background-color: var(--bg);
}
:root[data-theme="dark"] body {
  background-image: linear-gradient(180deg, #0f172a 0%, var(--bg) 100%);
}
:root[data-theme="dark"] .clear-search {
  background: #1f2937;
  color: var(--muted);
}
:root[data-theme="dark"] .clear-search:hover {
  background: #273449;
}
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .search-input-wrap input {
  background: #0f172a;
  color: var(--text);
  border-color: var(--line);
}
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .detail,
:root[data-theme="dark"] .suggestions,
:root[data-theme="dark"] .summary-card,
:root[data-theme="dark"] .chart-card {
  background: #0f172a;
  border-color: var(--line);
}
:root[data-theme="dark"] .result-none,
:root[data-theme="dark"] .history-none {
  background: #111827;
}
:root[data-theme="dark"] .result-good,
:root[data-theme="dark"] .history-good {
  background: rgba(16, 185, 129, 0.14);
}
:root[data-theme="dark"] .result-warn,
:root[data-theme="dark"] .history-warn {
  background: rgba(245, 158, 11, 0.14);
}
:root[data-theme="dark"] .result-bad,
:root[data-theme="dark"] .history-bad {
  background: rgba(248, 113, 113, 0.14);
}
:root[data-theme="dark"] .grade-a,
:root[data-theme="dark"] .legend-a {
  background: rgba(16, 185, 129, 0.22);
}
:root[data-theme="dark"] .grade-b,
:root[data-theme="dark"] .legend-b {
  background: rgba(245, 158, 11, 0.22);
}
:root[data-theme="dark"] .grade-c,
:root[data-theme="dark"] .legend-c {
  background: rgba(248, 113, 113, 0.22);
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 20px;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.05);
}

.topbar {
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.theme-toggle {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover {
  background: var(--accent-soft);
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--accent);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.25rem, 2.4vw, 2rem); line-height: 1.05; }
h2 { font-size: 1rem; }
h3 { font-size: 0.92rem; }
.topbar-copy, .muted { color: var(--muted); }
.topbar-copy { max-width: 34ch; }

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
}

.sidebar, .detail {
  padding: 10px;
  background: var(--card);
}
.search-toolbar { display: grid; gap: 6px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 0.76rem; font-weight: 600; }
.field input, .field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fbfdff;
}

.toolbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
}

.primary, .back-button, .suggestion-item {
  border: none;
  cursor: pointer;
}

.primary {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.search-field { position: relative; }
.search-input-wrap {
  position: relative;
}
.clear-search {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 999px;
  background: #e9eef5;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.clear-search:hover { background: #dde6f2; }
.search-input-wrap input { padding-right: 34px; }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: grid;
  gap: 3px;
  padding: 4px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
  z-index: 30;
}
.suggestion-item {
  text-align: left;
  padding: 7px 9px;
  border-radius: 8px;
  background: transparent;
  display: grid;
  gap: 1px;
}
.suggestion-item:hover { background: var(--accent-soft); }
.suggestion-item span { color: var(--muted); font-size: 0.84rem; }
.hidden { display: none !important; }

.results-header, .section-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin: 8px 0 6px;
}
.results-list, .history-list { display: grid; gap: 4px; }

.result-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.result-item:hover, .result-item.active {
  border-color: rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(37, 99, 235, 0.06);
}
.result-good { background: rgba(15, 118, 110, 0.08); }
.result-warn { background: rgba(180, 83, 9, 0.08); }
.result-bad { background: rgba(185, 28, 28, 0.08); }
.result-none { background: #fff; }
.result-main, .detail-hero, .history-header {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: start;
}
.result-copy {
  min-width: 0;
  flex: 1;
}
.result-item h3 {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.82rem;
  line-height: 1.1;
}
.result-item p {
  line-height: 1.1;
}
.small { font-size: 0.72rem; margin-top: 1px; }
.title-grade-prefix {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  margin-right: 3px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  border: 1px solid rgba(15, 23, 42, 0.06);
  flex: 0 0 auto;
}
.grade-a { background: rgba(15, 118, 110, 0.18); color: var(--good); }
.grade-b { background: rgba(180, 83, 9, 0.18); color: var(--warn); }
.grade-c { background: rgba(185, 28, 28, 0.18); color: var(--bad); }
.grade-—, .grade-null { background: #eef2f7; color: var(--muted); }

.badge, .score-chip {
  min-width: 66px;
  border-radius: 10px;
  padding: 5px 6px;
  text-align: center;
  background: #eef4ff;
}
.badge-grade, .score-chip strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
}
.badge-score {
  font-size: 0.68rem;
  margin-top: 2px;
  font-weight: 600;
}
.score-label { display: block; font-size: 0.62rem; color: var(--muted); }
.badge.good, .score-chip.good { background: rgba(15, 118, 110, 0.12); color: var(--good); }
.badge.warn, .score-chip.warn { background: rgba(180, 83, 9, 0.12); color: var(--warn); }
.badge.bad, .score-chip.bad { background: rgba(185, 28, 28, 0.12); color: var(--bad); }

.empty-state {
  min-height: 320px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.detail-view { display: grid; gap: 8px; }
.summary-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.summary-card {
  border: 1px solid #e7edf4;
  border-radius: 12px;
  background: #fafcff;
}
.summary-card.compact {
  padding: 8px 10px;
}
.summary-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}
.chart-card {
  padding: 8px 10px;
  border-radius: 12px;
  background: #fafcff;
  border: 1px solid #e7edf4;
}
#scoreChart { width: 100%; height: 110px; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 3; }
.chart-dot { fill: white; stroke: var(--accent); stroke-width: 2; }
.chart-label { fill: var(--muted); font-size: 10px; }
.chart-axis-label { fill: var(--muted); font-size: 10px; }
.chart-grade-label { fill: var(--muted); font-size: 10px; font-weight: 700; }
.chart-axis { stroke: #cbd5e1; stroke-width: 1; }
.chart-grid { stroke: #e2e8f0; stroke-width: 1; stroke-dasharray: 2 2; }
.grade-band { opacity: 0.5; }
.grade-band-a { fill: rgba(15, 118, 110, 0.12); }
.grade-band-b { fill: rgba(180, 83, 9, 0.12); }
.grade-band-c { fill: rgba(185, 28, 28, 0.12); }
.grade-legend {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid rgba(15, 23, 42, 0.06);
}
.legend-item strong { color: var(--text); }
.legend-item small { font-size: 0.68rem; }
.legend-a { background: rgba(15, 118, 110, 0.12); }
.legend-b { background: rgba(180, 83, 9, 0.12); }
.legend-c { background: rgba(185, 28, 28, 0.12); }

.history-item {
  border-top: 1px solid #ebf0f5;
  padding: 6px 7px;
  border-radius: 10px;
}
.history-item:first-child { border-top: none; padding-top: 6px; }
.history-item h3 {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.88rem;
  line-height: 1.12;
}
.history-item .muted {
  font-size: 0.78rem;
}
.history-good { background: rgba(15, 118, 110, 0.08); }
.history-warn { background: rgba(180, 83, 9, 0.08); }
.history-bad { background: rgba(185, 28, 28, 0.08); }
.history-none { background: #fff; }
.history-action {
  margin-top: 3px;
  margin-bottom: 3px;
  font-size: 0.84rem;
  line-height: 1.2;
}
.violation-list {
  margin: 0;
  padding-left: 14px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.2;
}
.violation-list li { margin-bottom: 2px; }

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #eef4ff;
  color: var(--accent);
  font-weight: 700;
}
:root[data-theme="dark"] .back-button {
  background: #1f2937;
  color: var(--accent);
  border: 1px solid var(--line);
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .topbar { align-items: start; flex-direction: column; }
  .detail { order: -1; }
  .detail:not(.mobile-active) .detail-view,
  .detail:not(.mobile-active) .back-button {
    display: none !important;
  }
  .detail.mobile-active .empty-state {
    display: none !important;
  }
  .detail:not(.mobile-active) {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }
  .detail.no-selection {
    display: none;
  }
  .detail.mobile-active {
    padding: 14px;
    background: var(--card);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 20px;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.05);
  }
}

@media (max-width: 640px) {
  .app-shell { padding: 8px; }
  .topbar, .sidebar, .detail.mobile-active { padding: 8px; }
  .toolbar-row, .summary-strip { grid-template-columns: 1fr; }
  .result-main, .detail-hero, .history-header { flex-direction: column; }
  .empty-state { min-height: 160px; }
  .results-list, .history-list { gap: 3px; }
  .result-item, .history-item { padding-top: 6px; padding-bottom: 6px; }
}
