/* ====================================================
   Photo Editor — Layout & Component Styles
   ==================================================== */

#pe-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  background: #282E2F;
}

/* ---- Toolbar ---- */
#pe-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #323A3C;
  border-bottom: 1px solid #404A4C;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.pe-toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pe-toolbar-sep {
  width: 1px;
  height: 22px;
  background: #555;
  margin: 0 4px;
  flex-shrink: 0;
}

.pe-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #464D4F;
  color: #D0D8DA;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  transition: background 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.pe-toolbar-btn:hover {
  background: #5A6264;
  color: #fff;
  text-decoration: none;
}

.pe-toolbar-btn:disabled,
.pe-toolbar-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

#pe-zoom-label {
  min-width: 38px;
  text-align: center;
  color: #D0D8DA;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* ---- Photo Filmstrip ---- */
#pe-photo-strip {
  background: #2A3032;
  border-bottom: 1px solid #404A4C;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  min-height: 54px;
  flex-shrink: 0;
}

#pe-photo-strip-inner {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  padding-bottom: 2px;
}

#pe-photo-strip-inner::-webkit-scrollbar { height: 4px; }
#pe-photo-strip-inner::-webkit-scrollbar-track { background: transparent; }
#pe-photo-strip-inner::-webkit-scrollbar-thumb { background: #555; border-radius: 2px; }

.pe-strip-item {
  flex-shrink: 0;
  width: 60px;
  height: 42px;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.pe-strip-item:hover {
  border-color: #0078d4;
  transform: scale(1.05);
}

.pe-strip-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#pe-strip-empty {
  color: #8FA0A4;
  font-size: 12px;
  padding: 2px 8px;
}

/* ---- Main area ---- */
#pe-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---- Canvas area ---- */
#pe-canvas-area {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3C4446;
  position: relative;
  min-width: 0;
}

#pe-canvas {
  display: block;
  cursor: default;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  flex-shrink: 0;
  margin: 20px;
  touch-action: none;
}

#pe-img-loading {
  display: none;
  position: absolute;
  bottom: 14px;
  left: 14px;
  align-items: center;
  gap: 7px;
  background: rgba(0, 0, 0, 0.62);
  color: #e8e8e8;
  font-size: 12px;
  padding: 5px 12px 5px 10px;
  border-radius: 20px;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}

#pe-text-input {
  position: absolute;
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  border: 2px dashed rgba(0, 120, 255, 0.85);
  border-radius: 2px;
  padding: 4px 6px;
  resize: none;
  z-index: 100;
  box-sizing: border-box;
  outline: none;
  overflow: hidden;
  line-height: 1.3;
}

/* ---- Right Sidebar ---- */
#pe-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #2A3032;
  border-left: 1px solid #404A4C;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sidebar tab buttons */
#pe-sidebar-tabs {
  display: flex;
  background: #323A3C;
  border-bottom: 1px solid #404A4C;
  flex-shrink: 0;
}

.pe-sidebar-tab {
  flex: 1;
  padding: 8px 2px;
  background: transparent;
  color: #8FA0A4;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  transition: color 0.15s, border-color 0.15s;
}

.pe-sidebar-tab:hover { color: #D0D8DA; }

.pe-sidebar-tab.active {
  color: #fff;
  border-bottom-color: #0078d4;
}

/* Sidebar panels */
.pe-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.pe-panel.active { display: flex; }

.pe-panel::-webkit-scrollbar { width: 5px; }
.pe-panel::-webkit-scrollbar-track { background: transparent; }
.pe-panel::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* ---- Layers Panel ---- */
#pe-layers-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pe-layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  background: #353D3F;
  transition: background 0.1s;
}

.pe-layer-item:hover { background: #404A4C; }

.pe-layer-item.selected {
  background: #1A3D5C;
  border-color: #0078d4;
}

.pe-layer-thumb {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid #555;
}

.pe-layer-swatch {
  width: 100%;
  height: 100%;
}

.pe-layer-img-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pe-layer-text-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: bold;
  background: #222;
}

.pe-layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #D0D8DA;
  font-size: 12px;
}

.pe-layer-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.pe-icon-btn {
  background: transparent;
  border: none;
  color: #8FA0A4;
  padding: 3px 4px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 13px;
  line-height: 1;
  transition: color 0.1s, background 0.1s;
}

.pe-icon-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}

.pe-delete-btn:hover { color: #ff6b6b !important; }

/* ---- Properties Panel ---- */
.pe-prop-empty {
  color: #8FA0A4;
  font-size: 12px;
  padding: 16px 4px;
  text-align: center;
  font-style: italic;
  line-height: 1.5;
}

.pe-prop-group {
  margin-bottom: 12px;
}

.pe-prop-label {
  display: block;
  color: #8FA0A4;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 700;
}

.pe-prop-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pe-prop-unit {
  color: #8FA0A4;
  font-size: 11px;
  min-width: 12px;
  flex-shrink: 0;
}

.pe-prop-input {
  flex: 1;
  min-width: 0;
  background: #353D3F;
  color: #D0D8DA;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 12px;
  -moz-appearance: textfield;
}

.pe-prop-input::-webkit-outer-spin-button,
.pe-prop-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.pe-prop-input:focus { outline: none; border-color: #0078d4; }

.pe-prop-select {
  flex: 1;
  width: 100%;
  background: #353D3F;
  color: #D0D8DA;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 12px;
}

.pe-prop-select:focus { outline: none; border-color: #0078d4; }

.pe-prop-textarea {
  width: 100%;
  background: #353D3F;
  color: #D0D8DA;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 6px;
  font-size: 12px;
  min-height: 60px;
  resize: vertical;
  box-sizing: border-box;
}

.pe-prop-textarea:focus { outline: none; border-color: #0078d4; }

.pe-prop-color {
  width: 32px;
  height: 28px;
  padding: 2px;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.pe-prop-toggle {
  padding: 4px 8px;
  background: #353D3F;
  color: #8FA0A4;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}

.pe-prop-toggle:hover { background: #464D4F; color: #fff; }
.pe-prop-toggle.active { background: #0078d4; border-color: #0063b1; color: #fff; }

/* ---- Background Panel ---- */
#pe-panel-background .nav-tabs {
  border-bottom: 1px solid #404A4C;
  margin: -10px -10px 10px -10px;
  padding: 0 10px;
}

#pe-panel-background .nav-tabs .nav-link {
  color: #8FA0A4;
  border: none;
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
}

#pe-panel-background .nav-tabs .nav-link.active {
  color: #fff;
  background: transparent;
  border-bottom-color: #0078d4;
}

#pe-panel-background .nav-tabs .nav-link:hover { color: #D0D8DA; }

.pe-bg-swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.pe-bg-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.12);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.pe-bg-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  position: relative;
  z-index: 1;
}

.pe-bg-color-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.pe-bg-color-input-row .input-group {
  flex: 1;
  min-width: 0;
}

.pe-bg-gallery-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pe-bg-gallery-item {
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.pe-bg-gallery-item:hover { border-color: #0078d4; }

.pe-bg-gallery-item img {
  width: 100%;
  height: 64px;
  object-fit: cover;
  display: block;
}

.pe-bg-upload-btn-row {
  margin-bottom: 8px;
}

.pe-bg-upload-btn-row label {
  cursor: pointer;
  margin: 0;
}

/* ---- Canvas Size Modal ---- */
#pe-canvas-size-modal .modal-content {
  background: #2A3032;
  color: #D0D8DA;
  border: 1px solid #555;
}

#pe-canvas-size-modal .modal-header {
  background: #323A3C;
  border-bottom: 1px solid #404A4C;
  color: #D0D8DA;
}

#pe-canvas-size-modal .modal-header .close { color: #D0D8DA; }

.pe-size-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.pe-size-preset-btn {
  padding: 10px 8px;
  background: #3C4446;
  color: #D0D8DA;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1.4;
}

.pe-size-preset-btn:hover { background: #464D4F; border-color: #0078d4; color: #fff; }
.pe-size-preset-btn strong { display: block; font-size: 14px; margin-bottom: 2px; }

.pe-size-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.pe-size-custom-row input {
  flex: 1;
  background: #3C4446;
  color: #D0D8DA;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
}

.pe-size-custom-row input:focus { outline: none; border-color: #0078d4; }

.pe-size-custom-row span { color: #8FA0A4; flex-shrink: 0; }

#pe-canvas-size-modal .modal-footer {
  background: #323A3C;
  border-top: 1px solid #404A4C;
}

/* ---- Upload drop zone ---- */
#pe-upload-drop-zone {
  border: 2px dashed #ccc;
  border-radius: 8px;
  padding: 40px 20px;
  text-align: center;
  color: #666;
  background: #fafafa;
  cursor: pointer;
}
#pe-upload-drop-zone:hover {
  border-color: #0078d4;
  background: #f0f6ff;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #pe-main {
    flex-direction: column;
    height: auto;
  }
  #pe-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid #404A4C;
    height: 300px;
  }
  #pe-main {
    min-height: 300px;
  }
  #pe-canvas-area {
    min-height: 300px;
  }
}

/* ---- Touch device improvements ---- */
@media (hover: none) and (pointer: coarse) {
  /* Larger tap targets on toolbar */
  .pe-toolbar-btn {
    padding: 9px 13px;
    font-size: 13px;
  }

  /* Larger layer rows */
  .pe-layer-item {
    padding: 9px 10px;
  }

  /* Larger icon buttons */
  .pe-icon-btn {
    padding: 6px 8px;
    font-size: 16px;
  }

  /* Taller strip items for easier tapping */
  .pe-strip-item {
    width: 72px;
    height: 52px;
  }

  /* Allow natural touch scrolling on strip and panels */
  #pe-photo-strip-inner {
    -webkit-overflow-scrolling: touch;
  }

  .pe-panel {
    -webkit-overflow-scrolling: touch;
  }

  /* Larger swatches */
  .pe-bg-swatch-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  /* Sidebar tabs more tappable */
  .pe-sidebar-tab {
    padding: 11px 2px;
    font-size: 12px;
  }
}

/* Transparency grid for swatches */
.pe-bg-swatch.transparency-grid,
.pe-layer-swatch.transparency-grid {
  background-image: linear-gradient(45deg, #b0b0b0 25%, transparent 25%),
    linear-gradient(-45deg, #b0b0b0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #b0b0b0 75%),
    linear-gradient(-45deg, transparent 75%, #b0b0b0 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-color: #fff;
}

.pe-strip-img.transparency-grid {
  background-image: linear-gradient(45deg, #b0b0b0 25%, transparent 25%),
    linear-gradient(-45deg, #b0b0b0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #b0b0b0 75%),
    linear-gradient(-45deg, transparent 75%, #b0b0b0 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #fff;
}
