:root {
  --bg: #f5f6f1;
  --panel: #ffffff;
  --ink: #16211c;
  --muted: #66716a;
  --line: #d9ded6;
  --line-strong: #c6cec4;
  --green: #087f5b;
  --red: #b42318;
  --gold: #a46a00;
  --blue: #265d97;
  --violet: #6b4db3;
  --shadow: 0 10px 30px rgba(28, 39, 33, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 20px clamp(16px, 3vw, 34px) 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfbf8;
}

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

h1 {
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: 0;
}

.topbar p,
.panel-title p,
.notes p,
.filters span {
  color: var(--muted);
}

.topbar p {
  margin-top: 4px;
  line-height: 1.45;
  max-width: 820px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-link,
button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 8px 11px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.ghost-link:hover,
button:hover {
  border-color: #aeb9ad;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr)) auto;
  gap: 10px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: #fdfdfb;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.filters span {
  font-size: 12px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
}

.segmented {
  align-self: end;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  overflow: hidden;
  min-height: 38px;
  min-width: 0;
}

.segmented button,
.chart-tabs button {
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--muted);
  min-width: 0;
  white-space: normal;
}

.segmented button + button,
.chart-tabs button + button {
  border-left: 1px solid var(--line);
}

.segmented button.active,
.chart-tabs button.active {
  color: #fff;
  background: var(--ink);
}

main {
  padding: 14px clamp(16px, 3vw, 34px) 32px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi {
  padding: 13px;
}

.kpi b {
  display: block;
  font-size: 23px;
  line-height: 1.05;
  margin-bottom: 3px;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
}

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

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

.panel {
  padding: 13px;
  min-width: 0;
}

.panel-title,
.market-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.panel-title h2,
.market-heading h2 {
  font-size: 17px;
  letter-spacing: 0;
}

.panel-title p {
  margin-top: 3px;
  font-size: 12px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 3px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 8px 7px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

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

th {
  color: var(--muted);
  font-weight: 700;
  background: #fff;
  position: sticky;
  top: 0;
}

.markets-table tr {
  cursor: pointer;
}

.markets-table tbody tr:hover,
.markets-table tbody tr.active {
  background: #f0f3ec;
}

.market-actions {
  display: flex;
  gap: 8px;
}

.positive-gap {
  color: var(--green);
}

.muted {
  color: var(--muted);
}

.negative-gap {
  color: var(--red);
}

.neutral {
  color: var(--gold);
}

.chart-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 10px;
}

.chart-tabs button {
  min-height: 34px;
}

.chart-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

canvas {
  display: block;
  width: 100%;
  height: 360px;
}

.map-panel,
.market-panel {
  display: grid;
  align-content: start;
}

.map-panel canvas,
#mainChart {
  height: 430px;
}

.chart-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

canvas.interactive {
  cursor: crosshair;
}

.chart-tooltip {
  position: fixed;
  z-index: 50;
  max-width: min(320px, calc(100vw - 24px));
  pointer-events: none;
  background: rgba(22, 33, 28, 0.96);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(22, 33, 28, 0.22);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  transform: translate(-9999px, -9999px);
  transition: opacity 0.08s ease;
}

.chart-tooltip.visible {
  opacity: 1;
}

.chart-focus {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 45;
  pointer-events: none;
  opacity: 0;
  transform: translate(-9999px, -9999px);
}

.chart-focus.visible {
  opacity: 1;
}

.chart-focus-line,
.chart-focus-dot,
.chart-focus-bar {
  position: absolute;
  display: block;
  pointer-events: none;
}

.chart-focus-line {
  width: 1px;
  background: rgba(22, 33, 28, 0.34);
}

.chart-focus-dot {
  border: 2px solid currentColor;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.85), 0 4px 12px rgba(22, 33, 28, 0.2);
  transform: translate(-50%, -50%);
}

.chart-focus-bar {
  border: 2px solid currentColor;
  border-radius: 4px;
}

.chart-tooltip b {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

.chart-tooltip div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  white-space: nowrap;
}

.chart-tooltip span:first-child {
  color: #cdd6cf;
}

.notes {
  display: grid;
  gap: 9px;
}

.note {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcf8;
}

.note b {
  display: block;
  margin-bottom: 4px;
}

.note p {
  font-size: 13px;
  line-height: 1.4;
}

.mini-section {
  margin-top: 14px;
}

.mini-section h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

.small {
  max-height: 260px;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  padding: 3px 8px;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .layout,
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
.topbar,
  .panel-title,
  .market-heading {
    display: grid;
  }

  .topbar > div,
  .filters > *,
  .market-heading > div {
    min-width: 0;
  }

  .topbar p,
  .panel-title p {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .filters,
  .kpis {
    grid-template-columns: 1fr;
  }

  .segmented,
  .chart-tabs {
    width: 100%;
  }

  .segmented button,
  .chart-tabs button {
    padding-inline: 6px;
  }

  .market-heading h2 {
    overflow-wrap: anywhere;
  }

  canvas,
  #mainChart {
    height: 300px;
  }

  .map-panel canvas {
    height: 320px;
  }
}
