/* ============================================================
   Matrix Table Chart — Tool-specific styles
   ============================================================ */

/* ── Layout: header offset handled by JS (top set dynamically) ── */

:root {
  --dvz-control-select-width: 180px;
  --selector-canvas: #ffffff;
  --selector-inverse-canvas: #000000;
  --selector-surface-soft: #f7f7f5;
  --selector-hairline: #e6e6e6;
  --selector-hairline-soft: #f1f1f1;
  --selector-ink: #000000;
  --selector-inverse-ink: #ffffff;
  --selector-muted-ink: rgba(0, 0, 0, 0.64);
  --selector-muted-inverse-ink: rgba(255, 255, 255, 0.74);
}

.dvz-app {
  overflow: hidden !important;
  position: fixed !important;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  height: auto !important;
  margin-top: 0 !important;
}

.dvz-app [hidden] {
  display: none !important;
}

.dvz-app[data-dvz-view="selector"] #chart-selector {
  display: block !important;
}

.dvz-app[data-dvz-view="selector"] #dvz-chart,
.dvz-app[data-dvz-view="selector"] #dvz-sidebar {
  display: none !important;
}

.dvz-app[data-dvz-view="chart"] #chart-selector {
  display: none !important;
}

.dvz-app[data-dvz-view="chart"] #dvz-chart {
  display: grid !important;
}

.dvz-app[data-dvz-view="chart"] #dvz-sidebar {
  display: flex !important;
}

dataviz-tool-header[hidden],
body[data-dvz-tool-header="hidden"] dataviz-tool-header {
  display: none !important;
}

/* ── Chart Selector ─────────────────────────────────────── */

#chart-selector {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 0 !important;
  background:
    radial-gradient(circle at top left, rgba(247, 247, 245, 0.95) 0%, rgba(247, 247, 245, 0.45) 28%, transparent 58%),
    radial-gradient(circle at top right, rgba(241, 241, 241, 0.85) 0%, rgba(241, 241, 241, 0.15) 26%, transparent 54%),
    linear-gradient(180deg, #ffffff 0%, #fafaf9 100%);
}

.dvz-catalog {
  width: min(1152px, calc(100% - 48px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.dvz-catalog__header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 16px;
  margin-bottom: 32px;
}

.dvz-catalog__kicker {
  margin: 0 0 12px;
  color: #6b7280;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.dvz-catalog__title {
  grid-column: 1 / -1;
  margin: 0;
  color: #111827;
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: 0;
}

.dvz-catalog__lead {
  grid-column: 1 / -1;
  max-width: 680px;
  margin: 2px 0 0;
  color: rgba(0, 0, 0, 0.64);
  font-size: 1rem;
  line-height: 1.7;
}

.dvz-catalog__grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 20px;
}

.dvz-catalog-card {
  --dvz-catalog-card-surface: var(--selector-canvas);
  --dvz-catalog-card-border: var(--selector-hairline);
  --dvz-catalog-card-ink: var(--selector-ink);
  --dvz-catalog-card-muted: var(--selector-muted-ink);

  display: block;
  min-height: 100%;
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s ease;
}
.dvz-catalog-card:hover {
  transform: translateY(-3px);
}
.dvz-catalog-card:active {
  transform: translateY(0);
}
.dvz-catalog-card:focus-visible {
  outline: none;
}
.dvz-catalog-card:focus-visible .dvz-catalog-card__panel {
  outline: 2px solid var(--dvz-catalog-card-ink);
  outline-offset: 4px;
}
.dvz-catalog-card__panel {
  display: flex;
  min-height: 240px;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
  border: 1px solid var(--dvz-catalog-card-border);
  border-radius: 24px;
  background: var(--dvz-catalog-card-surface);
  padding: 28px;
  color: var(--dvz-catalog-card-ink);
  box-shadow: none;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease;
}
.dvz-catalog-card:hover .dvz-catalog-card__panel {
  border-color: var(--dvz-catalog-card-ink);
}
.dvz-catalog-card__header,
.dvz-catalog-card__footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.dvz-catalog-card__eyebrow,
.dvz-catalog-card__meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.dvz-catalog-card__eyebrow,
.dvz-catalog-card__meta {
  opacity: 0.7;
}
.dvz-catalog-card__body {
  display: flex;
  flex-direction: column;
}
.dvz-catalog-card__thumbnail {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 18px;
  overflow: hidden;
  border: 1px solid var(--dvz-catalog-card-border);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(135deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%) 0 0 / 16px 16px,
    var(--dvz-catalog-card-surface);
}
.dvz-catalog-card__thumbnail-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #ffffff;
}
.dvz-catalog-card__title {
  margin: 0;
  color: #000000;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: 0;
}
.dvz-catalog-card__description {
  margin: 12px 0 0;
  color: var(--dvz-catalog-card-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}
.dvz-catalog-card__glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #000000;
  font-size: 1.5rem;
  line-height: 1;
  opacity: 0.88;
}

.dvz-catalog-card[data-surface="canvas"] {
  --dvz-catalog-card-surface: var(--selector-canvas);
  --dvz-catalog-card-border: var(--selector-hairline);
  --dvz-catalog-card-ink: var(--selector-ink);
  --dvz-catalog-card-muted: var(--selector-muted-ink);
}

.dvz-catalog-card[data-surface="soft"] {
  --dvz-catalog-card-surface: var(--selector-surface-soft);
  --dvz-catalog-card-border: var(--selector-hairline);
  --dvz-catalog-card-ink: var(--selector-ink);
  --dvz-catalog-card-muted: var(--selector-muted-ink);
}

.dvz-catalog-card[data-surface="soft-alt"] {
  --dvz-catalog-card-surface: var(--selector-hairline-soft);
  --dvz-catalog-card-border: var(--selector-hairline);
  --dvz-catalog-card-ink: var(--selector-ink);
  --dvz-catalog-card-muted: var(--selector-muted-ink);
}

.dvz-catalog-card[data-surface="inverse"] {
  --dvz-catalog-card-surface: var(--selector-inverse-canvas);
  --dvz-catalog-card-border: var(--selector-inverse-canvas);
  --dvz-catalog-card-ink: var(--selector-inverse-ink);
  --dvz-catalog-card-muted: var(--selector-muted-inverse-ink);
}

@media (min-width: 768px) {
  .dvz-catalog__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .dvz-catalog__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  #chart-selector {
    padding: 0 !important;
  }

  .dvz-catalog {
    width: min(100% - 40px, 720px);
    padding: 28px 0 40px;
  }

  .dvz-catalog__header {
    grid-template-columns: minmax(0, 1fr);
  }

  .dvz-catalog__title {
    font-size: 2rem;
  }

  .dvz-catalog-card__panel {
    min-height: 216px;
    gap: 22px;
    padding: 22px;
    border-radius: 20px;
  }

  .dvz-catalog-card__body {
    max-width: none;
  }
}

/* Shared editor layout: stack the chart and setting sidebar on narrow screens. */
@media (max-width: 768px) {
  .dvz-app[data-dvz-view="chart"] {
    flex-direction: column;
  }

  .dvz-app[data-dvz-view="chart"] #main-area,
  .dvz-app[data-dvz-view="chart"] #dvz-sidebar {
    width: 100%;
    min-width: 0;
  }

  .dvz-app[data-dvz-view="chart"] #dvz-sidebar {
    flex: 0 0 auto;
    max-height: min(48dvh, 460px);
    border-top: 1px solid var(--dvz-setting-sidebar-border, #e5e7eb);
    border-left: 0;
  }

  .dvz-setting-sidebar__select-wrap {
    display: block;
  }

  .dvz-setting-sidebar [data-dvz-setting-tab-select] {
    display: block;
  }

  .dvz-setting-sidebar__tabs,
  .dvz-setting-sidebar [data-dvz-setting-tabs] {
    display: none;
  }
}

/* ── Chart Switcher bar ─────────────────────────────────── */

/* Override dvz-common grid to account for #chart-switcher row */
#dvz-chart {
  grid-template-rows: auto auto minmax(0, 1fr) auto auto !important;
}

/* Pin each grid child to its intended row explicitly. Otherwise, when
   #chart-title or #dvz-controls are empty (display:none via :empty),
   auto-placement shifts #chart-area up into the auto row, causing it
   to collapse to the SVG's intrinsic content height instead of taking
   the 1fr fractional row. */
#dvz-chart > #chart-switcher { grid-row: 1; }
#dvz-chart > #chart-title    { grid-row: 2; }
#dvz-chart > #chart-area     { grid-row: 3; }
#dvz-chart > #dvz-controls   { grid-row: 4; }
#dvz-chart > #chart-source   { grid-row: 5; }

#chart-switcher {
  flex-shrink: 0;
}

#chart-back-btn {
  transition: color 0.15s;
}

/* ── SVG template (dvz-template-svg) ────────────────────── */
/* Shared styles for all SVG-based charts.                  */
/* Applied when templateType='svg' in chart-registry.       */

.dvz-template-svg {
  position: relative;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  overflow: hidden;
}
.dvz-template-svg svg { width: 100%; height: auto; display: block; }

/* ── Empty state ────────────────────────────────────────── */

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 400px;
  color: #999; font-size: 15px; gap: 12px;
}
.empty-state .icon { font-size: 48px; opacity: 0.4; }

/* ── Shared axis ────────────────────────────────────────── */

.x-axis path, .x-axis line,
.y-axis path, .y-axis line,
.axis path, .axis line {
  stroke: #d5dce6;
  shape-rendering: crispEdges;
}

.x-axis .tick line,
.y-axis .tick line,
.axis .tick line {
  stroke: #e7edf4;
}

.x-axis text,
.y-axis text,
.axis text {
  fill: #99a3b2;
  font-size: 10px;
  font-family: sans-serif;
}

.chart-container {
  position: relative;
  background: #fff;
  border-radius: 8px;
  min-height: 0;
  height: 100%;
}
#dvz-legend {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  font-size: 11px;
  line-height: 1.5;
  max-height: 80%;
  overflow-y: auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
}
#dvz-legend:empty { display: none; }
#dvz-legend.top-right { top: 16px; right: 16px; }
#dvz-legend.bottom-right { bottom: 16px; right: 16px; }
#dvz-legend .dvz-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
#dvz-legend .dvz-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

#dvz-error:not(:empty) {
  display: block !important;
}
.chart-container svg { width: 100%; height: 100%; display: block; }
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #9ca3af;
  font-size: 0.95rem;
}
.dvz-dropzone { cursor: pointer; min-height: 88px; transition: background-color 160ms ease-out, border-color 160ms ease-out; }
.dvz-dropzone:hover { background: #f9fafb; }
.dvz-check { display: flex; align-items: center; gap: 8px; }
.dvz-check input { width: 16px; height: 16px; }
.dvz-preview-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.dvz-preview-table th, .dvz-preview-table td { border-bottom: 1px solid #f3f4f6; padding: 4px 6px; text-align: left; white-space: nowrap; }
.dvz-preview-table th { color: #6b7280; font-weight: 600; }
path.series.is-faded, circle.is-faded { opacity: 0.12; }
.dvz-control-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease-out, background-color 160ms ease-out;
}
.dvz-control-btn:hover { background: #f9fafb; }
.dvz-control-btn:active { transform: scale(0.97); }
.dvz-controls-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.dvz-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.dvz-control-label {
  font-size: 11px;
  font-weight: 700;
  color: #4b5563;
}
.dvz-control-select {
  width: var(--dvz-control-select-width);
  min-width: var(--dvz-control-select-width);
  max-width: var(--dvz-control-select-width);
  height: 30px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  font-size: 12px;
  color: #374151;
}
.adjacency-matrix .background { fill: #eee; }
.adjacency-matrix line { stroke: #fff; shape-rendering: crispEdges; }
.axis path, .axis line { stroke: #e5e7eb; }
@media (hover: hover) and (pointer: fine) {
  .dvz-catalog-card:hover { transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .dvz-catalog-card, .dvz-control-btn { transition: none; }
}
