/* ============================================================
   GiriTunnel Visual Editor — tunnel-visual-editor.css
   Full-screen overlay editor with toolbar, iframe preview,
   and floating AI prompt panel.
   All classes prefixed .ve- to avoid conflicts.
   ============================================================ */

/* ── Reset & Base ──────────────────────────────────────────── */

.ve-overlay *,
.ve-overlay *::before,
.ve-overlay *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Overlay (fullscreen container) ────────────────────────── */

.ve-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 10000;
  background: #0f0f1a;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #e2e8f0;
  overflow: hidden;
}

.ve-overlay.hidden {
  display: none;
}

/* ── Toolbar ───────────────────────────────────────────────── */

.ve-toolbar {
  position: relative;
  flex-shrink: 0;
  height: 56px;
  background: #0f0f1a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  z-index: 10;
}

/* Toolbar — Left (back + tunnel name) */

.ve-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ve-toolbar-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.ve-toolbar-back:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
}

.ve-toolbar-back svg {
  width: 18px;
  height: 18px;
}

.ve-tunnel-name {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* Toolbar — Center (page tabs) */

.ve-toolbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.ve-page-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 3px;
}

.ve-page-tab {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #94a3b8;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  border: none;
  background: transparent;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.ve-page-tab:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
}

.ve-page-tab.active {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
}

.ve-page-tab-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.ve-page-tab-label {
  line-height: 1;
}

/* Toolbar — Right (device toggle, undo/redo, save) */

.ve-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ve-toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  min-width: 36px;
  padding: 0 8px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 13px;
  font-weight: 500;
  gap: 6px;
}

.ve-toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
}

.ve-toolbar-btn.active {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
}

.ve-toolbar-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ve-toolbar-btn:disabled:hover {
  background: transparent;
  color: #94a3b8;
}

.ve-toolbar-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.ve-toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 4px;
}

.ve-save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #ffffff;
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.25);
}

.ve-save-btn:hover {
  opacity: 0.92;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.35);
}

.ve-save-btn:active {
  transform: scale(0.97);
}

.ve-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ve-save-btn svg {
  width: 14px;
  height: 14px;
}

/* ── Main Area ─────────────────────────────────────────────── */

.ve-main {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ── Preview Container ─────────────────────────────────────── */

.ve-preview-container {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  background: #0a0a12;
  overflow: auto;
  position: relative;
}

.ve-device-frame {
  position: relative;
  margin: 0 auto;
  transition: width 0.3s ease, max-width 0.3s ease;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 8px 40px rgba(0, 0, 0, 0.5),
    0 2px 12px rgba(0, 0, 0, 0.3);
  height: calc(100vh - 56px - 32px); /* full height minus toolbar and padding */
}

/* Device modes */

.ve-device-desktop .ve-device-frame {
  width: 100%;
  max-width: 100%;
}

.ve-device-tablet .ve-device-frame {
  width: 768px;
  max-width: 100%;
}

.ve-device-mobile .ve-device-frame {
  width: 375px;
  max-width: 100%;
}

/* Iframe */

.ve-preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #ffffff;
}

/* Device frame notch decoration (optional, for mobile) */

.ve-device-mobile .ve-device-frame::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 4px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 0 0 4px 4px;
  z-index: 5;
  pointer-events: none;
}

/* ── Floating Prompt Panel ─────────────────────────────────── */

.ve-prompt-panel {
  position: absolute;
  z-index: 100;
  width: 380px;
  max-height: 480px;
  background: #1a1a2e;
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 16px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 8px 24px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(139, 92, 246, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ve-panel-appear 0.2s ease-out;
}

.ve-prompt-panel.hidden {
  display: none;
}

@keyframes ve-panel-appear {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Panel — Header */

.ve-prompt-header {
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.ve-prompt-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ve-prompt-element-label {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ve-prompt-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ve-prompt-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
}

.ve-prompt-close svg {
  width: 14px;
  height: 14px;
}

.ve-prompt-current-value {
  font-size: 13px;
  line-height: 1.5;
  color: #e2e8f0;
  max-height: 60px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  position: relative;
}

.ve-prompt-current-value::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20px;
  background: linear-gradient(transparent, rgba(26, 26, 46, 0.9));
  pointer-events: none;
}

/* Panel — Quick Actions */

.ve-prompt-quick-actions {
  padding: 0 16px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ve-quick-btn {
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.ve-quick-btn:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: rgba(139, 92, 246, 0.35);
  color: #ddd6fe;
}

.ve-quick-btn:active {
  transform: scale(0.97);
}

/* Panel — Input Area */

.ve-prompt-input-area {
  padding: 16px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.ve-prompt-input {
  flex: 1;
  background: #13131f;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 14px;
  color: #e2e8f0;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.ve-prompt-input::placeholder {
  color: #64748b;
}

.ve-prompt-input:focus {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.ve-prompt-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #8b5cf6;
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.ve-prompt-send-btn:hover {
  background: #7c3aed;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.ve-prompt-send-btn:active {
  transform: scale(0.95);
}

.ve-prompt-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ve-prompt-send-btn svg {
  width: 18px;
  height: 18px;
}

/* Panel — Result Area */

.ve-prompt-result {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  overflow-y: auto;
}

.ve-prompt-result-preview {
  font-size: 13px;
  line-height: 1.6;
  color: #cbd5e1;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  max-height: 120px;
  overflow-y: auto;
}

.ve-prompt-result-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ve-result-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
  border: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ve-result-btn:hover {
  opacity: 0.88;
}

.ve-result-btn:active {
  transform: scale(0.97);
}

.ve-result-btn.accept {
  background: #10b981;
  color: #ffffff;
}

.ve-result-btn.undo {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.ve-result-btn.retry {
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ve-result-btn svg {
  width: 14px;
  height: 14px;
}

/* ── Loading State ─────────────────────────────────────────── */

.ve-prompt-loading {
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.ve-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: ve-spin 0.6s linear infinite;
}

@keyframes ve-spin {
  to {
    transform: rotate(360deg);
  }
}

.ve-loading-text {
  font-size: 13px;
  color: #94a3b8;
}

/* ── Status Indicators ─────────────────────────────────────── */

.ve-status {
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ve-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ve-status-saved {
  color: #10b981;
}

.ve-status-saved .ve-status-dot {
  background: #10b981;
}

.ve-status-saving {
  color: #f59e0b;
}

.ve-status-saving .ve-status-dot {
  background: #f59e0b;
  animation: ve-pulse 1s ease-in-out infinite;
}

.ve-status-error {
  color: #ef4444;
}

.ve-status-error .ve-status-dot {
  background: #ef4444;
}

@keyframes ve-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ── Highlight Overlay (shown on hovered/selected element in iframe) ── */

.ve-highlight-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  border: 2px solid #8b5cf6;
  border-radius: 4px;
  background: rgba(139, 92, 246, 0.08);
  transition: transform 0.15s ease-out, background 0.15s ease-out, border-color 0.15s ease-out, color 0.15s ease-out, opacity 0.15s ease-out;
}

.ve-highlight-label {
  position: absolute;
  top: -22px;
  left: 0;
  font-size: 10px;
  font-weight: 600;
  color: #ffffff;
  background: #8b5cf6;
  padding: 2px 8px;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.3px;
}

/* ── Empty State ───────────────────────────────────────────── */

.ve-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #64748b;
  text-align: center;
  padding: 40px;
}

.ve-empty-state-icon {
  width: 56px;
  height: 56px;
  color: #4a4a6a;
  margin-bottom: 16px;
}

.ve-empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 8px;
}

.ve-empty-state-text {
  font-size: 14px;
  line-height: 1.5;
  max-width: 320px;
}

/* ── Undo Toast ────────────────────────────────────────────── */

.ve-undo-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1a2e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 10100;
  opacity: 0;
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
  pointer-events: none;
}

.ve-undo-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.ve-undo-toast-text {
  font-size: 13px;
  color: #e2e8f0;
}

.ve-undo-toast-btn {
  font-size: 13px;
  font-weight: 600;
  color: #8b5cf6;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.ve-undo-toast-btn:hover {
  background: rgba(139, 92, 246, 0.15);
}

/* ── Keyboard Shortcut Hints ───────────────────────────────── */

.ve-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: #94a3b8;
  line-height: 1;
}

/* ── Tooltip ───────────────────────────────────────────────── */

.ve-tooltip {
  position: absolute;
  z-index: 10200;
  padding: 6px 10px;
  background: #2a2a40;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  font-size: 12px;
  color: #e2e8f0;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.ve-tooltip.visible {
  opacity: 1;
}

/* ── Custom Scrollbar (scoped, not on *) ───────────────────── */

.ve-prompt-panel,
.ve-prompt-result,
.ve-prompt-current-value,
.ve-preview-container {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.ve-prompt-panel::-webkit-scrollbar,
.ve-prompt-result::-webkit-scrollbar,
.ve-prompt-current-value::-webkit-scrollbar,
.ve-preview-container::-webkit-scrollbar {
  width: 6px;
}

.ve-prompt-panel::-webkit-scrollbar-track,
.ve-prompt-result::-webkit-scrollbar-track,
.ve-prompt-current-value::-webkit-scrollbar-track,
.ve-preview-container::-webkit-scrollbar-track {
  background: transparent;
}

.ve-prompt-panel::-webkit-scrollbar-thumb,
.ve-prompt-result::-webkit-scrollbar-thumb,
.ve-prompt-current-value::-webkit-scrollbar-thumb,
.ve-preview-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.ve-prompt-panel::-webkit-scrollbar-thumb:hover,
.ve-prompt-result::-webkit-scrollbar-thumb:hover,
.ve-prompt-current-value::-webkit-scrollbar-thumb:hover,
.ve-preview-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {

  /* Prompt panel becomes bottom sheet */
  .ve-prompt-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    animation: ve-slide-up 0.25s ease-out;
  }

  @keyframes ve-slide-up {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Page tabs: hide labels, show icons only */
  .ve-page-tab-label {
    display: none;
  }

  .ve-page-tab {
    padding: 6px 10px;
  }

  /* Tunnel name shrink */
  .ve-tunnel-name {
    max-width: 120px;
    font-size: 13px;
  }

  /* Save button compact */
  .ve-save-btn {
    padding: 8px 14px;
    font-size: 12px;
  }

  /* Toolbar tighter */
  .ve-toolbar {
    padding: 0 10px;
    gap: 4px;
  }

  .ve-toolbar-right {
    gap: 4px;
  }

  /* Device frame fills width */
  .ve-device-frame {
    border-radius: 0;
  }

  .ve-preview-container {
    padding: 0;
  }

  /* Hide undo/redo on very small screens */
  .ve-toolbar-divider {
    display: none;
  }
}

@media (max-width: 480px) {

  .ve-toolbar-center {
    position: relative;
    left: auto;
    transform: none;
  }

  .ve-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .ve-page-tab {
    padding: 6px 8px;
  }

  .ve-page-tab-icon {
    width: 16px;
    height: 16px;
  }
}

/* ── Print: hide everything ────────────────────────────────── */

@media print {
  .ve-overlay {
    display: none !important;
  }
}
