/* ==========================================================================
   Shared components
   Buttons, segmented control, switch, chips and menus — the same classes
   app.js/editor.js already target (see docs/redesign-notes.md). Loaded
   after tokens.css, before style.css, so these are the canonical rules for
   these selectors; style.css no longer defines them.
   ========================================================================== */

/* Buttons: .btn (recorder/dialogs) and .editor-btn (Video Editor) share one
   look — content-sized, icon + label, never stretched except the explicit
   .btn-small / .editor-btn-block full-width variants. */

.btn,
.editor-btn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--raised);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.editor-btn .icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn:hover:not(:disabled),
.editor-btn:hover:not(:disabled) {
  border-color: var(--text-2);
  background: var(--surface-sunken);
}

.btn:disabled,
.editor-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn:focus-visible,
.editor-btn:focus-visible,
.icon-btn:focus-visible,
.chip:focus-visible,
.segmented button:focus-visible,
.bg-item:focus-visible,
.corner-picker button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary,
.editor-btn-primary {
  min-height: 41px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled),
.editor-btn-primary:hover:not(:disabled) {
  border-color: var(--brand-hover);
  background: var(--brand-hover);
}

.btn-danger-ghost,
.editor-btn-danger-ghost {
  border-color: var(--danger-border);
  background: transparent;
  color: var(--danger-text);
}

.btn-danger-ghost:hover:not(:disabled),
.editor-btn-danger-ghost:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft-bg);
  color: var(--danger-text);
}

.btn-small {
  width: 100%;
  margin-top: 10px;
  padding: 7px 12px;
  font-size: 13px;
}

.btn-page {
  padding: 6px 12px;
  font-size: 16px;
  line-height: 1;
}

.editor-btn-block {
  width: 100%;
  justify-content: center;
}

#edInspectorBody > .editor-btn-block {
  margin-top: 16px;
}

/* Segmented control */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-1);
}

.segmented button {
  padding: 8px 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.segmented button[aria-checked="true"],
.segmented button[aria-selected="true"] {
  background: var(--border);
  color: var(--text);
  font-weight: 600;
}

/* Switch (native checkbox, restyled — no markup change) */

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  cursor: pointer;
}

.toggle input {
  appearance: none;
  position: relative;
  width: 40px;
  height: 24px;
  margin: 0;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  cursor: pointer;
  transition: background 0.15s ease;
}

.toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-ink);
  transition: transform 0.15s ease;
}

.toggle input:checked {
  background: var(--accent);
}

.toggle input:checked::after {
  transform: translateX(16px);
  background: var(--on-brand);
}

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

/* Chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-4);
  color: var(--text);
  cursor: pointer;
}

.chip[aria-pressed="true"],
.chip[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft-bg);
  color: var(--text);
}

/* Menus (Files / Tools dropdowns) */

.menu-bar {
  display: flex;
  gap: 4px;
}

.menu {
  position: relative;
}

.menu-trigger {
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.menu-trigger:hover {
  background: var(--surface-4);
}

.menu-trigger[aria-expanded="true"] {
  border-color: var(--border);
  background: var(--surface-4);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: 230px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-4);
  box-shadow: var(--shadow-popover);
  /* the Tools menu outgrew a laptop screen: scroll inside the menu instead of running off the bottom */
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.menu-dropdown-wide {
  width: 260px;
}

.menu-section-label {
  padding: 8px 12px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.menu-sep {
  margin: 6px 4px;
  border-top: 1px solid var(--border);
}

.menu-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: start;
  cursor: pointer;
  font-size: 14px;
}

.menu-item:hover {
  background: var(--raised);
}

.menu-item-stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.menu-item-sub {
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-mono);
}

.menu-item-check {
  position: relative;
  padding-inline-start: 32px;
}

.menu-item-check::before {
  content: "";
  position: absolute;
  inset-inline-start: 11px;
  top: 50%;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-1);
  transform: translateY(-50%);
}

.menu-item-check[aria-checked="true"]::before {
  border-color: var(--accent);
  background: var(--accent);
}

.menu-item-check[aria-checked="true"]::after {
  content: "";
  position: absolute;
  inset-inline-start: 15px;
  top: 50%;
  width: 4px;
  height: 8px;
  border-right: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: translateY(-65%) rotate(45deg);
}
