/**
 * Admin Mode Styles
 * Visual editor for super admin
 */

/* ==========================================
   MODE TOGGLE BUTTON
   ========================================== */
.admin-mode-toggle {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 9999;
}

.admin-mode-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
  transition: all 0.3s ease;
}

.admin-mode-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.admin-mode-btn .icon-eye {
  display: none;
}

.admin-mode-active .admin-mode-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
}

.admin-mode-active .admin-mode-btn:hover {
  box-shadow: 0 6px 25px rgba(16, 185, 129, 0.5);
}

.admin-mode-active .admin-mode-btn .icon-edit {
  display: none;
}

.admin-mode-active .admin-mode-btn .icon-eye {
  display: block;
}

/* Theme Settings Button */
.admin-theme-btn {
  position: fixed;
  bottom: 100px;
  left: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.4);
  transition: all 0.3s ease;
}

.admin-theme-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(245, 158, 11, 0.5);
}

@media (max-width: 768px) {
  .admin-theme-btn {
    bottom: 80px;
    left: 16px;
    padding: 10px 14px;
  }

  .admin-theme-btn span {
    display: none;
  }
}

/* ==========================================
   EDITABLE ELEMENT CONTROLS
   ========================================== */
.admin-editable {
  position: relative;
}

.admin-controls {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 100;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8px;
  padding: 6px 10px;
  align-items: center;
  gap: 8px;
}

/* Announcement bar controls - มุมขวาบน z-index สูงกว่า header */
.admin-controls-fixed {
  display: none;
  position: absolute;
  top: 4px;
  right: 8px;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8px;
  padding: 6px 10px;
  align-items: center;
  gap: 8px;
}

.admin-mode-active .admin-controls-fixed {
  display: flex;
}

/* Announcement bar ต้อง z-index สูงกว่า header */
.admin-mode-active .announcement-bar {
  position: relative;
  z-index: 101;
}

.admin-mode-active .admin-controls {
  display: flex;
}

.admin-mode-active .admin-editable {
  outline: 2px dashed rgba(99, 102, 241, 0.5);
  outline-offset: 4px;
}

.admin-mode-active .admin-editable:hover {
  outline-color: rgba(99, 102, 241, 0.8);
}

.admin-label {
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.admin-buttons {
  display: flex;
  gap: 4px;
}

.admin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.admin-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.admin-btn .icon-show {
  display: block;
}

.admin-btn .icon-hide {
  display: none;
}

.admin-btn.active {
  background: #ef4444;
}

.admin-btn.active .icon-show {
  display: none;
}

.admin-btn.active .icon-hide {
  display: block;
}

/* Hidden element in admin mode */
.admin-mode-active .admin-hidden {
  opacity: 0.3;
  pointer-events: none;
}

.admin-mode-active .admin-hidden .admin-controls {
  pointer-events: auto;
}

/* Hidden element in user mode */
body:not(.admin-mode-active) .admin-hidden {
  display: none !important;
}

/* ==========================================
   EDITOR MODAL
   ========================================== */
.admin-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.admin-modal.show {
  opacity: 1;
  visibility: visible;
}

.admin-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.admin-modal-content {
  position: relative;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  background: #1a1a1a;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: scale(0.9);
  transition: transform 0.3s ease;
  overflow: hidden;
}

.admin-modal.show .admin-modal-content {
  transform: scale(1);
}

.admin-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: #fff;
}

.admin-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  color: #888;
  cursor: pointer;
  transition: all 0.2s ease;
}

.admin-modal-close:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.admin-modal-body {
  padding: 20px;
  max-height: 60vh;
  overflow-y: auto;
}

.admin-modal-footer {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-modal-footer-right {
  display: flex;
  gap: 12px;
}

.admin-modal-footer .btn-reset {
  background: transparent;
  border-color: #f59e0b;
  color: #f59e0b;
  font-size: 13px;
}

.admin-modal-footer .btn-reset:hover {
  background: rgba(245, 158, 11, 0.1);
}

/* Form fields */
.admin-field {
  margin-bottom: 16px;
}

.admin-field:last-child {
  margin-bottom: 0;
}

.admin-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #888;
}

.admin-field input[type="text"],
.admin-field input[type="datetime-local"],
.admin-field textarea {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  transition: all 0.2s ease;
}

.admin-field input:focus,
.admin-field textarea:focus {
  outline: none;
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.1);
}

.admin-field textarea {
  resize: vertical;
  min-height: 80px;
}

/* Select field */
.admin-select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  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='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.admin-select:focus {
  outline: none;
  border-color: #6366f1;
  background-color: rgba(99, 102, 241, 0.1);
}

.admin-select option {
  background: #1a1a1a;
  color: #fff;
}

/* Image upload field */
.admin-image-upload {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-image-preview {
  width: 100%;
  min-height: 120px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.admin-image-preview img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
}

.admin-image-preview span {
  color: #666;
  font-size: 14px;
}

.admin-image-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-danger {
  background: #ef4444;
  color: white;
  border: none;
}

.btn-danger:hover {
  background: #dc2626;
}

/* Code textarea */
.admin-code {
  width: 100%;
  padding: 12px;
  background: #0d0d0d;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #10b981;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  min-height: 80px;
}

.admin-code:focus {
  outline: none;
  border-color: #6366f1;
}

.admin-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: #666;
}

/* Color picker */
.admin-field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-field-inline label {
  margin-bottom: 0;
  flex-shrink: 0;
}

.admin-color-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-color-picker input[type="color"] {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
}

.admin-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.admin-color-picker input[type="color"]::-webkit-color-swatch {
  border-radius: 4px;
  border: none;
}

.admin-color-text {
  width: 120px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-family: monospace;
}

/* Color with Alpha */
.admin-color-alpha {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}

.admin-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-color-input {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
}

.admin-color-input::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.admin-color-input::-webkit-color-swatch {
  border-radius: 4px;
  border: none;
}

.admin-color-hex {
  flex: 1;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-family: monospace;
}

.admin-alpha-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-alpha-row label {
  font-size: 12px;
  color: #888;
  margin: 0;
  min-width: 50px;
}

.admin-alpha-slider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  background: linear-gradient(to right, transparent, #fff);
  border-radius: 3px;
  cursor: pointer;
}

.admin-alpha-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.admin-alpha-value {
  font-size: 12px;
  color: #888;
  min-width: 40px;
  text-align: right;
}

.admin-color-preview-box {
  height: 24px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background-image: linear-gradient(45deg, #333 25%, transparent 25%),
                    linear-gradient(-45deg, #333 25%, transparent 25%),
                    linear-gradient(45deg, transparent 75%, #333 75%),
                    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  position: relative;
}

.admin-color-preview-box::after {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  border-radius: inherit;
}

/* Toggle switch */
.admin-toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.admin-switch {
  position: relative;
  width: 48px;
  height: 26px;
}

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

.admin-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: 0.3s;
  border-radius: 26px;
}

.admin-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.admin-switch input:checked + .admin-slider {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

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

/* ==========================================
   TOAST NOTIFICATIONS
   ========================================== */
.admin-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background: #1a1a1a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  z-index: 10001;
  opacity: 0;
  transition: all 0.3s ease;
}

.admin-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.admin-toast-success {
  border-color: #10b981;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(16, 185, 129, 0.1));
}

.admin-toast-error {
  border-color: #ef4444;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(239, 68, 68, 0.1));
}

.admin-toast-info {
  border-color: #6366f1;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.1));
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
  .admin-mode-toggle {
    bottom: 80px;
    right: 16px;
  }

  .admin-mode-btn {
    padding: 10px 14px;
  }

  .admin-mode-btn .mode-label {
    display: none;
  }

  .admin-controls {
    top: 4px;
    right: 4px;
    padding: 4px 8px;
  }

  .admin-label {
    display: none;
  }

  .admin-modal-content {
    width: 95%;
    margin: 16px;
  }
}

/* ==========================================
   LOGO UPLOAD
   ========================================== */
.admin-logo-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}

.admin-logo-preview {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.admin-logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.admin-logo-preview span {
  font-size: 11px;
  color: #666;
  text-align: center;
  padding: 4px;
}

/* Hero Image Upload */
.admin-hero-upload {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}

.admin-hero-preview {
  width: 100%;
  max-width: 200px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
}

.admin-hero-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.admin-hero-preview span {
  font-size: 12px;
  color: #666;
  text-align: center;
  padding: 8px;
}

/* ==========================================
   PRODUCT SELECTOR (Drag & Drop Slots)
   ========================================== */
.admin-field-hint {
  font-size: 12px;
  color: #888;
  margin: 4px 0 12px 0;
}

.admin-product-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Product Slots Grid */
.admin-product-slots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 600px) {
  .admin-product-slots {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Slot Base */
.admin-slot {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.admin-slot .slot-number {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  z-index: 2;
}

/* Filled Slot */
.admin-slot.filled {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  cursor: grab;
}

.admin-slot.filled:hover {
  border-color: #6366f1;
}

.admin-slot.filled img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.admin-slot.filled .slot-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
}

.admin-slot.filled .slot-info strong {
  display: block;
  font-size: 11px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-slot.filled .slot-info span {
  font-size: 10px;
  color: #10b981;
}

/* Remove Button */
.btn-slot-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: rgba(239, 68, 68, 0.9);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 2;
}

.admin-slot.filled:hover .btn-slot-remove {
  opacity: 1;
}

.btn-slot-remove:hover {
  background: #ef4444;
  transform: scale(1.1);
}

/* Drag Handle */
.slot-drag-handle {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 2;
}

.admin-slot.filled:hover .slot-drag-handle {
  opacity: 1;
}

/* Empty Slot */
.admin-slot.empty {
  background: rgba(255, 255, 255, 0.02);
  border: 2px dashed rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.admin-slot.empty:hover {
  border-color: rgba(99, 102, 241, 0.5);
  background: rgba(99, 102, 241, 0.05);
}

.btn-slot-add {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-slot-add:hover {
  background: rgba(99, 102, 241, 0.3);
  color: #fff;
  transform: scale(1.1);
}

/* Drag States */
.admin-slot.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.admin-slot.drag-over {
  border-color: #6366f1 !important;
  border-style: solid !important;
  background: rgba(99, 102, 241, 0.1) !important;
}

/* Product Picker Modal */
.admin-product-picker {
  margin-top: 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
}

.admin-product-picker-header {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-product-picker-header input {
  flex: 1;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
}

.admin-product-picker-header input:focus {
  outline: none;
  border-color: #6366f1;
}

.btn-close-picker {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-close-picker:hover {
  background: rgba(239, 68, 68, 0.3);
  color: #fff;
}

/* Product List in Picker */
.admin-product-list {
  max-height: 250px;
  overflow-y: auto;
  padding: 8px;
}

.admin-product-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 6px;
}

.admin-product-item:last-child {
  margin-bottom: 0;
}

.admin-product-item:hover {
  background: rgba(99, 102, 241, 0.2);
}

.admin-product-item img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

.admin-product-info {
  flex: 1;
  min-width: 0;
}

.admin-product-info strong {
  display: block;
  font-size: 13px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-product-info span {
  font-size: 12px;
  color: #10b981;
}

.admin-product-list .empty-text,
.admin-product-list .loading-text,
.admin-product-slots .loading-text,
.admin-product-slots .error-text {
  font-size: 13px;
  color: #888;
  text-align: center;
  padding: 20px;
  margin: 0;
}

.admin-product-slots .error-text {
  color: #ef4444;
}
