/* Edwiser Store - Reusable Components */
/* Toggle switches, modals, forms, editor panels */

/* Delete Modal Base */
.local-edwiserstore-delete-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
}

/* Product editor sidebar modal (simplified) */
.edwiser-product-editor-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000; /* below Moodle picker */
}
.edwiser-product-editor-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50vw;
  max-width: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
}
.edwiser-editor-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.edwiser-editor-body {
  padding: 24px;
  overflow-y: auto;
}
.edwiser-editor-footer {
  padding: 16px 24px;
  border-top: 1px solid #e2e8f0;
}
.edwiser-editor-close {
  font-size: 22px;
  line-height: 1;
}

/* Notes/tips styling to match design cues */
.edwiser-note {
  font-size: 12px;
  color: #6c757d;
}

/* Precise layout for Product Editor modal */
.edwiser-product-editor-backdrop .edwiser-product-editor-panel {
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
}
.edwiser-product-editor-panel .edwiser-editor-header {
  padding-top: 24px;
  padding-bottom: 16px;
}
.edwiser-product-editor-panel .edwiser-editor-header h4 {
  font-weight: 600;
  font-size: 20px;
}

.edwiser-product-editor-panel .edwiser-editor-body .form-control {
  height: auto;
}

.edwiser-product-editor-panel .edwiser-editor-body .form-group {
  margin-bottom: 16px;
}
.edwiser-editor-body .edwiser-note {
  font-size: 12px;
  line-height: 1.4;
}
.edwiser-editor-body .form-row + .form-row {
  margin-top: 16px;
}

/* Related products chips (core/form-autocomplete) */
.form-autocomplete-selection .form-autocomplete-selection-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.form-autocomplete-selection
  .form-autocomplete-selection-list
  .form-autocomplete-selection-item,
.form-autocomplete-selection .form-autocomplete-token {
  background: #eef5ff;
  color: #2f80ed;
  border-radius: 16px;
  padding: 4px 10px;
  border: 1px solid #d6e7ff;
}
.form-autocomplete-selection .deleteaction {
  margin-left: 6px;
  color: #2f80ed;
}

/* Footer buttons sizing */
.edwiser-editor-footer .btn {
  height: 44px;
  padding: 0 18px;
  font-weight: 600;
}
.edwiser-editor-footer .btn-primary {
  background: #2f80ed;
  border-color: #2f80ed;
}
.edwiser-editor-footer .btn-primary:hover {
  background: #1e6fe0;
  border-color: #1e6fe0;
}
.edwiser-editor-footer .btn-link {
  color: #6c757d;
}
.edwiser-editor-footer .btn-link:hover {
  color: #343a40;
}
.edwiser-compact-select {
  width: 220px;
  min-width: 200px;
  max-width: 260px;
}
.edwiser-editor-body .form-row {
  gap: 16px;
}
.edwiser-editor-body label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.edwiser-editor-body select.form-control {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236c757d' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  padding-left: 12px;
  height: 40px;
  line-height: 24px;
  width: 100%;
}
.edwiser-section-title {
  font-size: 14px;
  font-weight: 700;
  color: #374151;
}
.edwiser-inline-default {
  color: #6c757d;
  font-size: 12px;
  white-space: nowrap;
  margin-left: 12px;
  align-self: center;
}
.edwiser-editor-body .form-row.align-items-start .edwiser-inline-default {
  align-self: flex-end;
}
/* Product type section: proper alignment */
.edwiser-editor-body .edwiser-product-type-group {
  margin-bottom: 16px;
}
.edwiser-editor-body .edwiser-product-type-group label {
  margin-bottom: 6px;
  display: block;
}
.edwiser-editor-body .form-row.edwiser-product-type-row {
  align-items: flex-start;
  margin-top: 0;
  gap: 12px;
}
.edwiser-editor-body .edwiser-product-type-row .flex-fill {
  display: flex;
  flex-direction: column;
}
.edwiser-editor-body .edwiser-product-type-row .flex-fill .edwiser-note {
  margin-top: 8px;
  margin-left: 0;
}
.edwiser-editor-body .edwiser-product-type-help {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 120px;
  padding-top: 0;
  flex-shrink: 0;
}
.edwiser-editor-body .edwiser-product-type-help .edwiser-inline-default {
  margin-left: 0;
  margin-bottom: 0;
  padding-top: 0;
  height: 40px;
  line-height: 40px;
  display: flex;
  align-items: center;
}

/* Toggle style for show/hide grid - proper toggle switches matching shop_settings */
.edwiser-showhide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.edwiser-showhide-grid .toggle-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.edwiser-showhide-grid .toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.edwiser-showhide-grid .toggle-switch input[type='checkbox'] {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
}

.edwiser-showhide-grid .toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  transition: background-color 0.2s;
  border-radius: 24px;
}

.edwiser-showhide-grid .toggle-slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: transform 0.2s;
  border-radius: 50%;
}

.edwiser-showhide-grid .toggle-switch input:checked + .toggle-slider {
  background-color: #2f80ed;
}

.edwiser-showhide-grid .toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

.edwiser-showhide-grid .toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.3);
}

.edwiser-showhide-grid .toggle-label-text {
  font-size: 14px;
  color: #374151;
  font-weight: 500;
  white-space: nowrap;
}
.edwiser-editor-body textarea.form-control {
  height: auto;
  min-height: 240px;
}

/* Tiny/Atto editor height parity */
.edwiser-product-editor-panel .tox-tinymce {
  min-height: 280px;
}
.edwiser-product-editor-panel .tox .tox-edit-area__iframe {
  min-height: 220px;
}
.edwiser-product-editor-panel .editor_atto {
  min-height: 280px;
}

/* Ensure TinyMCE dialogs (source code, link, etc.) appear above the product editor backdrop */
.tox-tinymce-aux {
  z-index: 10001 !important;
}

/* When Moodle file picker is open, allow clicks to pass through our backdrop */
body.edwiser-picker-open .edwiser-product-editor-backdrop {
  display: block; /* keep modal visible */
  pointer-events: none; /* but do not block clicks intended for the picker */
}
body.edwiser-picker-open
  .edwiser-product-editor-backdrop
  .edwiser-product-editor-panel {
  pointer-events: auto; /* keep our editor panel interactive if needed */
}

/* Related product chips size */
.form-autocomplete-selection
  .form-autocomplete-selection-list
  .form-autocomplete-selection-item,
.form-autocomplete-selection .form-autocomplete-token {
  height: 28px;
  line-height: 28px;
  padding: 0 12px;
  border-radius: 14px;
  font-weight: 500;
}

/* Autocomplete dropdown spacing */
.form-autocomplete-suggestions .form-autocomplete-suggestions li,
.form-autocomplete-suggestions .form-autocomplete-suggestion {
  padding: 8px 12px !important;
  font-size: 14px;
}

/* Footer spacing from content */
.edwiser-product-editor-panel .edwiser-editor-footer {
  margin-top: 8px;
}
.edwiser-editor-body .form-check {
  margin-right: 20px;
}
.edwiser-editor-body .form-check-label {
  font-weight: 500;
}
.edwiser-editor-footer {
  padding-top: 16px;
  padding-bottom: 16px;
}
.edwiser-editor-footer .btn {
  min-width: 140px;
}
.edwiser-product-editor-panel .btn.btn-primary {
  box-shadow: none;
}
.edwiser-product-editor-panel .btn.btn-link {
  color: #6c757d;
}
.edwiser-product-editor-panel .btn.btn-link:hover {
  color: #343a40;
  text-decoration: none;
}

/* Fine spacing for helper notes and icon tips */
.edwiser-note.mt-1 {
  margin-top: 6px !important;
}
.edwiser-product-editor-panel i.fa.fa-info-circle {
  color: #6c757d;
  font-size: 13px;
  margin-left: 4px;
}

/* Autocomplete width & spacing */
.edwiser-product-editor-panel .form-autocomplete-downarrow {
  right: 10px;
}
.edwiser-product-editor-panel .form-autocomplete-suggestions {
  max-height: 240px;
}

/* Hide paid and subscription sections by default - JavaScript will show them based on product type */
.edwiser-product-editor-panel .section-paid,
.edwiser-product-editor-panel .section-subscription {
  display: none;
}

/* Responsive adjustments for editor panel */
@media (max-width: 1024px) {
  .edwiser-product-editor-panel {
    width: 92vw;
  }
}
@media (max-width: 576px) {
  .edwiser-product-editor-panel {
    width: 100vw;
  }
  .edwiser-editor-body .form-row {
    display: block !important;
  }
}

/* Delete Modal Overlay */
.local-edwiserstore-delete-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.local-edwiserstore-delete-modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  min-width: 400px;
  max-width: 90%;
  z-index: 10000;
}

.local-edwiserstore-delete-modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid #e2e8f0;
}

.local-edwiserstore-delete-modal-header h4 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #212529;
}

.local-edwiserstore-delete-modal-body {
  padding: 20px 24px;
}

.local-edwiserstore-delete-modal-body p {
  margin: 0;
  color: #495057;
  font-size: 14px;
}

.local-edwiserstore-delete-modal-footer {
  padding: 16px 24px 20px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.local-edwiserstore-delete-modal-footer .btn {
  padding: 8px 20px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
}

.local-edwiserstore-delete-modal-footer .btn-secondary {
  background: #fff;
  border: 1px solid #dee2e6;
  color: #495057;
}

.local-edwiserstore-delete-modal-footer .btn-secondary:hover {
  background: #f8f9fa;
}

.local-edwiserstore-delete-modal-footer .btn-primary {
  background: #007bff;
  border: 1px solid #007bff;
  color: #fff;
}

.local-edwiserstore-delete-modal-footer .btn-primary:hover {
  background: #0056b3;
  border-color: #0056b3;
}

/* Shop Settings Styles */
.local-edwiserstore-shop-settings {
  padding: 24px;
  background: #fff;
  border-radius: 8px;
}

.shop-settings-form .form-group {
  margin-bottom: 24px;
}

.shop-settings-form .form-group:last-child {
  margin-bottom: 0;
}

.shop-settings-form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #374151;
  font-size: 14px;
}

.shop-settings-form .form-control {
  width: 100%;
  max-width: 400px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

/* Override max-width for payment settings full-width fields */
.local-edwiserstore-payment-settings
  .shop-settings-form
  .form-control.payment-field-full-width {
  max-width: 100%;
}

.local-edwiserstore-payment-settings .shop-settings-form .form-control {
  max-width: 100%;
}

.shop-settings-form .form-control:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: #2f80ed;
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.1);
}

/* Toggle Switch Styles */
.toggle-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  transition: 0.2s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: #2f80ed;
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

.toggle-label-text {
  font-size: 14px;
  color: #6b7280;
  font-weight: 500;
  min-width: 40px;
}

/* Disabled Toggle State */
.toggle-switch-wrapper.toggle-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.toggle-switch-wrapper.toggle-disabled .toggle-switch {
  cursor: not-allowed;
}

.toggle-switch-wrapper.toggle-disabled .toggle-slider {
  cursor: not-allowed;
  background-color: #e5e7eb;
}

.toggle-switch-wrapper.toggle-disabled .toggle-label-text {
  color: #9ca3af;
  cursor: help;
}

.toggle-switch input:disabled + .toggle-slider {
  background-color: #e5e7eb;
  cursor: not-allowed;
}

.toggle-switch input:disabled + .toggle-slider:before {
  background-color: #d1d5db;
}

/* Toast Notification Styles */
.shop-settings-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  min-width: 300px;
  max-width: 500px;
  background-color: #10b981;
  color: white;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 9999;
  animation: slideInRight 0.3s ease-out;
}

.shop-settings-toast-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
}

.shop-settings-toast-message {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.shop-settings-toast-close {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  margin-left: 16px;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.shop-settings-toast-close:hover {
  opacity: 1;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Save Button */
.shop-settings-form .btn-primary {
  background-color: #2f80ed;
  border-color: #2f80ed;
  color: white;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  min-width: 140px;
}

.shop-settings-form .btn-primary:hover {
  background-color: #1e6fe0;
  border-color: #1e6fe0;
}

.shop-settings-form .btn-primary:disabled {
  background-color: #9ca3af;
  border-color: #9ca3af;
  cursor: not-allowed;
}

/* Payment Settings Styles */
.local-edwiserstore-payment-settings {
  padding: 24px;
  background: #fff;
  border-radius: 8px;
}

.local-edwiserstore-payment-settings .shop-settings-form .form-group {
  margin-bottom: 24px;
}

.local-edwiserstore-payment-settings .shop-settings-form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #374151;
  font-size: 14px;
}

.local-edwiserstore-payment-settings .shop-settings-form .form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

.local-edwiserstore-payment-settings .shop-settings-form .form-control:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: #2f80ed;
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.1);
}

/* Coupon Editor Modal Styles - Using Moodle ModalFactory */
.modal-sidebar.modal-dialog {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: auto !important;
  margin: 0 !important;
  max-width: 50vw !important;
  width: 50vw !important;
  transform: none !important;
}

.modal-sidebar.modal-dialog:focus .modal-content {
  box-shadow: none !important;
}

.modal-sidebar .modal-content {
  height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

.modal-sidebar .modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-sidebar .modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.modal-sidebar .modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #e2e8f0;
}

/* Product editor styles in ModalFactory sidebar */
.modal-sidebar .edwiser-editor-body {
  padding: 0; /* Remove padding since modal-body already has it */
}

.modal-sidebar .edwiser-editor-footer {
  padding: 0; /* Remove padding since modal-footer already has it */
}

.modal-sidebar .modal-header .modal-title {
  font-size: 18px;
  font-weight: 600;
  color: #212529;
  flex-grow: 1;
}

.modal-sidebar .order-download-icon-btn,
.modal-sidebar .order-download-icon-btn:hover {
  color: #2f80ed;
  background: none;
  border: none;
  padding: 4px;
  margin-right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  order: 1;
}

.modal-sidebar .modal-header .btn-close {
  order: 2;
  margin-left: 0;
}

.modal-sidebar .order-download-icon-btn:hover,
.modal-sidebar .order-download-icon-btn:focus {
  color: #1a5fc7;
}

.modal-sidebar .order-download-icon-btn i {
  font-size: 18px;
}

.modal-sidebar .edwiser-editor-body .form-group {
  margin-bottom: 16px;
}

.modal-sidebar .edwiser-editor-body .form-control {
  height: auto;
}

.modal-sidebar .edwiser-editor-body textarea.form-control {
  min-height: 100px;
}

.modal-sidebar .edwiser-editor-body .tox-tinymce {
  min-height: 280px;
}

.modal-sidebar .edwiser-editor-body .tox .tox-edit-area__iframe {
  min-height: 220px;
}

.modal-sidebar .edwiser-editor-body .editor_atto {
  min-height: 280px;
}

.modal-sidebar.edwiser-picker-open {
  pointer-events: none;
}

.modal-sidebar.edwiser-picker-open .modal-content {
  pointer-events: auto;
}

/* Empty state styling */
.local-edwiserstore-empty-state {
  padding: 60px 20px;
}

.local-edwiserstore-empty-state .empty-illustration img {
  max-width: 200px;
  opacity: 0.6;
}

.local-edwiserstore-empty-state p {
  color: #6b7280;
  max-width: 400px;
  margin: 0 auto;
}

/* Badge styles */
.local-edwiserstore-content-card .badge {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 2px;
  font-weight: 500;
}

/* Design fixes for toggle switches */
.edwiser-showhide-grid .toggle-switch input:checked + .toggle-slider,
.toggle-switch input:checked + .toggle-slider {
  background-color: #28a745;
}

/* Floating cart icon - pill button design */
.edwiserstore-floating-cart {
  position: fixed;
  top: calc(var(--edwiserstore-navbar-offset, 56px) + 24px);
  right: 0;
  z-index: 1020;
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.edwiserstore-floating-cart.is-empty {
  opacity: 0.4;
}

.edwiserstore-floating-cart-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  border-radius: 8px 0 0 8px;
  background: #343a40;
  color: #6b7280;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.edwiserstore-floating-cart-link:hover,
.edwiserstore-floating-cart-link:focus {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.edwiserstore-floating-cart-link svg {
  color: #fff;
}

.edwiserstore-floating-cart-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  background: #6bf28a;
  color: #111;
  font-size: 13px;
  font-weight: 600;
}

.edwiserstore-floating-cart-badge.is-hidden {
  display: none;
}

@media (max-width: 768px) {
  .edwiserstore-floating-cart {
    right: 12px;
    top: calc(var(--edwiserstore-navbar-offset, 56px) + 12px);
  }

  .edwiserstore-floating-cart-link {
    padding: 6px 8px 6px 12px;
    gap: 6px;
  }

  .edwiserstore-floating-cart-link i.fa {
    font-size: 16px;
  }

  .edwiserstore-floating-cart-badge {
    min-width: 22px;
    height: 22px;
    font-size: 12px;
    padding: 0 6px;
  }
}
