/* components/composer-plus/plus.css — [CPX5 inline-pills-v5]
   Composer toolbar layout:
   1. Pin Icon Button (#cplus-pinbtn) -> compact dropdown popover for attachments
   2. + Button (#plusbtn) -> count badge, toggles tool pills
   3. Inline Tools Pills (Search the web, Analyse my data, A logged-in site, This computer)
   - Mathematically balanced sizing to fill the composer bar (~820px) without scrolling or large gaps.
   - Dark mode: LIME for active pills/switches/badges (--success).
   - Light mode: BLUE for active pills/switches/badges (--accent).
*/

#composer {
  /* Dark mode palette: LIME */
  --cplus-on: var(--success);
  --cplus-on-fill: var(--success-tint);
  --cplus-on-border: var(--success-tint-border);
  --cplus-on-text: var(--success-text);
  --cplus-on-ink: #0c0e13;
}

:root[data-theme="light"] #composer {
  /* Light mode palette: BLUE */
  --cplus-on: var(--accent);
  --cplus-on-fill: var(--selected-fill);
  --cplus-on-border: var(--selected-border);
  --cplus-on-text: var(--tb-accent-text, var(--accent));
  --cplus-on-ink: #ffffff;
}

#composer #cplus-badge[hidden],
#composer #cplus-attach-badge[hidden],
#composer .cplus-attach-pop[hidden] {
  display: none !important;
}

/* ---- Compose Toolbar Layout --------------------------------------------- */
#composebar {
  position: relative;
  width: 100%;
  max-width: 880px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  box-sizing: border-box;
}

#composebar .compose-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
}

/* ---- Pin Button & Attachment Popover ------------------------------------- */
.cplus-pin-wrap {
  position: relative;
  flex: 0 0 28px;
}

#composer #cplus-pinbtn {
  position: relative;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
  z-index: 2;
}

#composer #cplus-pinbtn:hover,
#composer #cplus-pinbtn[aria-expanded="true"] {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-2);
}

#composer #cplus-pinbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#composer #cplus-pinbtn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#composer #cplus-attach-badge {
  position: absolute;
  top: -6px;
  right: -7px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--cplus-on);
  color: var(--cplus-on-ink);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: none;
  z-index: 3;
}

/* Attach Popover */
.cplus-attach-pop {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 70;
  width: max-content;
  min-width: 250px;
  max-width: 320px;
  box-sizing: border-box;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel, #1d2028);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-card, 8px);
  box-shadow: var(--shadow-pop, 0 8px 24px rgba(0, 0, 0, 0.45));
}

#composer #composebar .cplus-attach-pop .cplus-pop-opt,
#composer #composebar .cplus-attach-pop #attachbtn,
#composer #composebar .cplus-attach-pop #attachfolderbtn {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 10px !important;
  width: 100% !important;
  height: auto !important;
  min-height: 46px !important;
  box-sizing: border-box !important;
  padding: 8px 10px !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: var(--radius-input, 6px) !important;
  background: transparent !important;
  color: var(--text) !important;
  font-family: inherit !important;
  text-align: left !important;
  cursor: pointer !important;
  transition: background 120ms ease !important;
}

#composer #composebar .cplus-attach-pop .cplus-pop-opt:hover,
#composer #composebar .cplus-attach-pop #attachbtn:hover,
#composer #composebar .cplus-attach-pop #attachfolderbtn:hover {
  background: var(--surface-2) !important;
}

#composer #composebar .cplus-attach-pop .cplus-pop-opt:focus-visible,
#composer #composebar .cplus-attach-pop #attachbtn:focus-visible,
#composer #composebar .cplus-attach-pop #attachfolderbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.cplus-pop-opt .cplus-ico {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--text-dim);
}

.cplus-pop-opt:hover .cplus-ico {
  color: var(--cplus-on);
}

.cplus-pop-opt-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  min-width: 0;
  flex: 1 1 auto;
}

.cplus-pop-opt-text b {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  white-space: nowrap;
}

.cplus-pop-opt-text span {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap;
}

/* ---- + Trigger Button ---------------------------------------------------- */
#composer #plusbtn {
  position: relative;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
  z-index: 2;
}

#composer #plusbtn:hover,
#composebar.pills-open #composer #plusbtn,
#composebar.pills-open #plusbtn {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-2);
}

#composer #plusbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#composer #plusbtn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* + rotates 45deg to become x when pills are open */
#composebar.pills-open #plusbtn svg {
  transform: rotate(45deg);
}

/* Badge showing count of active tools */
#composer #cplus-badge {
  position: absolute;
  top: -6px;
  right: -7px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--cplus-on);
  color: var(--cplus-on-ink);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: none;
  z-index: 3;
}

/* ---- Hint Text (Visible only when collapsed) ----------------------------- */
#composebar .compose-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 400;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 180ms ease, max-width 240ms ease;
}

#composebar.pills-open .compose-hint {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
  display: none;
}

#composebar.pills-collapsed .compose-hint {
  opacity: 1;
  max-width: 320px;
  display: inline;
}

/* ---- Inline Pills Container (Mathematically Balanced & Zero Scroll) ----- */
.cplus-pills {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  flex-wrap: nowrap;
  overflow: hidden !important;
  overflow-x: hidden !important;
  overflow-y: hidden !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
  transition: max-width 260ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 200ms ease,
              transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
}

.cplus-pills::-webkit-scrollbar {
  display: none !important;
}

#composebar.pills-open .cplus-pills {
  max-width: 720px;
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

#composebar.pills-collapsed .cplus-pills {
  max-width: 0;
  opacity: 0;
  transform: translateX(-12px);
  pointer-events: none;
  overflow: hidden !important;
  margin: 0;
  padding: 0;
}

/* ---- Individual Tool Pill Design (Balanced 28px height, 11.5px font) ----- */
.cplus-pill {
  position: relative;
  height: 28px;
  flex: 0 0 auto;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px 0 8px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: var(--surface-1, transparent);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 140ms ease,
              border-color 140ms ease,
              color 140ms ease,
              opacity 140ms ease;
}

.cplus-pill:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-2);
}

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

/* On / Active pill */
.cplus-pill.on {
  background: var(--cplus-on-fill);
  border-color: var(--cplus-on-border);
  color: var(--text);
}

.cplus-pill.on:hover {
  background: var(--cplus-on-fill);
  border-color: var(--cplus-on-border);
  filter: brightness(1.06);
}

/* Disabled pill */
.cplus-pill.disabled,
.cplus-pill.is-off {
  opacity: 0.52;
  cursor: pointer;
}

.cplus-pill.disabled:hover,
.cplus-pill.is-off:hover {
  opacity: 0.82;
  border-color: var(--border-hover);
}

/* Icon in pill */
.cplus-pill .cplus-ico {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--text-dim);
  transition: color 140ms ease;
}

.cplus-pill:hover .cplus-ico {
  color: var(--text);
}

.cplus-pill.on .cplus-ico {
  color: var(--cplus-on);
}

/* Pill Name */
.cplus-pill-name {
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1;
  color: inherit;
  white-space: nowrap;
}

/* ---- Mini Switch Inside Pill (Proportional 19x11.5px) --------------------- */
.cplus-pill-sw {
  position: relative;
  width: 19px;
  height: 11.5px;
  flex: 0 0 19px;
  margin-left: 1px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: var(--surface-3, var(--surface-2));
  box-sizing: border-box;
  pointer-events: none;
  transition: background 150ms ease, border-color 150ms ease;
}

.cplus-pill-sw::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 7.5px;
  height: 7.5px;
  border-radius: 50%;
  background: var(--text-muted);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1), background 150ms ease;
}

.cplus-pill.on .cplus-pill-sw {
  background: var(--cplus-on);
  border-color: var(--cplus-on);
}

.cplus-pill.on .cplus-pill-sw::after {
  transform: translateX(7.5px);
  background: var(--cplus-on-ink);
}

.cplus-pill.disabled .cplus-pill-sw,
.cplus-pill.is-off .cplus-pill-sw {
  opacity: 0.6;
}

/* ---- Body Floating Tooltip ----------------------------------------------- */
.cplus-tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  max-width: 290px;
  box-sizing: border-box;
  padding: 8px 11px;
  border-radius: var(--radius-card, 8px);
  background: var(--panel, #1d2028);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-pop, 0 8px 24px rgba(0, 0, 0, 0.35));
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.cplus-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.cplus-tooltip[hidden] {
  display: none !important;
}

.cplus-tooltip b {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.cplus-tooltip span {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.38;
}

.cplus-tooltip .cplus-tip-action {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  font-weight: 550;
  color: var(--cplus-on-text);
}

/* ---- Motion Accessibility ------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  #composer #plusbtn,
  #composer #plusbtn svg,
  #composer #cplus-pinbtn,
  .cplus-pills,
  .cplus-pill,
  .cplus-pill-sw,
  .cplus-pill-sw::after,
  .cplus-tooltip {
    transition: none !important;
  }
}
