:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --line: #d9e0ea;
  --line-strong: #b8c3d4;
  --text: #18202f;
  --muted: #657287;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --warning: #b45309;
  --success: #15803d;
  --shadow: 0 14px 38px rgba(24, 32, 47, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(245, 247, 251, 0.92)),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 6px;
  font-size: 0.9rem;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.header-actions,
.search-row,
.panel-header,
.panel-header.compact {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.timestamp {
  color: var(--muted);
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.8fr);
  gap: 18px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 32px;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-wide {
  grid-column: span 1;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header.compact {
  justify-content: space-between;
  margin-bottom: 12px;
}

.primary-button,
.icon-button,
.segment {
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  transition:
    border-color 0.16s ease,
    background-color 0.16s ease,
    color 0.16s ease;
}

.primary-button {
  min-height: 38px;
  padding: 0 16px;
  border-color: var(--primary);
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  font-size: 1.1rem;
}

.icon-button:hover,
.segment:hover {
  border-color: var(--primary);
}

.search-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

input,
select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

input {
  width: min(360px, 48vw);
  padding: 0 12px;
}

select {
  padding: 0 34px 0 10px;
}

.inline-status {
  min-height: 22px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  font-size: 0.9rem;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.market-title {
  display: block;
  max-width: 520px;
  font-weight: 700;
}

.market-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.price {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.tag,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.pill.ok {
  border-color: rgba(21, 128, 61, 0.28);
  background: rgba(21, 128, 61, 0.08);
  color: var(--success);
}

.pill.warn {
  border-color: rgba(180, 83, 9, 0.28);
  background: rgba(180, 83, 9, 0.08);
  color: var(--warning);
}

.pill.error {
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    background-color 0.16s ease,
    color 0.16s ease;
}

.tag-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tag-chip.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.source-grid,
.metric-grid {
  display: grid;
  gap: 10px;
}

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

.source-card,
.metric-card,
.placeholder {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 12px;
}

.source-card h3,
.metric-card h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.source-card dl,
.metric-card dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin: 0;
}

.source-card dt,
.metric-card dt {
  color: var(--muted);
}

.source-card dd,
.metric-card dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.metric-card {
  min-height: 86px;
}

.metric-value {
  display: block;
  margin-top: 8px;
  font-size: 1.4rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.metric-card p {
  margin: 6px 0 0;
  font-size: 0.78rem;
}

.placeholder {
  margin-top: 10px;
}

.placeholder p {
  margin-bottom: 0;
  font-size: 0.86rem;
}

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
}

.segment {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.segment.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(24, 32, 47, 0.08);
}

.docs-preview {
  overflow: auto;
  min-height: 320px;
  max-height: 520px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.query-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1.1fr) minmax(110px, 0.7fr) minmax(120px, 0.8fr) minmax(120px, 0.8fr) minmax(100px, 0.6fr) minmax(80px, 0.5fr);
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.query-grid label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.query-grid label span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.query-grid input,
.query-grid select {
  width: 100%;
}

.query-output {
  min-height: 220px;
  max-height: 420px;
}

.mini-table-shell {
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mini-table {
  min-width: 0;
  table-layout: fixed;
}

.mini-table th,
.mini-table td {
  padding: 9px 10px;
  font-size: 0.78rem;
}

.mini-table th:nth-child(1),
.mini-table td:nth-child(1) {
  width: 22%;
}

.mini-table th:nth-child(3),
.mini-table td:nth-child(3),
.mini-table th:nth-child(4),
.mini-table td:nth-child(4),
.mini-table th:nth-child(5),
.mini-table td:nth-child(5) {
  width: 17%;
}

.mini-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .panel-wide {
    grid-column: auto;
  }

  .query-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app-header,
  .layout {
    padding-left: 14px;
    padding-right: 14px;
  }

  .panel,
  .panel-header {
    padding: 14px;
  }

  .panel-header,
  .search-row {
    align-items: stretch;
    flex-direction: column;
  }

  input,
  select {
    width: 100%;
  }

  .metric-grid,
  .query-grid {
    grid-template-columns: 1fr;
  }
}
