/* ============================================================================
   StoreBuild — Module Offcanvas (Concept theme)
   Scoped under #storebuild-admin-app so it uses the concept --c-* tokens and
   overrides any legacy .strb-offcanvas-* rules without !important.
   Every module shares the Offcanvas + Dropdown/Input/Switch/Radio components,
   so styling here upgrades all module panels at once.
   ========================================================================== */

#storebuild-admin-app {

  /* ── Drawer shell ─────────────────────────────────────────────────────── */
  .strb-offcanvas-area {
    position: fixed;
    top: 0; right: 0;
    height: 100%;
    width: 850px;
    max-width: 100vw;
    background: var(--c-bg);
    z-index: 9999;
    transform: translateX(calc(100% + 80px));
    visibility: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    box-shadow: -24px 0 60px -30px rgba(40, 33, 99, .4);

    &::-webkit-scrollbar { width: 8px; }
    &::-webkit-scrollbar-thumb { background: var(--c-line-2); border-radius: 8px; }

    // Transition only after first paint (RAF in JS) — prevents mount glitch.
    // visibility delays .42s on close so the panel hides after sliding out.
    &.strb-offcanvas-ready {
      transition: transform .42s cubic-bezier(.22, 1, .36, 1), visibility 0s .42s;
    }
    // When opening: both transform and visibility fire immediately (no delay).
    &.strb-offcanvas-opened {
      transform: translateX(0);
      visibility: visible;
      transition: transform .42s cubic-bezier(.22, 1, .36, 1), visibility 0s 0s;
    }

    @media (max-width: 600px) { width: 100%; }
  }
  [dir="rtl"] .strb-offcanvas-area {
    right: auto; left: 0;
    transform: translateX(calc(-100% - 80px));
    box-shadow: 24px 0 60px -30px rgba(40, 33, 99, .4);
    &.strb-offcanvas-opened { transform: translateX(0); visibility: visible; }
  }

  .strb-offcanvas-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100%;
  }
  .strb-offcanvas-main { flex: 1; }

  /* ── Header ───────────────────────────────────────────────────────────── */
  .strb-offcanvas-header {
    position: sticky; top: 0; z-index: 12;
    display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
    padding: 50px 24px 18px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-line);
  }
  .strb-oc-head-left { display: flex; align-items: flex-start; gap: 14px; min-width: 0; }
  .strb-offcanvas-close-btn {
    flex: none; width: 38px; height: 38px; margin: 2px 0 0;
    display: grid; place-items: center;
    border-radius: 50%; cursor: pointer;
    background: var(--c-surface); border: 1px solid var(--c-line-2); color: var(--c-ink-2);
    transition: .15s;
    svg { width: 13px; height: 13px; }
    &:hover { background: var(--c-tile); color: var(--c-ink); border-color: var(--c-line); }
  }
  .strb-oc-head-text { min-width: 0; }
  .strb-oc-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .strb-oc-title-row h2,
  .strb-offcanvas-header p.strb-oc-title {
    font-size: 19px; font-weight: 760; letter-spacing: -.3px; color: var(--c-ink); margin: 0;
  }
  .strb-oc-badge {
    font-size: 11.5px; font-weight: 650; line-height: 1;
    padding: 5px 10px; border-radius: 20px;
    background: var(--c-violet-soft); color: var(--c-violet);
  }
  .strb-oc-subtitle { font-size: 13.5px; color: var(--c-muted); margin: 5px 0 0; }

  .strb-oc-docs {
    flex: none;
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 13px; font-weight: 600; text-decoration: none;
    color: var(--c-ink-2); background: var(--c-surface);
    border: 1px solid var(--c-line-2); border-radius: 11px; padding: 8px 14px;
    transition: .15s;
    svg { width: 15px; height: 15px; }
    &:hover { color: var(--c-violet); border-color: var(--c-violet); background: var(--c-violet-soft); }
  }

  /* ── Content ──────────────────────────────────────────────────────────── */
  .strb-offcanvas-content {
    padding: 18px 24px;
    display: flex; flex-direction: column; gap: 16px;
  }

  /* Card grouping each block of options */
  .strb-offcanvas-option {
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--c-r-lg);
    box-shadow: var(--c-shadow-sm);
    padding: 6px 22px;

    &.strb-video-guide {
      padding: 0;
      margin: 0;
      overflow: hidden;
      iframe {
        display: block;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: var(--c-r-lg);
      }
    }
  }

  /* A single setting row */
  .strb-offcanvas-option-item {
    display: flex; align-items: center; gap: 15px;
    padding: 19px 0;
    border-bottom: 1px solid var(--c-line);
    flex-wrap: wrap;
    &:last-child { border-bottom: 0; }
  }
  .strb-oc-ico {
    flex: none; width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: 12px;
    background: var(--c-violet-soft); color: var(--c-violet);
    svg { width: 21px; height: 21px; }
  }
  .strb-offcanvas-option-content {
    flex: 1; min-width: 160px;
    .strb-offcanvas-option-title {
      font-size: 15px; font-weight: 650; color: var(--c-ink); margin: 0 0 2px;
      &.font-semibold { font-weight: 700; }
    }
    p { font-size: 13px; line-height: 1.5; color: var(--c-muted); margin: 0; }
  }
  .strb-offcanvas-option-action {
    flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
    margin-left: auto; padding-left: 24px;
    @media (max-width: 520px) { width: 100%; align-items: stretch; padding-left: 0; }
  }
  .strb-oc-hint {
    font-size: 12px; color: var(--c-muted);
    &.is-accent { color: var(--c-violet); font-weight: 600; }
  }

  /* Sub-section heading inside a card */
  .strb-offcanvas-section-title {
    margin: 4px 0; padding: 13px 16px;
    background: var(--c-tile); border-radius: var(--c-r-md);
    h3 { font-size: 14px; font-weight: 700; color: var(--c-ink); margin: 0; }
  }

  /* ── Toggle switch ────────────────────────────────────────────────────── */
  .strb-toggle-switch-2 {
    label { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
    .switch-input { position: absolute; opacity: 0; width: 0; height: 0; }
    .strb-toggle-switch-2-text { display: none; }
    .strb-toggle-switch-2-bg {
      display: block; width: 46px; height: 26px; border-radius: 20px;
      background: var(--c-line-2); transition: .2s;
    }
    .strb-toggle-switch-2-handle {
      position: absolute; top: 3px; left: 3px;
      width: 20px; height: 20px; border-radius: 50%;
      background: #fff; box-shadow: 0 1px 3px rgba(34, 29, 71, .25); transition: .2s;
    }
    .switch-input:checked ~ .strb-toggle-switch-2-bg { background: var(--c-violet); }
    .switch-input:checked ~ .strb-toggle-switch-2-handle { transform: translateX(20px); }
  }

  /* ── Native / Choices select ──────────────────────────────────────────── */
  .strb-offcanvas-select { width: 280px; @media (max-width: 520px) { width: 100%; } }

  .strb-offcanvas-select select,
  .strb-offcanvas-select .choices__inner {
    width: 100%; min-height: 44px;
    background: var(--c-surface); border: 1px solid var(--c-line-2); border-radius: 11px;
    padding: 10px 38px 10px 14px;
    font-size: 14px; color: var(--c-ink); line-height: 1.3;
    box-shadow: none; transition: .15s;
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8aa7' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 13px center;
  }
  .strb-offcanvas-select select:focus,
  .strb-offcanvas-select .choices.is-focused .choices__inner {
    border-color: var(--c-violet); box-shadow: 0 0 0 3px rgba(111, 89, 243, .15); outline: 0;
  }
  /* Choices.js specifics */
  .strb-offcanvas-select .choices { margin: 0; width: 100%; }
  .strb-offcanvas-select .choices__inner { display: flex; align-items: center; }
  .strb-offcanvas-select .choices__list--single { padding: 0; }
  .strb-offcanvas-select .choices__list--single .choices__item { color: var(--c-ink); padding-left: 15px; }
  .strb-offcanvas-select .choices[data-type*="select-one"]::after { display: none; }
  .strb-offcanvas-select .choices__list--dropdown,
  .strb-offcanvas-select .choices__list[aria-expanded] {
    border: 1px solid var(--c-line-2); border-radius: 12px; margin-top: 6px;
    box-shadow: var(--c-shadow); overflow: hidden; z-index: 30;
  }
  .strb-offcanvas-select .choices__list--dropdown .choices__item {
    font-size: 13.5px; color: var(--c-ink-2); padding: 9px 14px;
  }
  .strb-offcanvas-select .choices__list--dropdown .choices__item--selectable.is-highlighted {
    background: var(--c-violet-soft); color: var(--c-violet);
  }

  /* react-select (multi) */
  .strb-offcanvas-select .select__control {
    min-height: 44px; border-radius: 11px; border-color: var(--c-line-2); box-shadow: none;
    &:hover { border-color: var(--c-line-2); }
    &--is-focused { border-color: var(--c-violet); box-shadow: 0 0 0 3px rgba(111, 89, 243, .15); }
  }
  .strb-offcanvas-select .select__multi-value {
    background: var(--c-violet-soft); border-radius: 7px;
    .select__multi-value__label { color: var(--c-violet); font-weight: 600; }
  }
  .strb-offcanvas-select .select__menu { border-radius: 12px; box-shadow: var(--c-shadow); overflow: hidden; z-index: 30; }
  .strb-offcanvas-select .select__option--is-focused { background: var(--c-violet-soft); color: var(--c-violet); }

  /* ── Text / number input ──────────────────────────────────────────────── */
  .strb-offcanvas-input {
    width: 280px; @media (max-width: 520px) { width: 100%; }
    input, textarea {
      width: 100%; min-height: 44px;
      background: var(--c-surface); border: 1px solid var(--c-line-2); border-radius: 11px;
      padding: 11px 14px; font-size: 14px; color: var(--c-ink); line-height: 1.4;
      outline: 0; box-shadow: none; transition: .15s;
      &:focus { border-color: var(--c-violet); box-shadow: 0 0 0 3px rgba(111, 89, 243, .15); }
      &::placeholder { color: var(--c-faint); }
    }
    textarea { min-height: 96px; resize: vertical; }
  }

  /* ── Number stepper ───────────────────────────────────────────────────── */
  .strb-oc-stepper {
    display: inline-flex; align-items: stretch;
    border: 1px solid var(--c-line-2); border-radius: 11px; overflow: hidden;
    background: var(--c-surface); width: 280px;
    @media (max-width: 520px) { width: 100%; }
    button {
      flex: none; width: 46px; cursor: pointer;
      background: var(--c-tile-2); color: var(--c-ink-2); border: 0;
      display: grid; place-items: center; font-size: 18px; line-height: 1; transition: .15s;
      &:hover { background: var(--c-violet-soft); color: var(--c-violet); }
      svg { width: 16px; height: 16px; }
    }
    input {
      flex: 1; min-width: 0; text-align: center; border: 0; outline: 0;
      background: var(--c-surface); font-size: 15px; font-weight: 650; color: var(--c-ink);
      border-left: 1px solid var(--c-line); border-right: 1px solid var(--c-line);
      -moz-appearance: textfield;
      &::-webkit-outer-spin-button, &::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
    }
  }

  /* ── Radio toggle (pill group) ────────────────────────────────────────── */
  .strb-offcanvas-radio-wrapper { display: inline-flex; gap: 8px; background: var(--c-tile-2); border: 1px solid var(--c-line-2); border-radius: 11px; padding: 4px; }
  .strb-radio-toggle {
    &:not(:last-child) { margin-right: 0; }
    label { display: inline-flex; cursor: pointer; margin: 0; }
    input { position: absolute; opacity: 0; width: 0; height: 0; }
    .strb-radio-handle {
      display: inline-flex; align-items: center; justify-content: center;
      padding: 8px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 600;
      color: var(--c-ink-2); transition: .15s;
    }
    input:checked + .strb-radio-handle { background: var(--c-violet); color: #fff; box-shadow: var(--c-shadow-sm); }
  }

  /* ── Inline info notice ───────────────────────────────────────────────── */
  .strb-oc-notice, .strb-offcanvas-option .components-notice {
    display: flex; align-items: flex-start; gap: 10px;
    background: var(--c-violet-soft); border: 0; border-radius: var(--c-r-md);
    padding: 12px 15px; margin: 4px 0 16px;
    font-size: 13px; color: var(--c-violet-600, #5a44e0);
    .strb-oc-notice-ic { flex: none; color: var(--c-violet); svg { width: 17px; height: 17px; } }
    a { color: var(--c-violet); font-weight: 600; }
  }

  /* ── Currency Switcher ───────────────────────────────────────────────── */
  .strb-cs-card { padding: 0; overflow: hidden; }

  .strb-cs-section-head {
    display: flex; align-items: flex-start; gap: 14px;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--c-line);
    h4 { font-size: 14px; font-weight: 700; color: var(--c-ink); margin: 0 0 2px; }
    p  { font-size: 12.5px; color: var(--c-muted); margin: 0; }
  }
  .strb-cs-section-ic {
    flex: none; width: 36px; height: 36px; border-radius: 10px;
    background: var(--c-violet-soft); color: var(--c-violet);
    display: grid; place-items: center;
    svg { width: 16px; height: 16px; }
  }

  .strb-cs-list { padding: 8px 0; }

  .strb-cs-row {
    border-bottom: 1px solid var(--c-line);
    &:last-child { border-bottom: 0; }
  }
  .strb-cs-row-head {
    width: 100%; display: flex; align-items: center; gap: 10px;
    padding: 13px 22px; cursor: pointer; background: none; border: 0;
    text-align: left; transition: background .12s;
    &:hover { background: var(--c-tile); }
  }
  .strb-cs-code {
    font-size: 14px; font-weight: 700; color: var(--c-ink); min-width: 48px;
  }
  .strb-cs-symbol {
    font-size: 14px; color: var(--c-muted); min-width: 24px;
  }
  .strb-cs-default-badge {
    font-size: 11px; font-weight: 650; padding: 3px 9px; border-radius: 20px;
    background: var(--c-violet-soft); color: var(--c-violet);
  }
  .strb-cs-rate-preview {
    font-size: 12px; color: var(--c-muted); font-family: ui-monospace, monospace;
  }
  .strb-cs-chevron {
    margin-left: auto; color: var(--c-muted); transition: transform .2s;
    svg { width: 16px; height: 16px; display: block; }
    .is-open & { transform: rotate(180deg); }
  }

  .strb-cs-row-body {
    padding: 0 22px 18px;
    background: var(--c-tile);
    border-top: 1px solid var(--c-line);
  }
  .strb-cs-default-info {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 0; font-size: 13px; color: var(--c-muted);
    svg { width: 15px; height: 15px; }
  }
  .strb-cs-lock-ic { flex: none; }

  .strb-cs-fields {
    display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px;
    padding: 14px 0 12px;
    @media (max-width: 600px) { grid-template-columns: 1fr; }
  }
  .strb-cs-field { display: flex; flex-direction: column; gap: 6px; }
  .strb-cs-field-label {
    font-size: 11.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--c-muted);
  }
  .strb-cs-input {
    height: 40px; width: 100%;
    padding: 0 12px;
    background: var(--c-surface); border: 1.5px solid var(--c-line-2);
    border-radius: var(--c-r-md); font-size: 13.5px; color: var(--c-ink);
    transition: border-color .15s, box-shadow .15s;
    &::placeholder { color: var(--c-muted); }
    &:focus { outline: none; border-color: var(--c-violet); box-shadow: 0 0 0 3px rgba(109,86,250,.12); }
  }

  .strb-cs-delete-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 8px; cursor: pointer; border: 0;
    font-size: 13px; font-weight: 600;
    background: #fff0f0; color: #d94040;
    transition: background .15s;
    svg { width: 14px; height: 14px; }
    &:hover { background: #ffe0e0; }
  }

  .strb-cs-add-form { padding: 16px 22px; }

  .strb-cs-add-btn {
    margin-top: 4px;
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px; border-radius: 12px; cursor: pointer; border: 0;
    font-size: 14px; font-weight: 650;
    background: var(--c-violet); color: #fff;
    transition: opacity .15s;
    svg { width: 16px; height: 16px; }
    &:hover { opacity: .88; }
  }

  .strb-cs-pro-notice { padding: 0 22px 16px; }

  /* ── Compact color picker ────────────────────────────────────────────── */
  .strb-color-wrap { position: relative; }
  .strb-color-trigger {
    display: flex; align-items: center; gap: 10px;
    width: 280px; height: 44px; padding: 0 14px;
    background: var(--c-tile); border: 1.5px solid var(--c-line-2);
    border-radius: var(--c-r-md); cursor: pointer;
    font-size: 13px; font-weight: 500; color: var(--c-ink);
    transition: border-color .15s, box-shadow .15s;
    @media (max-width: 520px) { width: 100%; }
    &:hover { border-color: var(--c-violet); }
    &.is-open { border-color: var(--c-violet); box-shadow: 0 0 0 3px rgba(109, 86, 250, .14); }
  }
  .strb-color-dot {
    flex: none; width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid rgba(0,0,0,.1);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
  }
  .strb-color-hex {
    flex: 1; text-align: left;
    font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
    font-size: 12.5px; letter-spacing: .04em; color: var(--c-ink);
  }
  .strb-color-caret {
    flex: none; width: 14px; height: 14px; color: var(--c-muted);
    transition: transform .15s;
    .is-open & { transform: rotate(180deg); }
  }
  .strb-color-popover {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 120;
    background: var(--c-surface); border: 1.5px solid var(--c-line);
    border-radius: var(--c-r-lg); box-shadow: 0 8px 32px rgba(0,0,0,.15);
    padding: 12px;
    // Strip WP's default wrapper padding so our own padding wraps it neatly
    .components-color-picker { width: 254px; }
    .components-color-picker__color-picker,
    .react-colorful { width: 100% !important; }
  }

  /* ── Invoice template picker ─────────────────────────────────────────── */
  .strb-inv-tpl-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 4px 22px 18px;
  }

  .strb-inv-tpl-card {
    background: var(--c-surface);
    border: 2px solid var(--c-line);
    border-radius: 10px;
    padding: 10px 10px 8px;
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, box-shadow .15s;

    &:hover { border-color: var(--c-violet); }

    &.is-active {
      border-color: var(--c-violet);
      box-shadow: 0 0 0 3px rgba(111, 89, 243, .12);
      background: rgba(111, 89, 243, .04);
    }

    svg { width: 100%; height: auto; display: block; border-radius: 4px; overflow: hidden; }

    .strb-inv-tpl-name {
      display: block;
      font-size: 11.5px;
      font-weight: 650;
      color: var(--c-ink);
      margin-top: 7px;
    }
  }

  /* ── Invoice settings fields ──────────────────────────────────────────── */
  .strb-inv-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 4px 22px 16px;
  }

  .strb-inv-field {
    display: flex;
    flex-direction: column;
    gap: 5px;

    &.strb-inv-field--full { grid-column: 1 / -1; }

    label {
      font-size: 11.5px;
      font-weight: 650;
      color: var(--c-ink-2);
      text-transform: uppercase;
      letter-spacing: .05em;
    }

    input, textarea {
      width: 100%;
      border: 1.5px solid var(--c-line);
      border-radius: 8px;
      padding: 9px 12px;
      font-size: 13px;
      color: var(--c-ink);
      background: var(--c-surface);
      font-family: inherit;
      outline: none;
      transition: border-color .15s;
      resize: vertical;

      &:focus { border-color: var(--c-violet); }
      &::placeholder { color: var(--c-muted); }
    }

    textarea { min-height: 72px; }
  }

  /* ── Footer ───────────────────────────────────────────────────────────── */
  .strb-offcanvas-footer {
    position: sticky; bottom: 0; z-index: 12;
    display: flex; align-items: center; gap: 14px;
    padding: 16px 24px;
    background: var(--c-surface); border-top: 1px solid var(--c-line);
  }
  .strb-oc-autosave { flex: 1; text-align: center; font-size: 12.5px; color: var(--c-muted); }
  .strb-offcanvas-footer-btn-wrapper { display: contents; }

  .strb-offcanvas-btn-reset,
  .strb-offcanvas-btn-fill {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    font-size: 14px; font-weight: 650; text-decoration: none; border-radius: 12px;
    padding: 11px 20px; transition: .15s; border: 1px solid transparent;
    svg { width: 16px; height: 16px; }
  }
  .strb-offcanvas-btn-reset {
    color: var(--c-ink-2); background: var(--c-surface); border-color: var(--c-line-2);
    &:hover { background: var(--c-tile); color: var(--c-ink); }
  }
  .strb-offcanvas-btn-fill {
    color: #fff; background: var(--c-violet); border-color: var(--c-violet);
    box-shadow: 0 8px 18px -8px rgba(111, 89, 243, .7);
    &:hover { background: var(--c-violet-600); border-color: var(--c-violet-600); color: #fff; }
  }

  /* If a module doesn't use the autosave note, push Save to the right */
  .strb-offcanvas-footer:not(:has(.strb-oc-autosave)) .strb-offcanvas-btn-fill { margin-left: auto; }
}

/* ── Backdrop ───────────────────────────────────────────────────────────── */
#storebuild-admin-app ~ .strb-body-overlay,
.strb-body-overlay {
  position: fixed; inset: 0; z-index: 9990;
  background: #1a1730; opacity: 0; visibility: hidden;
  transition: opacity .3s ease, visibility .3s ease;
  &.opened { opacity: .45; visibility: visible; }
}
