/* =========================================================
   Toolbar component – styles
   Override any --tb-* variable on .tb (or a parent) to theme it.
   ========================================================= */
.tb {
  --tb-bg: transparent;
  --tb-section-bg: #ffffff;
  --tb-border: transparent;
  --tb-title: #5c5c5c;
  --tb-fg: #1f2630;
  --tb-btn-bg: #f4f6f8;
  --tb-btn-border: #d3d8df;
  --tb-hover: #e9edf2;
  --tb-active: #dce2ea;
  --tb-pressed-bg: #d7e6fb;
  --tb-pressed-fg: #1554b8;
  --tb-focus: #2f6fd6;
  --tb-radius: 6px;
  --tb-btn-size: 48px;
  --tb-gap: 4px;
  --tb-chevron-w: 22px;

  display: flex;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
  padding: 6px;
  overflow: hidden;
  background: var(--tb-bg);
  border: 1px solid var(--tb-border);
  border-radius: 8px;
  color: var(--tb-fg);
  font: inherit;
  font-size: 12pt;
}

@media (prefers-color-scheme: dark) {
  .tb:not([data-theme="light"]) {
    --tb-bg: transparent;
    --tb-section-bg: #23272e;
    --tb-border: transparent;
    --tb-title: #9aa3b0;
    --tb-fg: #e6e9ee;
    --tb-btn-bg: #2a2f37;
    --tb-btn-border: #3d444f;
    --tb-hover: #2e333c;
    --tb-active: #383e49;
    --tb-pressed-bg: #1f3a63;
    --tb-pressed-fg: #a9cbff;
    --tb-focus: #6ea2ff;
  }
}
.tb[data-theme="dark"] {
    --tb-bg: transparent;
    --tb-section-bg: #252525;
    --tb-border: transparent;
    --tb-title: #9aa3b0;
    --tb-fg: #e6e9ee;
    --tb-btn-bg: #181818;
    --tb-btn-border: #898989;
    --tb-hover: #52555c;
    --tb-active: #383e49;
    --tb-pressed-bg: #1f3a63;
    --tb-pressed-fg: #a9cbff;
    --tb-focus: #6ea2ff;
}

/* ---------- Show / hide (slide down from its own position) ---------- */
.tb-wrap {
  --tb-slide-duration: 250ms;
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--tb-slide-duration) ease;
}
.tb-clip {
  min-height: 0;
  overflow: hidden;
}
.tb-wrap .tb {
  transition:
    transform var(--tb-slide-duration) ease,
    opacity var(--tb-slide-duration) ease;
}
.tb-wrap.is-collapsed { grid-template-rows: 0fr; }
.tb-wrap.is-collapsed .tb {
  transform: translateY(-100%);
  opacity: 0;
}

/* ---------- Sections ---------- */
.tb-section {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;               /* sections shrink when space runs out */
  min-width: calc(var(--tb-btn-size) + 2 * var(--tb-chevron-w) + 10px);
  padding: 8px;
  background: var(--tb-section-bg);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
}
.tb-title {
  padding: 0 4px 4px;
  overflow: hidden;
  color: var(--tb-title);
  font-size: 0.8em;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tb-body {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.tb-viewport {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scrollbar-width: none;
}
.tb-viewport::-webkit-scrollbar { display: none; }
.tb-track {
  display: flex;
  gap: var(--tb-gap);
  width: max-content;
}

/* ---------- Buttons ---------- */
.tb-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--tb-btn-size);
  min-width: var(--tb-btn-size);
  padding: 0 10px;
  border: 2px solid var(--tb-btn-border);
  border-radius: var(--tb-radius);
  background: var(--tb-btn-bg);
  color: inherit;
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  font-size: 17px;
}
.tb-btn--icon { width: var(--tb-btn-size); padding: 0; }   /* square */
.tb-btn svg { width: 24px; height: 24px; flex: none; }
.tb-btn:hover:not(:disabled) {
  background: var(--tb-hover);
  border-color: color-mix(in srgb, var(--tb-btn-border) 70%, var(--tb-fg));
}
.tb-btn:active { background: var(--tb-active); }
.tb-btn[aria-pressed="true"] {
  background: var(--tb-pressed-bg);
  color: var(--tb-pressed-fg);
  border-color: color-mix(in srgb, var(--tb-pressed-fg) 30%, transparent);
}
.tb-btn:disabled {
  opacity: .4;
  cursor: default;
}
.tb-btn:focus-visible,
.tb-chevron:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: -2px;
}

/* ---------- Chevrons ---------- */
.tb-chevron {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--tb-chevron-w);
  height: var(--tb-btn-size);
  padding: 0;
  border: 0;
  border-radius: var(--tb-radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.tb-chevron svg { width: 16px; height: 16px; }
.tb-chevron:hover:not(:disabled) { background: var(--tb-hover); }
.tb-chevron:disabled { opacity: .25; cursor: default; }
.tb-section.is-overflowing .tb-chevron { display: inline-flex; }

/* ---------- Colored sections (section option: color) ----------
   Everything is derived from --tb-accent, set by the component.
   Works in light and dark mode because it mixes with the theme colors. */
.tb-section.tb-section--colored {
  background: color-mix(in srgb, var(--tb-accent) 6%, var(--tb-section-bg));
  border-color: color-mix(in srgb, var(--tb-accent) 35%, var(--tb-border));
}
.tb-section--colored .tb-title {
  color: color-mix(in srgb, var(--tb-accent) 80%, var(--tb-fg));
}
.tb-section--colored .tb-btn {
  background: color-mix(in srgb, var(--tb-accent) 10%, var(--tb-btn-bg));
  border-color: color-mix(in srgb, var(--tb-accent) 35%, var(--tb-btn-border));
  --tb-focus: var(--tb-accent);
}
.tb-section--colored .tb-btn svg {
  color: color-mix(in srgb, var(--tb-accent) 85%, var(--tb-fg));
}
.tb-section--colored .tb-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--tb-accent) 20%, var(--tb-btn-bg));
  border-color: color-mix(in srgb, var(--tb-accent) 60%, var(--tb-btn-border));
}
.tb-section--colored .tb-btn:active:not(:disabled) {
  background: color-mix(in srgb, var(--tb-accent) 28%, var(--tb-btn-bg));
}
.tb-section--colored .tb-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--tb-accent) 25%, var(--tb-btn-bg));
  border-color: var(--tb-accent);
  color: color-mix(in srgb, var(--tb-accent) 75%, var(--tb-fg));
}
.tb-section--colored .tb-chevron:hover:not(:disabled) {
  background: color-mix(in srgb, var(--tb-accent) 15%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .tb-viewport { scroll-behavior: auto; }
  .tb-wrap, .tb-wrap .tb { transition: none; }
}
