:root {
  --bg: #edf3fa;
  --bg-soft: #f8fbff;
  --panel: #ffffff;
  --ink: #122033;
  --muted: #5f6c7c;
  --line: #d6e2f0;
  --accent: #0f6db8;
  --accent-strong: #0a5b9b;
  --accent-soft: #e9f2fd;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 0%, #dfeeff 0%, transparent 38%),
    radial-gradient(circle at 95% 20%, #e7f6ef 0%, transparent 35%),
    linear-gradient(180deg, #f6faff 0%, var(--bg) 100%);
  color: var(--ink);
}

.site-credit {
  text-align: center;
  color: #7e8c9c;
  font-size: 12px;
  font-style: italic;
  margin: 2px 0 16px;
}

.layout {
  max-width: 1240px;
  margin: 22px auto;
  padding: 0 16px 24px;
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 12px 28px rgba(18, 32, 51, 0.06), 0 2px 6px rgba(18, 32, 51, 0.03);
}

h1, h2 { margin: 0 0 10px; }
h1 {
  font-size: 28px;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
h2 {
  font-size: 18px;
  letter-spacing: -0.01em;
  color: #1f344d;
}
.sub { margin: 0 0 14px; color: var(--muted); }
.source-header { font-size: 12px; color: #6b7b8f; margin-bottom: 10px; }
.prompt-suggestions { margin-top: -8px; font-size: 13px; }
.legal-note { text-align: center; font-size: 12px; color: #6b7b8f; margin: 2px 0 2px; }

.query-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.inline-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #24415f;
  font-size: 13px;
}

.inline-control select {
  min-width: 100px;
}

.tabs {
  margin-bottom: 10px;
}

.tab-btn {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid #c8ddf8;
  padding: 9px 12px;
  font-size: 13px;
}

.tab-btn.active {
  background: linear-gradient(180deg, #1880cf 0%, var(--accent) 100%);
  color: #ffffff;
  border-color: var(--accent);
}

input, select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: #1b3551;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:hover, select:hover {
  border-color: #b9cde3;
}

input:focus, select:focus {
  outline: none;
  border-color: #5ea4de;
  box-shadow: 0 0 0 3px rgba(15, 109, 184, 0.12);
}

input { flex: 1; }

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #24415f;
  font-size: 13px;
  min-width: 150px;
}

button {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  filter: brightness(0.98);
  box-shadow: 0 6px 16px rgba(15, 109, 184, 0.24);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: none;
}

.status {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.parsed {
  margin-top: 8px;
  font-size: 14px;
  color: #234865;
  line-height: 1.45;
}

.groups {
  margin-top: 8px;
  padding: 10px 12px;
  background: #f8fbff;
  border: 1px solid #d9e7fb;
  border-radius: 10px;
}

.groups details { margin-top: 6px; }
.group-members {
  margin-top: 6px;
  color: #35516d;
  font-size: 13px;
  line-height: 1.4;
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
  position: relative;
}

.chart-title {
  margin: 2px 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: #2b4057;
}

.chart-tip {
  margin-top: 8px;
  font-size: 12px;
  color: #6b7b8f;
}

.chart-wrap svg {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #fcfdff 0%, #f8fbff 100%);
}

.chart-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f8fbff;
  border: 1px solid #d9e7fb;
  border-radius: 999px;
  padding: 5px 10px;
  max-width: 100%;
  cursor: pointer;
  color: #22334a;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  appearance: none;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.chart-legend-item.is-muted {
  opacity: 0.45;
  background: #eef3f8;
}

.chart-legend-item:hover {
  background: #edf5ff;
}

.chart-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.chart-legend-text {
  font-size: 12px;
  color: #22334a;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

.hover-line {
  stroke: #7e93aa;
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
}

.hover-link {
  stroke: #9fb0c2;
  stroke-width: 1;
}

.hover-dot {
  stroke: #ffffff;
  stroke-width: 1.2;
}

.chart-tooltip {
  position: absolute;
  display: none;
  min-width: 240px;
  max-width: 280px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #d4dfec;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(18, 32, 51, 0.14);
  padding: 8px 10px;
  font-size: 12px;
  color: #22334a;
  pointer-events: none;
  z-index: 5;
}

.chart-tooltip-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.chart-tooltip-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  column-gap: 6px;
  row-gap: 4px;
  margin-top: 4px;
}

.chart-tooltip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.table-wrap {
  overflow: auto;
  max-height: 430px;
}

.table-note {
  margin-top: 8px;
  font-size: 12px;
  color: #4b6179;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
  border-radius: 10px;
  overflow: hidden;
}

.table-wrap th, .table-wrap td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: right;
  white-space: nowrap;
}

.table-wrap thead th {
  background: #f2f7fe;
  color: #2b4460;
}

.table-wrap tbody tr:nth-child(even) td {
  background: #fbfdff;
}

.table-wrap th:first-child,
.table-wrap td:first-child { text-align: left; }

.table-wrap .desc-col {
  width: 40%;
  min-width: 280px;
  text-align: left;
}

.table-wrap .desc-cell {
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap th {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.table-wrap th:first-child {
  width: 110px;
  white-space: nowrap;
}

.table-wrap .ranking-table th:nth-child(2),
.table-wrap .ranking-table td:nth-child(2) {
  text-align: left;
  width: 180px;
  max-width: 180px;
}

.table-wrap .ranking-table .code-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap .ranking-table.product-ranking th:nth-child(2),
.table-wrap .ranking-table.product-ranking td:nth-child(2) {
  width: 84px;
  max-width: 84px;
}

.table-wrap .ranking-table.product-ranking th:nth-child(n+4),
.table-wrap .ranking-table.product-ranking td:nth-child(n+4) {
  padding-left: 14px;
  padding-right: 12px;
}

@media (max-width: 860px) {
  .query-row { flex-direction: column; }
  .controls label { min-width: 0; }
  button { width: 100%; }
}

.rank-title {
  font-weight: 700;
  margin-bottom: 8px;
  color: #22334a;
}

.rank-chart {
  display: grid;
  gap: 8px;
}

.rank-row {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(180px, 3fr) auto;
  align-items: center;
  gap: 8px;
}

.rank-label {
  font-size: 12px;
  color: #2d4258;
  overflow-wrap: anywhere;
}

.rank-bar-wrap {
  height: 12px;
  background: #ecf2fa;
  border-radius: 999px;
  overflow: hidden;
}

.rank-bar {
  height: 100%;
  border-radius: 999px;
}

.rank-value {
  font-size: 12px;
  font-weight: 600;
  color: #20384f;
  white-space: nowrap;
}
