/* The grid's right-click menu (js/context.js, drawn by js/menu.js
   openContextMenu), the text color palette (js/rowformat.js) and the small
   setup editors opened from the apply panel (js/apply.js, modal.js
   anchoredForm). Uses the app's :root tokens; placement comes from generated
   rules (.ctx-menu.placed, .popover.placed). */

/* ------------------------------------------------------------------------ */
/* Palette: each color has a light and a dark value, both 4.5:1 or better on
   the grid's backgrounds (selected rows included). The file stores the light
   value; in a dark window the grid shows the dark one. */

:root {
  --sw-red: #c03530;
  --sw-orange: #a8551c;
  --sw-gold: #836521;
  --sw-green: #1f7a36;
  --sw-teal: #1e7673;
  --sw-blue: #1d63c9;
  --sw-purple: #7c3fd1;
  --sw-pink: #b72e78;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sw-red: #ef8079;
    --sw-orange: #f08a45;
    --sw-gold: #d39b1f;
    --sw-green: #3fbf62;
    --sw-teal: #2fbfb8;
    --sw-blue: #6ca0e5;
    --sw-purple: #b58de2;
    --sw-pink: #e779b4;
  }

  /* Rows colored from the palette (tr.tc-<light value>, generated by grid.js). */
  .grid-host .grid tr.tc-c03530 { color: #ef8079; }
  .grid-host .grid tr.tc-a8551c { color: #f08a45; }
  .grid-host .grid tr.tc-836521 { color: #d39b1f; }
  .grid-host .grid tr.tc-1f7a36 { color: #3fbf62; }
  .grid-host .grid tr.tc-1e7673 { color: #2fbfb8; }
  .grid-host .grid tr.tc-1d63c9 { color: #6ca0e5; }
  .grid-host .grid tr.tc-7c3fd1 { color: #b58de2; }
  .grid-host .grid tr.tc-b72e78 { color: #e779b4; }
}

.sw-red { background: var(--sw-red); }
.sw-orange { background: var(--sw-orange); }
.sw-gold { background: var(--sw-gold); }
.sw-green { background: var(--sw-green); }
.sw-teal { background: var(--sw-teal); }
.sw-blue { background: var(--sw-blue); }
.sw-purple { background: var(--sw-purple); }
.sw-pink { background: var(--sw-pink); }

/* "No color": an empty chip with a slash. */
.sw-none {
  position: relative;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--text-muted);
  overflow: hidden;
}

.sw-none::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 1px solid var(--text-muted);
  transform: rotate(-45deg);
}

/* ------------------------------------------------------------------------ */
/* Context menu */

.ctx-menu {
  min-width: 220px;
}

/* Measured before it is placed; never drawn unplaced. */
.ctx-menu:not(.placed) {
  visibility: hidden;
}

.ctx-item .popup-label {
  flex: 1;
}

.ctx-key {
  flex: none;
  margin-left: 24px;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.ctx-more {
  flex: none;
  margin-left: 16px;
  color: var(--text-muted);
}

.ctx-item[aria-expanded="true"] {
  background: var(--row-hover);
}

.ctx-item.disabled {
  color: var(--text-muted);
  opacity: 0.6;
  cursor: default;
}

.ctx-item.disabled:hover {
  background: none;
}

.ctx-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

.ctx-swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* ------------------------------------------------------------------------ */
/* Small setup editors (modal.js anchoredForm): fields in a column, a swatch
   row for colors, a switch line. */

.popover.popover-form {
  width: 320px;
}

.popover-fields {
  display: grid;
  gap: 8px;
}

.popover-fields .modal-field {
  margin: 0;
}

/* A field hidden for now (a percent fringe has no "charged per"). */
.popover-fields > [hidden] {
  display: none;
}

.popover-adorned {
  display: flex;
  align-items: center;
  gap: 6px;
}

.popover-adorned .modal-input {
  flex: 1;
  min-width: 0;
}

.popover-adorn {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
}

/* A quiet line between fields (a flat fringe's unused cutoff). */
.popover-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.popover-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.popover-check input {
  margin: 0;
  accent-color: var(--accent);
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.swatch[aria-checked="true"] {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media print {
  .ctx-menu {
    display: none !important;
  }
}

/* A group color that isn't one of the palette's: kept unless another is picked. */
.sw-keep {
  background: linear-gradient(135deg, var(--text-muted) 0 50%, var(--surface) 50% 100%);
  box-shadow: inset 0 0 0 1px var(--text-muted);
}
