/* ============================================================================
   BlockGraf UI — shared design system
   Use these tokens and .bgf-* classes for any new modal or common UI so the app
   stays consistent. See DESIGN.md for the rules.

   Theme: dark surfaces, gray delimiters, single accent #0072e6, Inter font.
   No emojis in the UI — use Font Awesome icons instead.
   ============================================================================ */

:root {
  /* Accent (the app's characteristic blue) */
  --bgf-accent: #0072e6;        /* white text 4.6:1 */
  --bgf-accent-hover: #0066cc;  /* darker, not lighter: white text 5.6:1 */
  --bgf-accent-press: #005bb8;
  --bgf-accent-soft: rgba(0, 114, 230, 0.12);
  --bgf-on-accent: #ffffff;     /* text and icons on accent and status fills */
  --bgf-accent-text: #7ab8ff;   /* accent-colored text on dark surfaces: 9.3:1 (the accent itself is 4.2:1) */

  /* BlockWorld identity (the yellow of profile blockworld cards) */
  --bgf-world-accent: #f1c40f;

  /* Video blockset identity (its BlockWorld card); white text 4.9:1 at the lighter end */
  --bgf-type-video: #d0353b;
  --bgf-type-video-strong: #a8282e;

  /* Dark surfaces — near-black modals (matches the Edit Button essence) */
  --bgf-bg: #000000;          /* deepest: page background, insets, panels (pure black) */
  --bgf-surface: #0e0e10;     /* modal surface (reads black) */
  --bgf-surface-2: #1c1c1f;   /* elevated: inputs, chips, hover, bubbles */

  /* Gray delimiters */
  --bgf-border: #33373d;
  --bgf-border-strong: #454a52;

  /* Text */
  --bgf-text: #e7e9ec;
  --bgf-text-muted: #9aa1aa;
  --bgf-text-dim: #6b727b;

  --bgf-text-placeholder: #8a919a;  /* 5.3:1 on --bgf-surface-2; --bgf-text-dim is 3.5:1 */

  /* Focus: one indicator for every control (4.2:1 against --bgf-surface) */
  --bgf-focus-ring: 2px solid var(--bgf-accent);
  --bgf-focus-offset: 2px;

  /* Status. The plain value is for text and icons on dark surfaces, -soft for
     tinted backgrounds, --bgf-danger-strong for filled buttons with white text. */
  --bgf-danger: #f87171;
  --bgf-danger-strong: #c62828;       /* white text 5.6:1 */
  --bgf-danger-strong-hover: #b71c1c; /* white text 6.6:1 */
  --bgf-danger-soft: rgba(248, 113, 113, 0.14);
  --bgf-success: #4ade80;
  --bgf-success-soft: rgba(74, 222, 128, 0.14);
  --bgf-warning: #fbbf24;
  --bgf-warning-soft: rgba(251, 191, 36, 0.14);

  /* QR codes: dark modules on a light field in every theme (inverted codes
     scan poorly), with the field as the quiet zone. */
  --bgf-qr-ink: #000000;
  --bgf-qr-paper: #ffffff;

  /* Shape & type */
  --bgf-radius: 12px;
  --bgf-radius-sm: 8px;
  --bgf-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  --bgf-overlay: rgba(0, 0, 0, 0.66);  /* backdrop behind dialogs */
  --bgf-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Type scale: UI text never goes below --bgf-text-xs */
  --bgf-text-xs: 12px;
  --bgf-text-sm: 13px;
  --bgf-text-md: 14px;
  --bgf-text-lg: 16px;

  /* Spacing scale */
  --bgf-space-1: 4px;
  --bgf-space-2: 8px;
  --bgf-space-3: 12px;
  --bgf-space-4: 16px;
  --bgf-space-5: 24px;
  --bgf-space-6: 32px;

  /* Control heights: desktop and touch targets */
  --bgf-control-h: 32px;
  --bgf-control-h-touch: 44px;

  /* Motion */
  --bgf-duration: 150ms;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --bgf-duration: 0ms;
  }
}

/* ---- Modal overlay + dialog -------------------------------------------- */
.bgf-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bgf-overlay);
  z-index: 10000;
  font-family: var(--bgf-font);
}
.bgf-modal.is-open {
  display: flex;
}

.bgf-modal__dialog {
  display: flex;
  flex-direction: column;
  width: 92%;
  max-width: 720px;
  max-height: 88vh;
  overflow: hidden;
  background: var(--bgf-surface);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius);
  box-shadow: var(--bgf-shadow);
  color: var(--bgf-text);
}

.bgf-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--bgf-border);
}
.bgf-modal__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--bgf-text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.bgf-modal__title i {
  color: var(--bgf-accent);
  font-size: 1rem;
}
.bgf-modal__close {
  padding: 6px 8px;
  background: none;
  border: none;
  color: var(--bgf-text-muted);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.bgf-modal__close:hover {
  color: var(--bgf-text);
  background: var(--bgf-surface-2);
}

.bgf-modal__body {
  padding: 20px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--bgf-text);
}
.bgf-modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap; /* never let buttons overflow narrow dialogs */
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--bgf-border);
}

/* ---- Buttons ----------------------------------------------------------- */
.bgf-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  font-family: var(--bgf-font);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--bgf-radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.bgf-btn--primary {
  background: var(--bgf-accent);
  color: var(--bgf-on-accent);
}
.bgf-btn--primary:hover {
  background: var(--bgf-accent-hover);
}
.bgf-btn--primary:active {
  background: var(--bgf-accent-press);
}
.bgf-btn--secondary {
  background: transparent;
  color: var(--bgf-text-muted);
  border-color: var(--bgf-border-strong);
}
.bgf-btn--danger {
  background: var(--bgf-danger-strong);
  color: var(--bgf-on-accent);
}
.bgf-btn--danger:hover {
  background: var(--bgf-danger-strong-hover);
}
.bgf-btn--secondary:hover {
  color: var(--bgf-text);
  border-color: var(--bgf-text-muted);
}
.bgf-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Segmented toggle (e.g. language selector) ------------------------- */
.bgf-toggle {
  display: inline-flex;
  gap: 8px;
}
.bgf-toggle__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: var(--bgf-font);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--bgf-text-muted);
  background: transparent;
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.bgf-toggle__btn:hover {
  color: var(--bgf-text);
  border-color: var(--bgf-accent);
}
.bgf-toggle__btn.is-active {
  color: var(--bgf-on-accent);
  background: var(--bgf-accent);
  border-color: var(--bgf-accent);
}
/* Language menu (page footers): globe button that opens the list upwards */
.bgf-language-menu {
  position: relative;
  display: inline-block;
}
.bgf-language-menu__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--bgf-space-2);
  min-height: var(--bgf-control-h);
  padding: 0 var(--bgf-space-3);
  font-family: var(--bgf-font);
  font-size: var(--bgf-text-sm);
  font-weight: 600;
  color: var(--bgf-text);
  background: var(--bgf-surface-2);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
  cursor: pointer;
}
.bgf-language-menu__trigger:hover {
  border-color: var(--bgf-border-strong);
}
.bgf-language-menu__icon {
  flex: none;
}
.bgf-language-menu__chevron {
  color: var(--bgf-text-muted);
}
.bgf-language-menu__list {
  position: absolute;
  right: 0;
  bottom: calc(100% + var(--bgf-space-1));
  z-index: 20;
  display: none;
  flex-direction: column;
  min-width: 100%;
  padding: var(--bgf-space-1);
  background: var(--bgf-surface);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
  box-shadow: var(--bgf-shadow);
  opacity: 0;
  transition: opacity var(--bgf-duration), display var(--bgf-duration) allow-discrete;
}
.bgf-language-menu__list.is-open {
  display: flex;
  opacity: 1;
}
@starting-style {
  .bgf-language-menu__list.is-open { opacity: 0; }
}
.bgf-language-menu__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bgf-space-4);
  padding: var(--bgf-space-2) var(--bgf-space-3);
  font-family: var(--bgf-font);
  font-size: var(--bgf-text-sm);
  color: var(--bgf-text);
  text-align: left;
  white-space: nowrap;
  background: transparent;
  border: 0;
  border-radius: var(--bgf-radius-sm);
  cursor: pointer;
}
.bgf-language-menu__option:hover {
  background: var(--bgf-surface-2);
}
.bgf-language-menu__option[aria-pressed="true"] .bgf-language-menu__icon {
  color: var(--bgf-accent-text);
}
.bgf-language-menu__trigger:focus-visible,
.bgf-language-menu__option:focus-visible {
  outline: var(--bgf-focus-ring);
  outline-offset: var(--bgf-focus-offset);
}

/* ---- Inset panel (content surface inside a modal) ---------------------- */
/* Keep borders even/gray on all sides — no accent "stripe" on one edge. */
.bgf-panel {
  padding: 16px 18px;
  background: var(--bgf-bg);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
}

/* ---- Text input -------------------------------------------------------- */
.bgf-input {
  width: 100%;
  box-sizing: border-box; /* keep padding inside the modal body width */
  padding: 11px 14px;
  font-family: var(--bgf-font);
  font-size: 0.95rem;
  color: var(--bgf-text);
  background: var(--bgf-surface-2);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.bgf-input:focus {
  border-color: var(--bgf-accent);
  box-shadow: 0 0 0 3px var(--bgf-accent-soft);
}
.bgf-input::placeholder {
  color: var(--bgf-text-placeholder);
}
/* Browser autofill paints inputs light blue; keep the field on the system
   surface. Autofill styles cannot be overridden directly, so an inset shadow
   covers the background and the text color is forced. */
.bgf-input:-webkit-autofill,
.bgf-input:-webkit-autofill:hover {
  -webkit-text-fill-color: var(--bgf-text);
  caret-color: var(--bgf-text);
  box-shadow: 0 0 0 1000px var(--bgf-surface-2) inset;
}
.bgf-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--bgf-text);
  box-shadow: 0 0 0 1000px var(--bgf-surface-2) inset, 0 0 0 3px var(--bgf-accent-soft);
}

/* ---- Bootstrap modal skin ---------------------------------------------
   For template modals that use Bootstrap's markup/JS: add the class
   "bgf-bs-modal" to the .modal to give it the BlockGraf look without changing
   the markup or the Bootstrap show/hide behavior. */
.bgf-bs-modal .modal-content {
  background: var(--bgf-surface);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius);
  color: var(--bgf-text);
  font-family: var(--bgf-font);
}
.bgf-bs-modal .modal-header,
.bgf-bs-modal .modal-footer {
  border-color: var(--bgf-border);
}
.bgf-bs-modal .modal-title {
  color: var(--bgf-text);
  font-weight: 600;
}
.bgf-bs-modal .btn-close {
  filter: invert(1) grayscale(1) brightness(1.4);
  opacity: 0.7;
}
.bgf-bs-modal .btn-close:hover {
  opacity: 1;
}
.bgf-bs-modal .col-form-label,
.bgf-bs-modal label {
  color: var(--bgf-text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.bgf-bs-modal .form-control {
  background: var(--bgf-surface-2);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
  color: var(--bgf-text);
}
.bgf-bs-modal .form-control:focus {
  background: var(--bgf-surface-2);
  border-color: var(--bgf-accent);
  box-shadow: 0 0 0 3px var(--bgf-accent-soft);
  color: var(--bgf-text);
}
.bgf-bs-modal .form-control::placeholder {
  color: var(--bgf-text-placeholder);
}
.bgf-bs-modal .btn-primary {
  background: var(--bgf-accent);
  border-color: var(--bgf-accent);
}
.bgf-bs-modal .btn-primary:hover {
  background: var(--bgf-accent-hover);
  border-color: var(--bgf-accent-hover);
}
.bgf-bs-modal .btn-secondary {
  background: transparent;
  color: var(--bgf-text-muted);
  border-color: var(--bgf-border-strong);
}
.bgf-bs-modal .btn-secondary:hover {
  background: var(--bgf-surface-2);
  color: var(--bgf-text);
  border-color: var(--bgf-text-muted);
}

/* ---- Small caption (e.g. timing) --------------------------------------- */
.bgf-caption {
  font-size: 0.8rem;
  color: var(--bgf-text-muted);
  font-variant-numeric: tabular-nums;
}
.bgf-caption:empty {
  display: none;
}

/* ---- Scroll area: the one scrollbar look --------------------------------
   Every list or panel that scrolls inside the interface uses it: a slim gray
   pill on a clear track, no arrows (the look of the HTML blockset pages),
   never the operating system's default bar. */
.bgf-scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.bgf-scroll::-webkit-scrollbar-track,
.bgf-scroll::-webkit-scrollbar-corner {
  background: transparent;
}
.bgf-scroll::-webkit-scrollbar-button {
  display: none;
}
.bgf-scroll::-webkit-scrollbar-thumb {
  background-color: var(--bgf-text-dim);
  background-clip: padding-box;
  border: 3px solid transparent;
  border-radius: 999px;
}
.bgf-scroll::-webkit-scrollbar-thumb:hover {
  background-color: var(--bgf-text-muted);
}
/* Browsers without the pseudo-elements (Firefox) take the standard ones. */
@supports not selector(::-webkit-scrollbar) {
  .bgf-scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--bgf-text-dim) transparent;
  }
}

/* ---- Focus: one visible indicator for every shared control ------------- */
.bgf-btn:focus-visible,
.bgf-toggle__btn:focus-visible,
.bgf-modal__close:focus-visible,
.bgf-bs-modal .btn:focus-visible,
.bgf-bs-modal .btn-close:focus-visible {
  outline: var(--bgf-focus-ring);
  outline-offset: var(--bgf-focus-offset);
  box-shadow: none;
}
.bgf-modal__dialog:focus {
  outline: none;
}

/* ---- Toast (static/js/ui/toast.js) -------------------------------------
   Bottom-center, above the chrome bars: never over the BlockSet frame or its
   navigation buttons. A page with a taller bottom bar sets --bgf-toast-bottom. */
.bgf-toast {
  position: fixed;
  left: 50%;
  bottom: var(--bgf-toast-bottom, 64px);
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: var(--bgf-space-2);
  max-width: min(70vw, 420px);
  padding: var(--bgf-space-2) var(--bgf-space-4);
  background: var(--bgf-surface-2);
  border: 1px solid var(--bgf-border-strong);
  border-radius: var(--bgf-radius-sm);
  box-shadow: var(--bgf-shadow);
  color: var(--bgf-text);
  font-family: var(--bgf-font);
  font-size: var(--bgf-text-sm);
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, var(--bgf-space-3));
  transition: opacity var(--bgf-duration), transform var(--bgf-duration);
}
.bgf-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.bgf-toast i {
  flex-shrink: 0;
  color: var(--bgf-accent);
}
.bgf-toast[data-variant="success"] i {
  color: var(--bgf-success);
}
.bgf-toast[data-variant="error"] {
  border-color: var(--bgf-danger);
}
.bgf-toast[data-variant="error"] i {
  color: var(--bgf-danger);
}

/* ---- Save status (static/js/ui/saveStatus.js) -------------------------
   Lives in a chrome bar next to what is being edited. On narrow screens the
   label is visually hidden (still announced); the icon and Retry stay. */
.bgf-save-status {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--bgf-space-1);
  margin: 0 var(--bgf-space-2);
  color: var(--bgf-text-muted);
  font-family: var(--bgf-font);
  font-size: var(--bgf-text-xs);
  white-space: nowrap;
}
.bgf-save-status[hidden] {
  display: none;
}
.bgf-save-status.is-fading {
  opacity: 0;
  transition: opacity 400ms ease; /* saveStatus.js FADE_MS */
}
.bgf-save-status__icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 13px;
}
.bgf-save-status[data-state="pending"] .bgf-save-status__icon {
  color: var(--bgf-warning);
  transform: scale(0.5);
}
.bgf-save-status[data-state="saving"] .bgf-save-status__icon {
  color: var(--bgf-text-muted);
  animation: bgf-save-spin 0.9s linear infinite;
}
.bgf-save-status[data-state="saved"] .bgf-save-status__icon {
  color: var(--bgf-success);
}
.bgf-save-status[data-state="failed"] {
  color: var(--bgf-danger);
}
@keyframes bgf-save-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .bgf-save-status[data-state="saving"] .bgf-save-status__icon {
    animation: none;
  }
  .bgf-save-status.is-fading {
    transition: none;
  }
}
/* Quiet states are icon-only; their words stay for screen readers and the
   tooltip. A failure keeps its words visible. */
.bgf-save-status:not([data-state="failed"]) .bgf-save-status__text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.bgf-save-status__retry {
  min-height: 24px;
  padding: 0 var(--bgf-space-2);
  background: transparent;
  border: 1px solid var(--bgf-danger);
  border-radius: var(--bgf-radius-sm);
  color: var(--bgf-text);
  font: inherit;
  cursor: pointer;
}
.bgf-save-status__retry:hover {
  background: var(--bgf-danger-soft);
}
.bgf-save-status__retry:focus-visible {
  outline: var(--bgf-focus-ring);
  outline-offset: var(--bgf-focus-offset);
}
@media (max-width: 600px) {
  .bgf-save-status__text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Blockset type picker (static/js/ui/blocksetTypePicker.js) */
.bgf-type-picker {
  display: grid;
  gap: var(--bgf-space-3);
}
.bgf-type-picker__option {
  display: flex;
  align-items: center;
  gap: var(--bgf-space-4);
  width: 100%;
  padding: var(--bgf-space-3) var(--bgf-space-4);
  background: var(--bgf-surface-2);
  border: 1px solid var(--bgf-border);
  border-radius: var(--bgf-radius);
  color: var(--bgf-text);
  font-family: var(--bgf-font);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--bgf-duration), border-color var(--bgf-duration);
}
.bgf-type-picker__option:hover {
  background: var(--bgf-accent-soft);
  border-color: var(--bgf-accent);
}
.bgf-type-picker__option:focus-visible {
  outline: var(--bgf-focus-ring);
  outline-offset: var(--bgf-focus-offset);
}
.bgf-type-picker__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  background: var(--bgf-border);
  border-radius: var(--bgf-radius-sm);
  font-size: var(--bgf-text-md);
}
.bgf-type-picker__copy {
  display: flex;
  flex-direction: column;
  gap: var(--bgf-space-1);
}
.bgf-type-picker__copy strong {
  font-size: var(--bgf-text-sm);
  font-weight: 600;
}
.bgf-type-picker__copy span {
  color: var(--bgf-text-muted);
  font-size: var(--bgf-text-xs);
}
