/**
 * 3.98" BWRY E-Paper Open Smart Badge & Ita-Bag
 * Studio Modules CSS (E-Badge, Ita-Bag, Memo, Paint, Image Lab, Scenes Remote, Presets, Diag)
 * Copyright (c) 2026 ZGQ Inc. Licensed under the MIT License.
 */

/* 
 * 1. Universal Studio Preview Containers & E-Paper Frame
 *  */
.preview-container,
.preview-box {
  width: 100%;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 12px 0 16px 0;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.08);
  padding: 12px;
  min-height: 200px;
}

[data-theme="dark"] .preview-container,
[data-theme="dark"] .preview-box {
  background: #181a1e;
  border-color: #383b42;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.preview-canvas {
  max-width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #ffffff;
  border-radius: 4px;
  box-shadow: var(--shadow-1);
}

/* 
 * 2. Tab 1: Smart E-Badge Studio
 *  */
.badge-style-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 640px) {
  .badge-style-chips {
    grid-template-columns: repeat(2, 1fr);
  }
}

.badge-style-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  touch-action: manipulation;
}

.badge-style-card:hover {
  background: var(--md-sys-color-surface-container-high);
}

.badge-style-card:active {
  transform: scale(0.96);
}

.badge-style-card.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
  box-shadow: var(--shadow-1);
}

/* 
 * 3. Tab 2: Ita-Bag & Charm Studio
 *  */
.itabag-lanyard-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.itabag-upload-zone,
.file-drop-area {
  border: 2px dashed var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  text-align: center;
  background: var(--md-sys-color-surface);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
  position: relative;
}

.itabag-upload-zone:hover,
.itabag-upload-zone.dragover,
.file-drop-area:hover,
.file-drop-area.dragover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.preview-container.drag-active {
  outline: 2px dashed var(--md-sys-color-primary);
  outline-offset: -4px;
  background: rgba(168, 199, 250, 0.05);
}

.itabag-upload-icon {
  font-size: 30px;
  line-height: 1;
}

.itabag-upload-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.itabag-upload-desc {
  font-size: 11px;
  color: var(--md-sys-color-outline);
}

.itabag-file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.itabag-slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-val-badge {
  display: inline-block;
  font-family: monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-primary);
}

.itabag-preview-frame {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 8px;
  background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(240,240,240,0.2) 100%);
  border: 2px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--shadow-2);
}

[data-theme="dark"] .itabag-preview-frame {
  background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, rgba(0,0,0,0.3) 100%);
  border-color: #44474e;
}

.itabag-bezel {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.itabag-window-glare {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  border-radius: 4px;
  background: linear-gradient(125deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.02) 40%, transparent 60%);
  z-index: 2;
}

/* 
 * 4. Tab 4: Paint Studio
 *  */
.palette-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.palette-box {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.palette-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--md-sys-color-outline);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 
 * 5. Tab 5: Image Lab
 *  */
.lab-slider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 580px) {
  .lab-slider-grid {
    grid-template-columns: 1fr;
  }
}

/* 
 * 6. Tab 6: Scenes & Hardware Remote Controls
 *  */
.clear-buttons-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .clear-buttons-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .clear-btn.refresh {
    grid-column: 1 / -1;
  }
}

.clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  gap: 6px;
  touch-action: manipulation;
  user-select: none;
}

.clear-btn:active {
  transform: scale(0.96);
}

.clear-btn.refresh {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.clear-btn.white {
  background: #ffffff;
  color: #1a1c1e;
  border-color: #c4c6d0;
}

.clear-btn.black {
  background: #000000;
  color: #ffffff;
  border-color: #333333;
}

.clear-btn.yellow {
  background: #f4c430;
  color: #1a1c1e;
  border-color: #d4a017;
}

.clear-btn.red {
  background: #d32f2f;
  color: #ffffff;
  border-color: #b71c1c;
}

.mode-switcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 500px) {
  .mode-switcher-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.mode-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  gap: 4px;
  touch-action: manipulation;
  user-select: none;
}

.mode-card-btn:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-primary);
}

.mode-card-btn:active {
  transform: scale(0.96);
}

.mode-card-btn.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.rf-mode-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .rf-mode-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.rf-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  gap: 2px;
  touch-action: manipulation;
  user-select: none;
}

.rf-btn:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-primary);
}

.rf-btn:active {
  transform: scale(0.96);
}

.rf-btn.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.bin-tools-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.bin-tools-row .m3-btn {
  flex: 1;
}

.scene-mode-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.mode-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  touch-action: manipulation;
  user-select: none;
}

.mode-chip:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container-high);
}

.mode-chip:active {
  transform: scale(0.96);
}

.mode-chip.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.mode-chip-icon {
  font-size: 22px;
  margin-bottom: 4px;
  line-height: 1;
}

.mode-chip-title {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.mode-chip-desc {
  font-size: 10px;
  color: var(--md-sys-color-outline);
  margin-top: 2px;
}

.mode-chip.active .mode-chip-desc {
  color: var(--md-sys-color-on-primary-container);
  opacity: 0.85;
}

.scene-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scene-form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 
 * 7. Device Manager List Items
 *  */
.dev-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-md);
  gap: 10px;
}

.dev-item-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dev-item-title {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dev-item-meta {
  font-size: 11px;
  color: var(--md-sys-color-outline);
}

.dev-item-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 
 * 8. Presets Grid & Diag Table
 *  */
.preset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.preset-card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
}

.preset-card:hover {
  border-color: var(--md-sys-color-primary);
  box-shadow: var(--shadow-1);
}

.preset-card.selected {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.preset-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preset-type-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  font-weight: 600;
}

.preset-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.diag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.diag-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.diag-table td:first-child {
  font-weight: 600;
  color: var(--md-sys-color-outline);
  width: 38%;
}

.diag-table td:last-child {
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 768px) {
  .grid-2col {
    grid-template-columns: 1fr;
  }
}

/* 
 * 9. Image Lab Interactive Transform Selector Box & Mobile Adaptations
 *  */
.canvas-interactive-wrapper {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  max-width: 100%;
  line-height: 0;
  user-select: none;
}

.image-select-box {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  box-sizing: border-box;
}

.select-box-border {
  position: absolute;
  inset: 0;
  border: 1.5px dashed var(--md-sys-color-primary, #1e90ff);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.select-handle {
  position: absolute;
  pointer-events: auto;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 2.5px solid var(--md-sys-color-primary, #1e90ff);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  touch-action: none;
  cursor: pointer;
  z-index: 6;
  transition: transform 0.1s, background-color 0.1s, border-color 0.1s;
}

.select-handle::after {
  content: '';
  position: absolute;
  top: -12px;
  left: -12px;
  right: -12px;
  bottom: -12px;
}

.select-handle:hover,
.select-handle.active {
  transform: translate(-50%, -50%) scale(1.3);
  background: #e8f0fe;
  border-color: #0b57d0;
}

.select-handle.handle-tl { top: 0; left: 0; cursor: nwse-resize; }
.select-handle.handle-tr { top: 0; left: 100%; cursor: nesw-resize; }
.select-handle.handle-br { top: 100%; left: 100%; cursor: nwse-resize; }
.select-handle.handle-bl { top: 100%; left: 0; cursor: nesw-resize; }

.select-handle.handle-tc { top: 0; left: 50%; cursor: ns-resize; }
.select-handle.handle-bc { top: 100%; left: 50%; cursor: ns-resize; }
.select-handle.handle-ml { top: 50%; left: 0; cursor: ew-resize; }
.select-handle.handle-mr { top: 50%; left: 100%; cursor: ew-resize; }

.image-lab-card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.canvas-zoom-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .image-lab-card-title {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .canvas-zoom-toolbar {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }
  .canvas-zoom-toolbar .m3-btn.small {
    padding: 6px 6px;
    font-size: 11px;
    flex: 1 1 auto;
    text-align: center;
  }
  .select-handle {
    width: 16px;
    height: 16px;
    border-width: 3px;
  }
  .select-handle::after {
    top: -15px;
    left: -15px;
    right: -15px;
    bottom: -15px;
  }
}
