/* JayBoard shared widget primitives — built on the tokens in theme.css. Loaded by both pages
   (index.html + board.html) after theme.css and before the page-specific stylesheet, so page CSS can
   still override where it must. One definition each for buttons, fields, menus, chips, and segmented
   controls, so a widget looks the same on the gallery and the board.

   Conventions: BEM-ish — .block, .block--variant (modifier), .block__part. */

/* ---------- button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: 600 var(--fs) var(--font);
  white-space: nowrap;
  text-decoration: none; /* so an <a class="btn"> reads as a button, not a link */
  cursor: pointer;
}
.btn:hover {
  border-color: var(--accent);
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn .ic {
  width: 15px;
  height: 15px;
}
/* Bare glyph — no chrome until hover (e.g. toolbar icon buttons). Declared BEFORE the fill modifiers so
   an icon button that's also --primary/--danger still gets its fill (equal specificity, later wins). */
.btn--icon {
  padding: 0 9px;
  background: none;
  border-color: transparent;
  color: var(--muted);
}
.btn--icon:hover {
  background: var(--panel-2);
  border-color: transparent;
  color: var(--text);
}
/* Accent-filled primary action. */
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- field (text input / textarea) ---------- */
.field {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: var(--fs) var(--font);
  transition: border-color 0.12s ease;
}
.field::placeholder {
  color: var(--muted);
}
.field:focus,
.field:focus-within {
  border-color: var(--accent);
  outline: none;
}
textarea.field {
  resize: vertical;
}
select.field {
  cursor: pointer;
}

/* ---------- menu (portalled dropdown; the caller sets left/top/width inline via getBoundingClientRect) ---------- */
.menu {
  position: fixed;
  z-index: 9999;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--border) transparent;
}
/* A slim, rounded, inset thumb with a transparent track — and no up/down arrow buttons. */
.menu::-webkit-scrollbar {
  width: 11px;
}
.menu::-webkit-scrollbar-track {
  background: transparent;
}
.menu::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: padding-box;
}
.menu::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
  background-clip: padding-box;
}
.menu::-webkit-scrollbar-button {
  display: none;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs);
  color: var(--text);
  cursor: pointer;
}
.menu-item.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- chip (rounded pill; tag pills tint themselves via an inline style) ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  line-height: 1.45;
}

/* ---------- segmented control (butted cells in one rounded, bordered unit) ---------- */
.segmented {
  display: inline-flex;
  align-items: stretch;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius); /* rounded-rect by default; pill variants override to --radius-pill */
  overflow: hidden;
}
.segmented__opt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s ease;
}
.segmented__opt:hover {
  color: var(--text);
}
/* The end options carry the container's rounding themselves, at ALL times. Visually this is a no-op —
   .segmented already clips them to exactly this shape with overflow:hidden — but an outline follows the
   element's OWN radius, so without it the focus ring below would be a rectangle inside a pill. Setting
   it on :focus-visible instead made the option square at rest and round on focus, which reshaped the
   filled AND/OR pill the moment it was tabbed to. */
.segmented__opt:first-child {
  border-top-left-radius: inherit;
  border-bottom-left-radius: inherit;
}
.segmented__opt:last-child {
  border-top-right-radius: inherit;
  border-bottom-right-radius: inherit;
}
/* Tabbing to one of these has to show a ring, and it has to be an INSET one. .segmented clips to its own
   border-radius (overflow:hidden, so the options' backgrounds follow the rounded ends), and a ring drawn
   outside the option — the --focus-ring box-shadow every other control here uses, or the browser's own
   outline — is clipped by exactly that: it survives along the straight edges and is cut away at the
   rounded corners. Drawn inside the option's own box, there is nothing to clip. Solid rather than the
   45% blend, since it now sits on top of the option's fill. */
.segmented__opt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* A SELECTED option is filled, and an accent ring inside an accent fill is one blue on another — a ring
   you can compute but not see. currentColor rather than a literal white, because "selected" is not one
   colour here: the default and the AND/OR pill fill solid and set white text, so this gives white; the
   kind chips fill with an 18% tint and keep accent text, so it gives accent. Whatever the option's own
   label reads against, the ring reads against too. */
.segmented__opt.active:focus-visible {
  outline-color: currentColor;
}
.segmented__opt + .segmented__opt {
  border-left: 1px solid var(--border);
}
.segmented__opt.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- fast custom tooltip (replaces the slow native title) — see tooltip.ts ---------- */
.jb-tip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  width: max-content;
  max-width: 260px;
  padding: 4px 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: var(--fs-sm) / 1.35 var(--font);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
