/* popover.css (B5b): the explanation and entry popovers (public/js/popover.js,
 * .cs-pop-*) and the add-effect editor (public/js/views/effect-editor.js,
 * .cs-fx-*), plus the Features chip for a feature automated by hand.
 * Kit's Clean tokens only; every transition names a --duration and an
 * --ease token. A popover is a modal <dialog> in the top layer, outside the
 * sheet, placed by popover.js with a transform from the top-left corner, so
 * its targets are 44 px everywhere. */

/* ---- the dialog ---- */
.cs-pop {
  position: fixed; inset: 0 auto auto 0; margin: 0; padding: 0;
  width: min(22rem, calc(100vw - 16px)); max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px);
  box-sizing: border-box; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text);
  box-shadow: var(--shadow-3);
  /* Placed, not moved: reduced motion's 0.01ms on every property would
     otherwise show the old place for a frame. */
  transition: none;
}
.cs-pop::backdrop { background: var(--scrim); }
.cs-pop.is-explain { width: min(22rem, calc(100vw - 16px)); }
.cs-pop.is-entry { width: min(30rem, calc(100vw - 16px)); }
.cs-pop.cs-fx { width: min(36rem, calc(100vw - 16px)); }
.cs-pop-in { display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 14px 16px 16px; }

.cs-pop-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cs-pop-title { flex: 1; min-width: 0; margin: 0; font-size: var(--text-lg); font-weight: 600; overflow-wrap: anywhere; }
.cs-pop-h { margin: 4px 0 0; font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.cs-pop-note, .cs-pop-source { margin: 0; font-size: var(--text-sm); color: var(--text-muted); overflow-wrap: anywhere; }

/* ---- the explanation: parts, total, override ---- */
.cs-pop-parts { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.cs-pop-parts.is-alt { border-top-style: dashed; }
.cs-pop-part, .cs-pop-alt, .cs-pop-total {
  display: flex; align-items: baseline; gap: 12px; min-width: 0; margin: 0; padding: 6px 0;
  border-bottom: 1px solid var(--border); font-size: var(--text-sm);
}
.cs-pop-total { border-bottom: 0; font-weight: 600; }
.cs-pop-what { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cs-pop-amt, .cs-pop-val { flex: none; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.cs-pop-over {
  display: flex; align-items: center; gap: 8px; margin: 0; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-soft-text); font-size: var(--text-sm); overflow-wrap: anywhere;
}
.cs-pop-mark { flex: none; }
.cs-pop-form { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.cs-pop-label { font-size: var(--text-sm); font-weight: 600; }
.cs-pop-input, .cs-fx-input {
  width: 100%; min-height: 44px; padding: 6px 10px; box-sizing: border-box; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit;
}
.cs-pop-input[aria-invalid="true"] { border-color: var(--danger); }
.cs-pop-error {
  margin: 0; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger-soft-text); font-size: var(--text-sm); overflow-wrap: anywhere;
}
.cs-pop-error[hidden] { display: none; }

/* ---- the entry: the rules text ---- */
.cs-pop-text { min-width: 0; font-size: var(--text-sm); overflow-wrap: break-word; }
.cs-pop-text .sc-table { max-width: 100%; }

/* ---- buttons ---- */
.cs-pop-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.cs-pop-btn {
  min-width: 44px; min-height: 44px; padding: 6px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-sm); cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.cs-pop-btn.is-primary { border-color: transparent; background: var(--accent); color: var(--accent-text); }
@media (hover: hover) { .cs-pop-btn:not(.is-primary):hover { background: var(--surface-alt); } }
.cs-pop-x, .cs-fx-rm { flex: none; padding: 0; border-color: transparent; background: none; color: var(--text-muted); }
.cs-pop-btn:focus-visible, .cs-pop-input:focus-visible, .cs-fx-input:focus-visible,
.cs-fx-check input:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---- the add-effect editor ---- */
.cs-fx-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.cs-fx-item { display: flex; align-items: center; gap: 8px; min-width: 0; border-bottom: 1px solid var(--border); }
.cs-fx-sum { flex: 1; min-width: 0; font-size: var(--text-sm); overflow-wrap: anywhere; }
.cs-fx-form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.cs-fx-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 10px; min-width: 0; }
.cs-fx-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
/* The fields that follow a select (amountFrom, category), updated in place
 * when it changes (FB-F2, R-1): their fields are the grid's own items. */
.cs-fx-dep { display: contents; }
.cs-fx-k { font-size: var(--text-sm); font-weight: 600; }
.cs-fx-group { grid-column: 1 / -1; min-width: 0; margin: 0; padding: 0; border: 0; }
/* "Applies to" over its checkboxes: the legend's inset matches a check's 6 px. */
.cs-fx-group > .cs-fx-k { padding: 0 6px; }
.cs-fx-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr)); gap: 4px 8px; margin-top: 4px; }
.cs-fx-check {
  display: flex; align-items: center; gap: 8px; min-width: 44px; min-height: 44px; padding: 0 6px;
  border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; overflow-wrap: anywhere;
}
.cs-fx-check.is-wide { grid-column: 1 / -1; }
.cs-fx-check input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
@media (hover: hover) { .cs-fx-check:hover { background: var(--surface-alt); } }
.cs-fx-error { margin: 0; }

/* ---- Features: a feature automated by hand ---- */
.sc-chip.is-ok { background: var(--success-soft); color: var(--success-soft-text); border-color: transparent; white-space: normal; }

/* ---- Features: effects added by hand whose feature is gone (F-Pb) ---- */
.cs-fx-orphans { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); min-width: 0; }
.cs-fx-orphan-list { margin: 6px 0 0; padding: 0; list-style: none; }
.cs-fx-orphan { padding: 6px 0; border-top: 1px solid var(--border); min-width: 0; }
.cs-fx-orphan:first-child { border-top: 0; }
.cs-fx-orphan-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
.cs-fx-orphan-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.cs-fx-orphan-effects { margin: 4px 0 0; padding-left: 18px; font-size: var(--text-sm); color: var(--text-muted); overflow-wrap: anywhere; }
