/* ========== Inline Editor Bar ========== */
.inline-editor-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #e0e0e0;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  box-shadow: 0 2px 20px rgba(0,0,0,0.5);
  border-bottom: 2px solid #f0c040;
  transition: transform 0.3s ease;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 40px;
}
.inline-editor-bar.edit-mode-off {
  transform: translateY(-100%);
  transition: transform 0.35s ease;
}
.inline-editor-bar.edit-mode-off::after {
  content: '⚙ Режим';
  position: fixed;
  top: 0;
  right: 20px;
  background: #1a1a2e;
  color: #f0c040;
  font-family: 'Montserrat', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px 5px;
  border-radius: 0 0 6px 6px;
  cursor: pointer;
  z-index: 99998;
  border: 1px solid #f0c040;
  border-top: none;
  opacity: 0.6;
  transition: opacity 0.2s;
  pointer-events: auto;
}
.inline-editor-bar.edit-mode-off:hover::after { opacity: 1; }
.inline-editor-bar.edit-mode-off:hover { transform: translateY(0); }
.inline-editor-bar.edit-mode-on { transform: translateY(0); }
.inline-editor-bar.edit-mode-on { transform: translateY(0); }

.ie-bar-left, .ie-bar-center, .ie-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ie-user-badge { color: #f0c040; font-weight: 600; font-size: 12px; }
.ie-role-badge {
  background: rgba(240,192,64,0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  text-transform: uppercase;
  color: #f0c040;
}
.ie-sep { color: #555; font-size: 11px; }

/* Toggle Switch */
.ie-toggle-label {
  font-size: 12px;
  font-weight: 500;
  transition: color 0.2s;
  cursor: pointer;
  user-select: none;
}
.ie-toggle-label.active { color: #f0c040; }
.ie-toggle-label:not(.active) { color: #888; }
.ie-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
  cursor: pointer;
}
.ie-switch input { opacity: 0; width: 0; height: 0; }
.ie-slider {
  position: absolute;
  inset: 0;
  background: #444;
  border-radius: 22px;
  transition: 0.3s;
}
.ie-slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}
.ie-switch input:checked + .ie-slider { background: #f0c040; }
.ie-switch input:checked + .ie-slider::before { transform: translateX(22px); }

/* Save Button */
.ie-save-btn {
  background: #27ae60;
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ie-save-btn:hover { background: #2ecc71; }
.ie-save-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.ie-save-btn.saving { background: #f39c12; pointer-events: none; }
.ie-save-btn.saved { background: #2980b9; }
.ie-save-btn.error { background: #e74c3c; }

/* Builder & Logout links */
.ie-builder-link, .ie-logout-link {
  color: #888;
  font-size: 16px;
  transition: color 0.2s;
  text-decoration: none;
}
.ie-builder-link:hover { color: #f0c040; }
.ie-logout-link:hover { color: #e74c3c; }

/* Save status flash */
.ie-save-status {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: #27ae60;
  color: #fff;
  padding: 4px 16px;
  border-radius: 0 0 6px 6px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.ie-save-status.show { opacity: 1; }
.ie-save-status.error { background: #e74c3c; }

/* ========== Edit Mode Highlights ========== */
body.ie-editing [data-editable] {
  outline: 2px dashed rgba(240, 192, 64, 0.5);
  outline-offset: 2px;
  cursor: text;
  transition: outline-color 0.2s;
  border-radius: 2px;
  position: relative;
}
body.ie-editing [data-editable]:hover {
  outline-color: #f0c040;
}
body.ie-editing [data-editable]:focus {
  outline: 2px solid #f0c040;
  background: rgba(240, 192, 64, 0.05);
  box-shadow: 0 0 0 4px rgba(240, 192, 64, 0.08);
}
body.ie-editing [data-editable].ie-modified {
  outline-color: #27ae60;
  background: rgba(39, 174, 96, 0.05);
}

/* PHP Block Protection */
body.ie-editing [data-php-block] {
  position: relative;
  outline: 2px dashed #e74c3c;
  outline-offset: 2px;
  opacity: 0.85;
  user-select: none;
  cursor: not-allowed;
  border-radius: 2px;
}
body.ie-editing [data-php-block]::after {
  content: '🔒 PHP';
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(231, 76, 60, 0.9);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Montserrat', sans-serif;
  z-index: 10;
  pointer-events: none;
  letter-spacing: 0.5px;
}
body.ie-editing [data-php-block] .ie-php-overlay {
  position: absolute;
  inset: 0;
  background: rgba(231, 76, 60, 0.08);
  z-index: 5;
  pointer-events: none;
  border-radius: 2px;
}

/* JSON edit button trigger */
body.ie-editing [data-json] {
  position: relative;
  outline: 2px dashed rgba(52, 152, 219, 0.5);
  outline-offset: 2px;
  cursor: pointer;
  border-radius: 2px;
}
body.ie-editing [data-json]:hover {
  outline-color: #3498db;
}
body.ie-editing [data-json].ie-modified {
  outline-color: #27ae60;
  background: rgba(39, 174, 96, 0.05);
}

/* JSON editor popup */
.ie-json-popup {
  position: fixed;
  z-index: 100000;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 30px rgba(0,0,0,0.3);
  padding: 16px;
  min-width: 320px;
  max-width: 500px;
  font-family: 'Montserrat', sans-serif;
}
.ie-json-popup .ie-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.ie-json-popup .ie-popup-header strong {
  font-size: 14px;
  color: #333;
}
.ie-json-popup .ie-popup-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  line-height: 1;
}
.ie-json-popup .ie-popup-close:hover { color: #333; }
.ie-json-popup textarea {
  width: 100%;
  min-height: 80px;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
.ie-json-popup .ie-popup-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}
.ie-json-popup .ie-popup-actions button {
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.ie-json-popup .ie-popup-save {
  background: #27ae60;
  color: #fff;
}
.ie-json-popup .ie-popup-save:hover { background: #2ecc71; }
.ie-json-popup .ie-popup-cancel {
  background: #eee;
  color: #555;
}
.ie-json-popup .ie-popup-cancel:hover { background: #ddd; }

/* ========== Image Context Menu ========== */
.ie-ctx-menu {
  position: fixed;
  z-index: 100010;
  background: #1e1e2e;
  border: 1px solid #333;
  border-radius: 8px;
  min-width: 200px;
  padding: 4px 0;
  font-family: 'Montserrat', sans-serif;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: ie-ctx-in 0.15s ease-out;
}
@keyframes ie-ctx-in {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.ie-ctx-header {
  padding: 8px 14px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  border-bottom: 1px solid #333;
}
.ie-ctx-item {
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #e0e0e0;
  transition: background 0.15s;
}
.ie-ctx-item:hover { background: rgba(240, 192, 64, 0.12); color: #f0c040; }
.ie-ctx-item i { width: 16px; text-align: center; font-size: 12px; color: #888; }
.ie-ctx-item:hover i { color: #f0c040; }
.ie-ctx-danger { color: #e74c3c; }
.ie-ctx-danger:hover { background: rgba(231, 76, 60, 0.12); color: #ff6b6b; }
.ie-ctx-danger:hover i { color: #ff6b6b; }
.ie-ctx-sep { height: 1px; background: #333; margin: 4px 0; }

/* Image highlight in edit mode */
body.ie-editing img.ie-img-ctx,
body.ie-editing .ie-bg-ctx {
  outline: 2px dashed rgba(240, 192, 64, 0.3);
  outline-offset: 1px;
  cursor: pointer;
  transition: outline-color 0.2s;
}
body.ie-editing img.ie-img-ctx:hover,
body.ie-editing .ie-bg-ctx:hover {
  outline-color: #f0c040;
  filter: brightness(1.05);
}
body.ie-editing img.ie-img-ctx.ie-modified,
body.ie-editing .ie-bg-ctx.ie-modified {
  outline-color: #27ae60;
}
body.ie-editing .ie-bg-ctx.ie-bg-changed {
  outline: 3px solid #3498db;
  outline-offset: 2px;
}

/* ========== Gallery Browser Modal ========== */
.ie-gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 100020;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: ie-overlay-in 0.2s ease-out;
}
@keyframes ie-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.ie-gallery-modal {
  background: #1a1a2e;
  border: 1px solid #333;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  animation: ie-modal-in 0.25s ease-out;
}
@keyframes ie-modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.ie-gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #333;
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #e0e0e0;
}
.ie-gallery-header i { color: #f0c040; margin-right: 8px; }
.ie-gallery-close {
  background: none;
  border: none;
  font-size: 22px;
  color: #888;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.ie-gallery-close:hover { color: #fff; }
.ie-gallery-uploadbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: #12121e;
  border-bottom: 1px solid #333;
  font-family: 'Montserrat', sans-serif;
  font-size: 12px;
  flex-wrap: wrap;
}
.ie-gallery-uploadbar span { color: #888; white-space: nowrap; }
.ie-gallery-uploadbar span i { color: #f0c040; margin-right: 4px; }
.ie-gallery-uploadbar select {
  background: #1a1a2e;
  border: 1px solid #444;
  border-radius: 4px;
  color: #ddd;
  padding: 5px 8px;
  font-size: 12px;
  min-width: 140px;
}
.ie-upload-btn {
  background: #555;
  border: none;
  color: #ccc;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.2s;
}
.ie-upload-btn:hover { background: #666; color: #fff; }
.ie-upload-status { font-size: 11px; color: #888; white-space: nowrap; }
.ie-gallery-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
}
.ie-gallery-loading, .ie-gallery-empty {
  text-align: center;
  color: #888;
  padding: 40px 20px;
  font-family: 'Montserrat', sans-serif;
}
.ie-gallery-empty i { font-size: 40px; display: block; margin-bottom: 12px; color: #555; }
.ie-gallery-section { margin-bottom: 16px; }
.ie-gallery-section-title {
  font-size: 12px;
  font-weight: 700;
  color: #aaa;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ie-gallery-section-title i { color: #f0c040; margin-right: 6px; }
.ie-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 6px;
}
.ie-gallery-item {
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s, transform 0.15s;
  aspect-ratio: 1;
}
.ie-gallery-item:hover {
  border-color: #f0c040;
  transform: scale(1.03);
}
.ie-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ie-gallery-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-top: 1px solid #333;
  gap: 8px;
}
.ie-gallery-selected-name {
  font-size: 11px;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.ie-gallery-cancel {
  background: #333;
  color: #ccc;
  border: none;
  padding: 7px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
}
.ie-gallery-cancel:hover { background: #444; color: #fff; }
.ie-gallery-replace {
  background: #555;
  color: #888;
  border: none;
  padding: 7px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: not-allowed;
  font-family: 'Montserrat', sans-serif;
}
.ie-gallery-replace:not(:disabled) {
  background: #f0c040;
  color: #000;
  cursor: pointer;
}
.ie-gallery-replace:not(:disabled):hover {
  background: #e0b030;
}

/* ========== Floating per-image save button ========== */
.ie-float-save-btn {
  position: fixed;
  z-index: 100000;
  background: rgba(39,174,96,0.85);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.9);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transition: transform .15s, background .15s, opacity .15s;
  opacity: 0.85;
  padding: 0;
  line-height: 1;
}
.ie-float-save-btn:hover {
  transform: scale(1.15);
  background: #27ae60;
  opacity: 1;
}
.ie-float-save-btn:active {
  transform: scale(0.95);
}
.ie-float-save-btn:disabled {
  opacity: 0.5;
  cursor: wait;
  transform: none;
}

/* ========== Undo Toast ========== */
.ie-undo-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 100000;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  color: #e0e0e0;
  animation: ie-toast-in 0.3s ease;
}
@keyframes ie-toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.ie-undo-btn {
  background: #f0c040;
  color: #1a1a2e;
  border: none;
  padding: 5px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  font-family: inherit;
  transition: background 0.15s;
}
.ie-undo-btn:hover { background: #f5d060; }

/* Body padding when editor bar is visible */
body.ie-editing { padding-top: 40px; }
.inline-editor-bar.edit-mode-on + * { margin-top: 0; }

/* Responsive inline editor */
@media(max-width:768px){
  #ie-bar{flex-wrap:wrap;gap:4px;padding:4px 8px;height:auto;min-height:36px;}
  #ie-bar button{font-size:11px;padding:3px 6px;}
  #ie-bar .ie-group-title{font-size:9px;padding:2px 6px;}
  .ie-gallery-palette{max-width:90vw;max-height:60vh;}
  .ie-gallery-palette .item img{width:60px;height:45px;}
  .ie-context-menu{font-size:12px;min-width:160px;}
  .ie-context-menu .ctx-item{padding:6px 10px;font-size:11px;}
  .ie-undo-toast{font-size:12px;padding:8px 16px;gap:10px;bottom:16px;width:auto;left:16px;right:16px;transform:none;}
}
@media(max-width:480px){
  #ie-bar{justify-content:center;}
  #ie-bar .ie-group-title{display:none;}
  #ie-bar button span{display:none;}
  body.ie-editing{padding-top:36px;}
}
