/* The side panel. First what every section has (title, folding, putting
   down into the strip, see source/ui/panelSections.js), then the sections
   that need rules of their own, from top to bottom. */

/* The side panel holds up to three columns side by side, each of the
   same fixed width. */
#sidePanel {
  grid-area: side;
  display: flex;
  min-height: 0;
}

.panelColumn {
  display: flex;
  flex: none;
  flex-direction: column;
  width: var(--size-side-panel);
  min-height: 0;
  /* With everything unfolded the sections can get longer than the window.
     Then the column scrolls, each for itself. */
  overflow-y: auto;
  background: var(--color-panel);
  border-left: 1px solid var(--color-border);
}

/* The line that shows where a dragged section gets a column of its own.
   It lies above the page and takes no part in it. */
.panelDropLine {
  position: fixed;
  z-index: 50;
  background: var(--color-accent);
  pointer-events: none;
}

/* A section. It keeps its height when room gets short; only the layers
   give way, see below. */
.panel {
  flex: none;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--color-border);
}

/* A section that is dragged to another place, and the line that shows
   where it would land: above or below the section the mouse is over. */
.panel.isMoving {
  opacity: 0.5;
}

.panel.dropBefore {
  box-shadow: inset 0 2px 0 var(--color-accent);
}

.panel.dropAfter {
  box-shadow: inset 0 -2px 0 var(--color-accent);
}

/* The font of the Text section: a field to type the name into, with the
   arrow that opens the list of fonts at its right end. */
.fontField {
  display: flex;
  min-width: 0;
}

.fontField input {
  flex: 1;
  min-width: 0;
  border-right: 0;
  border-radius: 3px 0 0 3px;
}

.fontFieldButton {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 22px;
  padding: 0;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: 0 3px 3px 0;
  color: var(--color-text-dim);
}

.fontFieldButton:hover {
  color: var(--color-text);
}

.fontFieldButton svg {
  width: 14px;
  height: 14px;
}

/* The grip at the lower edge of a section with a list: dragging it sets
   how high the list is. It lies in the lower padding of the section and
   adds no height of its own. A list with a height set by hand keeps it. */
.panelHeightGrip {
  flex: none;
  height: 8px;
  margin: 2px 0 -10px;
  cursor: ns-resize;
}

.panelHeightGrip:hover,
.panelHeightGrip.isDragging {
  background: linear-gradient(var(--color-accent), var(--color-accent)) center / 100% 2px no-repeat;
}

#libraryList.hasSetHeight,
#layerList.hasSetHeight {
  max-height: none;
}

/* The title shares its row with the cross that puts the section down. The
   space below the title belongs to the row. */
.panelHeader {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 8px;
}

/* Triangle, icon and name sit in one row. A click on it folds the section. */
.panelTitle {
  display: flex;
  flex: 1;
  align-items: center;
  cursor: pointer;
}

.panelTitle:hover {
  color: var(--color-text);
}

/* The little triangle: down while open, to the right while folded. */
.panelTitle::before {
  content: "";
  display: inline-block;
  flex: none;
  margin-right: 6px;
  border: 4px solid transparent;
  border-top-color: currentColor;
  border-bottom-width: 0;
}

.panel.collapsed .panelTitle::before {
  border: 4px solid transparent;
  border-left-color: currentColor;
  border-right-width: 0;
}

.panelTitleIcon {
  display: inline-flex;
  flex: none;
  margin-right: 6px;
}

.panelTitleIcon svg {
  width: 14px;
  height: 14px;
}

/* Folded: only the row with the title is left. */

.panel.collapsed {
  flex: none;
  padding-bottom: 8px;
}

.panel.collapsed .panelHeader {
  margin-bottom: 0;
}

.panel.collapsed > :not(.panelHeader),
.panel.collapsed .panelHeader > :not(.panelTitle):not(.panelDockButton) {
  display: none;
}

/* Put down: the section is gone from the list, its icon waits in the
   strip. */

.panelDockButton {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 4px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 3px;
  color: var(--color-text-dim);
  opacity: 0.55;
  cursor: pointer;
}

.panelDockButton:hover {
  background: var(--color-panel-raised);
  color: var(--color-text);
  opacity: 1;
}

.panelDockButton svg {
  width: 12px;
  height: 12px;
}

.panel.docked {
  display: none;
}

/* The strip at the top of a column. It stays in view when the column
   scrolls, above what scrolls by below it. A full row goes on in a new
   row below. */
.panelDock {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex: none;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px;
  background: var(--color-panel);
  border-bottom: 1px solid var(--color-border);
}

.panelDockItem {
  color: var(--color-text-dim);
}

.panelDockItem:hover {
  color: var(--color-text);
}

.panelDockItem.isIdle {
  opacity: 0.4;
}

/* The cross that closes a column: at the right end of its strip, below
   each other with the crosses of the sections. */
.panelColumnClose {
  align-self: center;
  margin-right: 2px;
  margin-left: auto;
}

/* Position and size of the selection: the lock for the proportions in
   front of width and height, which it belongs to; X and Y on the right. */

.placementGrid {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px 8px;
}

.placementLabel {
  color: var(--color-text);
}

/* The rows of the angles start below the lock, in line with B and H; the
   number of the rotation has its row to itself. */
.placementAngleRow {
  grid-column: 2;
}

#placementRotationSlot {
  grid-column: 3 / -1;
}

.placementIcon {
  display: inline-flex;
  color: var(--color-text-dim);
}

/* The lock sits in front of both rows, beside width and height. */
.placementLock {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 100%;
  min-height: 40px;
  padding: 0;
  background: var(--color-panel-raised);
  border: 0;
  border-radius: 4px;
  color: var(--color-text-dim);
  cursor: pointer;
}

.placementLock.on {
  color: #ffffff;
}

/* The color effect of an instance. */

.effectFields {
  margin-top: 6px;
}

.effectFields:empty {
  display: none;
}

/* "Advanced": label, percentage, the formula, fixed value. */
.effectAdvancedGrid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  justify-items: start;
  align-items: center;
  gap: 6px;
}

.effectFormula {
  color: var(--color-text-dim);
  white-space: nowrap;
}

/* Color and stroke: the two colors below each other, each with its "no
   color" button; behind them the button that swaps them, which belongs to
   both; the stroke width below, in line with the colors. */

.styleGrid {
  display: grid;
  grid-template-columns: auto auto auto auto minmax(0, 1fr);
  align-items: center;
  gap: 6px 8px;
}

.styleSwap {
  grid-column: 4;
  grid-row: 1 / span 2;
  justify-self: start;
}

/* "No color" while it is in force: grayed, the color field beside it
   shows the state. A click still brings the color back. */
.styleGrid .iconButton[aria-pressed="true"] {
  opacity: 0.35;
}

.styleWidth {
  grid-column: 2 / -1;
}

.styleSwap svg {
  width: 16px;
  height: 16px;
}

/* The gear that opens the part below. */
.styleGear {
  grid-column: 5;
  grid-row: 1 / span 2;
  justify-self: end;
}

/* What the gear opens: stroke or fill at the top, then the kind of fill,
   the color, the bar of a gradient, the palette. */

.fillEditor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.fillEditor[hidden] {
  display: none;
}

.fillEditor select {
  width: 100%;
  height: 22px;
  padding: 0 4px;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: 3px;
}

/* Stroke and fill share the row, each half of it. */
.fillEditorTarget {
  flex: 1;
  height: 22px;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  cursor: pointer;
}

.fillEditorTarget.on {
  border-color: var(--color-accent);
}

/* The bar of a gradient: the gradient itself, below it a pointer for
   every color. The pointers stand out a little at both ends, so the bar
   leaves them room at its sides. */

.gradientBar {
  padding: 0 6px;
  touch-action: none;
  cursor: copy;
}

.gradientBar[hidden] {
  display: none;
}

.gradientBarStrip {
  height: 22px;
  border: 1px solid var(--color-border);
  background:
    var(--swatch-image),
    repeating-conic-gradient(#b8b8b8 0% 25%, #ffffff 0% 50%) 0 0 / 10px 10px;
}

.gradientBarPointers {
  position: relative;
  height: 18px;
}

/* A pointer: a little house, its roof pointing at the place on the bar,
   its body in the color. The roof is black on the one that is picked. */
.gradientPointer {
  --swatch-color: #000000;
  position: absolute;
  top: 6px;
  width: 11px;
  height: 11px;
  margin-left: -6px;
  border: 1px solid #ffffff;
  box-shadow: 0 0 0 1px #000000;
  background:
    linear-gradient(var(--swatch-color), var(--swatch-color)),
    repeating-conic-gradient(#b8b8b8 0% 25%, #ffffff 0% 50%) 0 0 / 6px 6px;
  cursor: ew-resize;
}

.gradientPointer::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -7px;
  border: 5.5px solid transparent;
  border-top-width: 0;
  border-bottom: 6px solid #9a9a9a;
}

.gradientPointer.isSelected::before {
  border-bottom-color: #000000;
  filter: drop-shadow(0 0 1px #ffffff);
}

.gradientPointer.isLeaving {
  opacity: 0.3;
}

/* Filters. Plus and gear sit in the row of the title, in front of the
   cross that puts the section down. */

.panelHeaderButton {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 18px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 3px;
  color: var(--color-text-dim);
  cursor: pointer;
}

.panelHeaderButton:hover {
  background: var(--color-panel-raised);
  color: var(--color-text);
}

.panelHeaderButton svg {
  width: 14px;
  height: 14px;
}

.filterEmpty {
  margin: 0;
  color: var(--color-text-dim);
}

.filterList {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* One filter: its name with eye and bin, its fields below. */
.filterCard {
  padding: 2px 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 5px;
}

.filterCard.isFolded {
  padding-bottom: 2px;
}

.filterCard.isFolded .filterFields {
  display: none;
}

.filterCardHeader {
  display: flex;
  align-items: center;
  gap: 2px;
}

.filterCardTitle {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  height: 24px;
  padding: 0;
  background: transparent;
  border: 0;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

/* The same little triangle the sections have. */
.filterCardTitle::before {
  content: "";
  flex: none;
  margin-right: 6px;
  border: 4px solid transparent;
  border-top-color: currentColor;
  border-bottom-width: 0;
}

.filterCard.isFolded .filterCardTitle::before {
  border: 4px solid transparent;
  border-left-color: currentColor;
  border-right-width: 0;
}

/* A filter that is switched off keeps its fields, only paler. */
.filterCard.isOff .filterCardTitle,
.filterCard.isOff .filterFields {
  opacity: 0.5;
}

.filterFields {
  margin-top: 4px;
}

/* The two blur numbers, and at their right the lock that ties them. */
.filterBlurGrid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 10px;
}

.filterBlurLock {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 100%;
  padding: 0;
  background: var(--color-panel-raised);
  border: 0;
  border-radius: 4px;
  color: var(--color-text-dim);
  cursor: pointer;
}

.filterBlurLock.on {
  color: #ffffff;
}

.filterCheck {
  grid-column: 1 / -1;
}

.numberWithUnit {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* Align */

.alignLabel {
  color: var(--color-text-dim);
}

.alignRow {
  display: flex;
  gap: 1px;
}

.alignToStage {
  margin-bottom: 6px;
}

/* Library and layers hold lists that reach from edge to edge. So these
   two sections have no room at their sides, and what is not a list brings
   its own. */

#libraryPanel,
.layerPanel {
  padding-right: 0;
  padding-left: 0;
}

#libraryPanel .panelHeader,
.layerPanel .panelHeader,
.panelHint {
  padding: 0 10px;
}

/* Library */

.panelHint {
  margin: 0;
  color: var(--color-text-dim);
}

#libraryList {
  /* As high as its rows, up to half of the side panel; see
     source/ui/panelHeights.js. */
  max-height: calc(var(--side-panel-height, 560px) / 2);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

/* The button that makes a folder, above the list. */
.libraryTools {
  display: flex;
  align-items: center;
  padding: 0 8px 2px 6px;
  border-bottom: 1px solid #2a2a2a;
}

/* What lies in a folder is set in below it (--depth, see
   source/ui/libraryPanel.js). */
.libraryRow {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 6px 0 calc(6px + var(--depth, 0) * 14px);
  border-bottom: 1px solid #2a2a2a;
  cursor: grab;
}

.libraryRow:hover {
  background: var(--color-panel-raised);
}

/* Layers. The list is as high as its rows, up to half of the side panel,
   like the one of the library. */

.layerPanel {
  display: flex;
  flex-direction: column;
}

.layerPanel .panelHeader {
  margin-bottom: 4px;
}

#layerList {
  max-height: calc(var(--side-panel-height, 560px) / 2);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

/* The row above the list: new and delete on the left, on the right the
   icons of the three columns, above the columns they stand for. */
.layerColumnHeader {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px 2px 6px;
  border-bottom: 1px solid #2a2a2a;
}

/* What lies in a folder is set in below it, by one step for every folder
   it lies in (--depth, see source/ui/layerPanel.js). */
.layerRow {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 8px 0 calc(6px + var(--depth, 0) * 14px);
  border-bottom: 1px solid #2a2a2a;
  cursor: default;
}

.layerRow:hover {
  background: var(--color-panel-raised);
}

/* Has to stay below the hover: the layer in use keeps its color under the
   mouse. */
.layerRow.active {
  background: var(--color-accent-soft);
}

.layerRow.dragging {
  opacity: 0.5;
}

.layerRow.hiddenLayer .layerName {
  color: var(--color-text-dim);
}

.layerRow.dropBefore::before,
.layerRow.dropAfter::after {
  content: "";
  position: absolute;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--color-accent);
  pointer-events: none;
}

.layerRow.dropBefore::before {
  top: -1px;
}

/* A dragged row would go into this folder. */
.libraryRow.dropInto,
.layerRow.dropInto {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

/* The triangle that opens and closes a folder. */
.layerFolderToggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 20px;
  margin-left: -2px;
  padding: 0;
  color: var(--color-text-dim);
  background: transparent;
  border: 0;
  cursor: pointer;
}

.layerFolderToggle:hover {
  color: var(--color-text);
}

.layerFolderToggle svg {
  width: 14px;
  height: 14px;
}

.layerRow.dropAfter::after {
  bottom: -1px;
}

.layerKind {
  flex: none;
  display: inline-flex;
  width: 16px;
  color: var(--color-text-dim);
}

/* A masked layer is set in below its mask. */
.layerRow.maskedLayer .layerKind {
  margin-left: 12px;
}

.layerName {
  flex: 1;
  min-width: 0;
  padding-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layerNameInput {
  flex: 1;
  min-width: 0;
}

/* The three columns at the right of a row: visible, locked, outlines. */
.layerFlag {
  flex: none;
  width: 22px;
  height: 22px;
  color: var(--color-text-dim);
}

.layerFlag:hover,
.layerFlag.on {
  color: var(--color-text);
}

/* The outline column: a square in the outline color of the layer. Filled
   while the layer shows normally, hollow while it shows as outlines. */
.layerOutline {
  --outline-color: #4f80ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.layerOutline span {
  width: 10px;
  height: 13px;
  background: var(--outline-color);
  border: 2px solid var(--outline-color);
  border-radius: 1px;
}

.layerOutline.on span {
  background: transparent;
}
