:root {
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #1d293e;
  background: #f4f6fa;
  --border: #dfe5ee;
  --muted: #52617a;
  --blue: #2455d6;
  --purple: #653bb0;
  --teal: #126c62;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button, input, select, textarea, .export-picker summary {
  color: inherit; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
button, .export-picker summary { cursor: pointer; padding: 6px 11px; }
button:hover, .export-picker summary:hover { background: #eef3ff; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button:disabled { cursor: default; opacity: .55; }
input, select, textarea { padding: 7px 9px; max-width: 100%; }
a { color: var(--blue); }
summary { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); font-size: 12px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px clamp(12px, 2vw, 28px); background: #fff; border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.brand strong { font-size: 15px; }
.brand > span:last-child, .snapshot-label { color: var(--muted); font-size: 12px; }
.logo { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 7px; color: white; background: var(--blue); }
.top-divider { height: 16px; border-left: 1px solid var(--border); }
main { max-width: 1600px; margin: auto; padding: 18px clamp(10px, 2vw, 28px); }
.workbench { display: grid; grid-template-columns: 225px minmax(0, 1fr); gap: 14px; align-items: start; }
.panel { border: 1px solid var(--border); background: white; border-radius: 9px; min-width: 0; }
.fields summary, .coverage summary { padding: 11px 14px; }
.fields[open] summary { border-bottom: 1px solid var(--border); }
.badge { border-radius: 10px; background: #eef2fa; padding: 1px 7px; color: var(--muted); font-size: 11px; }
.field-content { padding: 11px; }
.field-content input { width: 100%; margin: 8px 0; }
.field-group-title { font-size: 11px; color: var(--muted); margin: 8px 2px 3px; font-weight: 650; }
.field { border: 0; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 28px; text-align: left; padding: 3px 4px; font-size: 12px; }
.type-badge { display: grid; place-items: center; min-width: 28px; font-size: 10px; font-weight: 650; color: var(--blue); background: #edf2ff; border-radius: 4px; }
.type-badge.calculated { background: #f2edff; color: var(--purple); }
.new-metric { width: 100%; margin-top: 8px; color: var(--blue); }
.tip { margin-top: 8px; }
.workspace { display: grid; min-width: 0; gap: 14px; }
.query, .result-content { padding: 15px; }
.query-heading, .result-heading, .viewbar, .actions, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.actions { justify-content: flex-end; flex-wrap: wrap; }
.primary { background: var(--blue); color: white; border-color: var(--blue); font-weight: 650; }
.primary:hover { background: #1b45b4; }
#run { min-width: 99px; }
#run[aria-busy="true"] { opacity: 1; }
#run[aria-busy="true"]::before {
  content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px;
  border: 1px solid #ffffff60; border-top-color: white; border-radius: 50%;
  animation: query-spin .7s linear infinite;
}
@keyframes query-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #run[aria-busy="true"]::before { animation: none; } }
.shelves { display: grid; gap: 6px; margin-top: 12px; }
.shelf-row { display: grid; grid-template-columns: 73px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 12px; }
.shelf { min-height: 37px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; background: #f8faff; border: 1px dashed #cfd9eb; border-radius: 6px; padding: 4px; }
.shelf.over { border-color: var(--blue); background: #e5edff; }
.chip { display: inline-flex; align-items: stretch; min-width: 0; max-width: 100%; border-radius: 5px; background: #e9efff; color: #244798; }
.chip.measure { background: #e5f6ef; color: #126456; }
.chip.filter { background: #f1ebfc; color: #5f389f; }
.chip button { min-width: 0; border: 0; background: transparent; color: inherit; padding: 4px 6px; text-align: left; overflow-wrap: anywhere; }
.chip button:hover { background: #0000000c; }
.chip button.remove { min-width: 22px; text-align: center; }
.shelf-add { color: var(--muted); background: transparent; border: 0; padding: 3px 6px; }
.query-status { margin-top: 7px; min-height: 18px; }
.viewbar { padding: 7px 11px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.views { display: flex; gap: 3px; flex-wrap: wrap; }
.views button { border-color: transparent; padding: 5px 9px; white-space: nowrap; }
.views button[aria-pressed="true"] { background: #e9efff; color: #1a47b7; font-weight: 650; }
.export-picker { position: relative; }
.export-options { position: absolute; right: 0; min-width: 178px; padding: 5px; border: 1px solid var(--border); background: white; border-radius: 6px; z-index: 2; box-shadow: 0 4px 12px #1d293e20; }
.export-options button { display: block; width: 100%; text-align: left; border: 0; }
.export-options p { padding: 5px 9px; }
#export-status:not(:empty) { margin-bottom: 8px; }
.result-heading { align-items: start; margin-bottom: 12px; }
#result-settings { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 4px; }
#result-settings select { padding: 4px 6px; font-size: 12px; }
.empty { background: #f6f8fc; border-radius: 6px; padding: 14px; color: var(--muted); }
.table-scroll { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 6px; }
table { border-collapse: collapse; min-width: 100%; font-size: 12px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid #edf0f5; white-space: nowrap; }
th { position: sticky; top: 0; background: #eef2f8; }
th button { border: 0; padding: 0; font-weight: 650; background: transparent; }
td { max-width: 360px; white-space: normal; overflow-wrap: anywhere; }
tr:nth-child(even) td { background: #f9fafe; }
.pager, .legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.legend { font-size: 12px; color: var(--muted); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 3px; margin-right: 4px; }
.bar-group { display: grid; grid-template-columns: minmax(85px, 24%) minmax(0, 1fr); gap: 8px; border-top: 1px solid #edf0f5; padding: 7px 0; }
.bar-label { align-self: center; font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.bar-series-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(75px, auto); gap: 7px; align-items: center; margin: 3px 0; }
.bar-track { position: relative; min-height: 13px; border-radius: 4px; background: #f1f4fa; }
.zero { position: absolute; height: 100%; border-left: 1px solid #8795ad; }
.bar-mark { display: block; position: absolute; height: 100%; min-width: 5px; padding: 0; border: 0; border-radius: 3px; }
.bar-amount { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.plot-svg { width: 100%; display: block; min-height: 150px; }
.plot-svg text { fill: var(--muted); font-size: 11px; }
.plot-svg [tabindex] { cursor: pointer; }
.plot-svg [tabindex]:focus-visible .point { stroke: #171c30; stroke-width: 3px; }
.plot-inspect { min-height: 35px; margin-top: 8px; padding: 7px 9px; border-radius: 5px; background: #f3f6ff; font-size: 12px; }
#result-footer { margin-top: 8px; }
#coverage-details { padding: 0 14px 12px; }
#coverage-details ul { margin: 6px 0; padding-left: 20px; }
.field-tooltip {
  position: fixed; z-index: 5; pointer-events: none;
  width: min(315px, calc(100% - 16px)); padding: 9px 11px;
  background: #fff; border: 1px solid var(--border); border-radius: 7px;
  box-shadow: 0 5px 18px #1d293e26; font-size: 12px; overflow-wrap: anywhere;
}
.field-tooltip p { color: var(--muted); margin-top: 3px; }
.expression { display: grid; gap: 3px; margin-top: 4px; }
.expression code { background: #f1f4fb; color: #263657; padding: 6px 8px; border-radius: 5px; overflow-wrap: anywhere; white-space: pre-wrap; }
dialog { border: 1px solid var(--border); border-radius: 10px; color: inherit; width: min(480px, calc(100% - 20px)); max-height: 88dvh; padding: 15px; box-shadow: 0 8px 40px #1d293e38; }
dialog::backdrop { background: #15233e69; }
.dialog-heading { margin-bottom: 10px; }
.dialog-heading button { padding: 2px 9px; }
#dialog-body { display: grid; gap: 8px; }
#dialog-body label.control { display: grid; gap: 3px; font-size: 12px; }
#dialog-body textarea { width: 100%; resize: vertical; min-height: 78px; }
.choices { display: grid; gap: 4px; max-height: 230px; overflow: auto; }
.choices label { display: flex; align-items: start; gap: 6px; overflow-wrap: anywhere; }
.choices input { flex-shrink: 0; }
.field-picker { display: grid; max-height: 260px; overflow: auto; }
.field-picker button { text-align: left; border: 0; }
.error { color: #a52234; margin: 7px 0; font-size: 12px; }
.dialog-actions { margin-top: 8px; }
@media (max-width: 760px) {
  main { padding-top: 10px; }
  .workbench { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .workspace { gap: 9px; }
  .fields summary { padding: 8px 12px; }
  .field { min-height: 36px; }
  .query, .result-content { padding: 11px; }
  .query-heading { align-items: start; flex-wrap: wrap; }
  .top-divider, .brand > span:last-child { display: none; }
  .viewbar { gap: 5px; }
  .views button { padding-inline: 6px; }
}
