/* Charts in answers (js/charts.js, js/network-chart.js): the chart card, its menu, tooltips, the table view and full screen.
   Moved out of base.css, shared-components.css and features.css in their
   original cascade order; loaded after features.css and before type.css. */

.analysis-chart {
  position: relative;
  width: 100%;
  max-width: 780px;
  margin: 24px 0 10px;
  color: var(--text);
}

.analysis-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.analysis-chart-copy {
  min-width: 0;
}

.analysis-chart-copy h3 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 650;
  line-height: 1.35;
}

.analysis-chart-copy p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.analysis-chart-menu {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 140ms ease;
}

.analysis-chart:hover .analysis-chart-menu,
.analysis-chart-menu:focus-within,
.analysis-chart-menu.is-open {
  opacity: 1;
  pointer-events: auto;
}

.analysis-chart-menu-trigger {
  position: relative;
  z-index: 1;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: var(--hover-bg);
  color: var(--text-soft);
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}

.analysis-chart-menu-trigger:hover,
.analysis-chart-menu-trigger:focus-visible,
.analysis-chart-menu.is-open .analysis-chart-menu-trigger {
  background: var(--hover-bg);
  border-color: var(--border-soft);
  color: var(--ink);
  transform: translateY(-1px);
}

.analysis-chart-menu-trigger svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.analysis-chart-menu-popover {
  position: absolute;
  z-index: 8;
  top: calc(100% + 4px);
  right: 0;
  width: max-content;
  min-width: 190px;
  padding: 5px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-float);
}

.analysis-chart-menu-popover button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.analysis-chart-menu-popover button:hover,
.analysis-chart-menu-popover button:focus-visible {
  background: var(--hover-bg);
  color: var(--ink);
}

.analysis-chart-menu-popover button:disabled {
  opacity: .5;
  cursor: default;
}

/* A whole-country map of katastry or obcí: the row to pick one okres or kraj
   and to find a territory by name or code. Drawn in the card, above the map. */
.analysis-chart-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.analysis-chart-scope {
  flex: 0 1 230px;
  min-width: 140px;
}

.analysis-chart-search-field {
  position: relative;
  flex: 1 1 200px;
  min-width: 0;
}

.analysis-chart-scope,
.analysis-chart-search {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--dur) ease;
}

.analysis-chart-scope:focus-visible,
.analysis-chart-search:focus-visible {
  border-color: var(--ink);
}

.analysis-chart-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.analysis-chart-suggestions {
  position: absolute;
  z-index: 3;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 260px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-float);
}

.analysis-chart-suggestions button {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.analysis-chart-suggestions button:hover,
.analysis-chart-suggestions button:focus-visible {
  background: var(--surface-inset);
  outline: none;
}

.analysis-chart-suggestions small {
  color: var(--muted);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.analysis-chart.is-table .analysis-chart-controls {
  display: none;
}

@media (max-width: 520px) {
  .analysis-chart-controls {
    flex-wrap: wrap;
  }

  .analysis-chart-scope {
    flex-basis: 100%;
  }
}

.analysis-chart-body {
  position: relative;
  width: 100%;
  height: 360px;
  overflow: hidden;
}

.analysis-chart-pie .analysis-chart-body {
  height: 300px;
}

.analysis-chart-map .analysis-chart-body {
  height: 374px;
}

.analysis-chart-network .analysis-chart-body { height: 380px; }

.network-chart { position: relative; display: flex; flex-direction: column; }

.network-canvas {
  flex: 1;
  min-height: 0;
  position: relative;
  background-color: transparent;
  background-image: radial-gradient(rgb(var(--muted-rgb) / .13) 1px, transparent 1.2px);
  background-size: 18px 18px;
  background-position: 9px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* Hover details float in a corner of the drawing; network-chart.js picks
   the corner opposite the hovered element. */
.network-details {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  max-width: min(340px, calc(100% - 20px));
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: rgb(var(--surface-page-rgb) / .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-float);
  pointer-events: none;
  font-size: var(--text-xs);
  line-height: 1.45;
  overflow-wrap: anywhere;
  animation: networkDetailsIn .16s var(--ease-out);
}

.network-details[hidden] { display: none; }

.network-details.is-right { left: auto; right: 10px; }

.network-details.is-top { bottom: auto; top: 10px; }

.network-details-dot {
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--dot, var(--accent));
}

.network-details-dot[hidden] { display: none; }

.network-details-text { min-width: 0; }

.network-details-title { color: var(--ink); font-weight: 600; }

.network-details-meta { margin-top: 1px; color: var(--muted); }

.network-details-meta[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .network-details { animation: none; }
}
@media (max-width: 600px) {
  .analysis-chart-network .analysis-chart-body { height: 360px; }
}
.analysis-chart-plot {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Charts, maps and networks draw only after their libraries and geography
   arrive, so the reserved box would sit empty meanwhile. It shimmers like a
   loading image instead, and the shimmer fades off the finished drawing
   rather than the drawing popping in. The shimmer is opaque: a chart's last
   adjustments (legend centring, Vega's own resize pass) happen behind it. */
.analysis-chart-body::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: var(--r-2xl);
  background: var(--skeleton), var(--surface-page);
  background-size: 220% 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease;
}

.analysis-chart:not([data-chart-hydrated="true"]):not(.is-fallback):not(.is-table) .analysis-chart-body::before {
  opacity: 1;
  animation: subtleSkeleton 1.9s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .analysis-chart-body::before {
      transition: none;
      animation: none !important;
    }
}
.analysis-chart.is-table .analysis-chart-plot,
.analysis-chart:not(.is-table) .chart-table-view {
  display: none !important;
}

.analysis-chart.is-table .chart-table-view {
  display: block !important;
}

.analysis-chart-plot .vega-embed,
.analysis-chart-plot .vega-embed > div,
.analysis-chart-plot svg,
.analysis-chart-plot canvas {
  max-width: 100%;
}

/* Dense obec and katastr maps avoid a Vega selection because it recalculates
   every shape on each pointer move. One host class lets the browser dim the
   existing SVG paths directly, with no chart dataflow or geometry redraw. */
.analysis-chart-map .analysis-chart-plot.has-map-hover .map-valued-marks path {
  opacity: .58;
}

.analysis-chart-map .analysis-chart-plot.has-map-hover .map-valued-marks path.is-map-hovered {
  opacity: 1;
  stroke-width: 1.8px;
}

.analysis-chart-tooltip {
  position: fixed;
  z-index: 1000;
  min-width: 190px;
  max-width: min(300px, calc(100vw - 24px));
  padding: 10px 11px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  color: var(--text);
  font-family: var(--font-sans);
  pointer-events: none;
}

.analysis-chart-tooltip-map {
  width: min(340px, calc(100vw - 24px));
  max-width: min(380px, calc(100vw - 24px));
}

.analysis-chart-tooltip-title {
  margin-bottom: 7px;
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 650;
  line-height: 1.2;
}

.analysis-chart-tooltip-row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 21px;
  font-size: var(--text-xs);
  line-height: 1.3;
}

.analysis-chart-tooltip-row.is-single-series {
  grid-template-columns: minmax(0, 1fr) auto;
}

.analysis-chart-tooltip-row.is-text {
  align-items: start;
}

.analysis-chart-tooltip-row.is-text .analysis-chart-tooltip-label {
  overflow: visible;
  color: var(--muted);
  text-overflow: clip;
  white-space: normal;
}

.analysis-chart-tooltip-row.is-text .analysis-chart-tooltip-value {
  overflow-wrap: anywhere;
  text-align: right;
  white-space: normal;
}

.analysis-chart-tooltip-map .analysis-chart-tooltip-row.is-single-series {
  grid-template-columns: minmax(108px, .8fr) minmax(0, 1.2fr);
  align-items: baseline;
  column-gap: 16px;
}

.analysis-chart-tooltip-map .analysis-chart-tooltip-row > .analysis-chart-tooltip-value {
  text-align: right;
}

.analysis-chart-tooltip-section-label {
  margin: 5px 0 2px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.3;
}

.analysis-chart-tooltip-map .analysis-chart-tooltip-row.is-list-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  min-height: 19px;
}

.analysis-chart-tooltip-row.is-list-item .analysis-chart-tooltip-label {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.analysis-chart-tooltip-row.is-list-item .analysis-chart-tooltip-value {
  text-align: right;
  white-space: nowrap;
}

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

.analysis-chart-tooltip-label {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-chart-tooltip-value {
  color: var(--ink);
  font-size: var(--text-xs);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.chart-table-view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chart-table-view .table-copy-wrapper {
  min-height: 100%;
  margin: 0;
}

.chart-table-view .table-copy-scroll {
  min-height: 100%;
}

.chart-table-view table.md-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}

.analysis-chart.is-fallback .analysis-chart-menu-trigger {
  display: none;
}

@media (max-width: 720px) {
  .analysis-chart {
      margin-top: 20px;
    }

  .analysis-chart-body {
      height: 300px;
    }

  .analysis-chart-pie .analysis-chart-body {
      height: 270px;
    }
}
@media (prefers-reduced-motion: reduce) {
  .analysis-chart-menu,
    .analysis-chart-menu-trigger {
      transition: none;
    }
}
/* ── Full-screen chart ─────────────────────────────────────────────── */
.chart-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  background: var(--surface-page);
  animation: chatContentReveal .16s ease-out;
}

.chart-fullscreen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}

.chart-fullscreen-head h3 {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-fullscreen-close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-input);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.chart-fullscreen-close:hover { background: var(--hover-bg); }

.chart-fullscreen-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

/* The body keeps its reserved inline height in the answer; here it fills. */
.chart-fullscreen .analysis-chart-body {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0;
}

body.chart-fullscreen-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .chart-fullscreen { animation: none; }
}
