/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:root, [data-bs-theme="light"] {
  --spark-sql-cluster-fill: #A0DFFF;
  --spark-sql-cluster-stroke: #3EC0FF;
  --spark-sql-node-fill: #C3EBFF;
  --spark-sql-edge: #444;
  --spark-sql-selected-fill: #E25A1CFF;
  --spark-sql-selected-stroke: #317EACFF;
  --spark-sql-linked-fill: #FFC106FF;
  --spark-sql-search-stroke: #FD7E14;
}
[data-bs-theme="dark"] {
  --spark-sql-cluster-fill: #1a5276;
  --spark-sql-cluster-stroke: #5dade2;
  --spark-sql-node-fill: #1b4f72;
  --spark-sql-edge: #adb5bd;
  --spark-sql-selected-fill: #c0470fff;
  --spark-sql-selected-stroke: #5dade2ff;
  --spark-sql-linked-fill: #d4a00aff;
  --spark-sql-search-stroke: #ffa94d;
}

svg g.label {
  font-size: 0.85rem;
  font-weight: normal;
  text-shadow: none;
  color: var(--bs-body-color);
}

svg g.cluster rect {
  fill: var(--spark-sql-cluster-fill);
  stroke: var(--spark-sql-cluster-stroke);
  stroke-width: 1px;
}

svg g.cluster > g.label {
  font-size: 0.75em;
  font-style: italic;
}

svg g.node rect {
  fill: var(--spark-sql-node-fill);
  stroke: var(--spark-sql-cluster-stroke);
  stroke-width: 1px;
}

/* Highlight the SparkPlan node name */
svg text :first-child:not(.stageId-and-taskId-metrics) {
  font-weight: bold;
  font-size: 0.85em;
}

svg text {
  fill: var(--bs-body-color);
}

svg path {
  stroke: var(--spark-sql-edge);
  stroke-width: 1.5px;
}

/* Breaks the long string like file path when showing tooltips */
.tooltip-inner {
  word-wrap:break-word;
}

/* Breaks the long job url list when showing Details for Query in SQL */
.job-url {
  word-wrap: break-word;
}

svg g.node rect.selected {
  fill: var(--spark-sql-selected-fill);
  stroke: var(--spark-sql-selected-stroke);
  stroke-width: 2px;
}

svg g.node rect.linked {
  fill: var(--spark-sql-linked-fill);
  stroke: var(--spark-sql-selected-stroke);
  stroke-width: 2px;
}

svg path.linked {
  fill: var(--spark-sql-selected-stroke);
  stroke: var(--spark-sql-selected-stroke);
  stroke-width: 2px;
}

/* Detail side panel */
#plan-viz-details-panel .card {
  font-size: 0.75rem;
}

#plan-viz-details-panel .card-body {
  max-height: 80vh;
  overflow-y: auto;
}

#plan-viz-details-panel .card-header {
  background-color: var(--spark-sql-node-fill);
  border-bottom-color: var(--spark-sql-cluster-stroke);
}

#plan-viz-details-panel .table th,
#plan-viz-details-panel .table td:first-child {
  white-space: nowrap;
}

#plan-viz-details-panel .table td:last-child {
  word-break: break-word;
}

/* Edge labels showing row counts */
.edgeLabel text {
  font-size: 10px;
  fill: var(--bs-secondary-color);
}

/* SVG text color for dark mode support */
#plan-viz-graph .node text,
#plan-viz-graph g.cluster text {
  fill: var(--bs-body-color);
}

#plan-viz-graph {
  position: relative;
}

#plan-viz-graph svg {
  width: 100%;
  height: 70vh;
  max-height: 70vh;
  display: block;
  cursor: grab;
  background-color: var(--bs-body-bg);
  user-select: none;
}

#plan-viz-graph svg.grabbing {
  cursor: grabbing;
}

/* Allow text selection inside HTML labels (detailed mode metrics tables) */
#plan-viz-graph svg foreignObject,
#plan-viz-graph svg foreignObject * {
  user-select: text;
}

.plan-viz-zoom-toolbar {
  position: absolute;
  top: 8px;
  right: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
}

.plan-viz-zoom-toolbar #plan-viz-zoom-level {
  display: inline-block;
  min-width: 3.25rem;
  font-variant-numeric: tabular-nums;
}

#plan-viz-search-expanded {
  width: auto;
}

#plan-viz-search-input {
  width: 12rem;
}

#plan-viz-search-count {
  min-width: 4.5rem;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
}

#plan-viz-search-count.no-match {
  color: var(--bs-danger);
}

/* Search result highlight: outline matched node/cluster with the search color. */
svg g.node rect.search-match,
svg g.cluster.search-match > rect {
  stroke: var(--spark-sql-search-stroke);
  stroke-width: 3px;
}

/* Currently active match: keep the outline visible and add an accent fill. */
svg g.node rect.search-match.search-active {
  fill: var(--spark-sql-linked-fill);
}

/* Dim non-matching nodes/clusters when a search is active.
   `!important` is needed because dagre-d3 writes an inline `opacity: 1`
   style on each <g class="node">/<g class="cluster"> at render time. */
svg g.node.search-dimmed,
svg g.cluster.search-dimmed {
  opacity: 0.3 !important;
}

/* Inline <pre> renderer used by the shared SQL DataTable column factory
 * (sql-table-utils.js) on the execution detail page. Keeps long SQL/error
 * text legible without stretching the row. */
.sql-cell-pre {
  font-size: 0.85rem;
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 0.25rem 0.5rem;
  background-color: transparent;
}

/* Collapsible disclosure used for long Description / Error Message cells.
 * Uses the native <details>/<summary> element so no JavaScript is needed. */
.sql-cell-details > summary {
  cursor: pointer;
  font-family: var(--bs-font-monospace);
  font-size: 0.85rem;
  list-style: revert;
  user-select: none;
}
.sql-cell-details[open] > summary {
  margin-bottom: 0.25rem;
}
