/* ============================================================================
   PORTAL — Hibrit Drag-Drop + AI
   ============================================================================ */

.portal-hero {
  background: linear-gradient(135deg, #1a1a1a 0%, #2d2419 100%);
  color: #fff;
  padding: 80px 0 60px;
  text-align: center;
}
.portal-hero h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0 0 12px;
  font-weight: 500;
}
.lang-ar .portal-hero h1 { font-family: 'Amiri', serif; }
.portal-hero p {
  opacity: 0.85;
  max-width: 640px;
  margin: 0 auto;
}

.portal-app {
  background: #f4f1ea;
  min-height: calc(100vh - 200px);
  padding: 24px 0 60px;
}

.portal-layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  height: calc(100vh - 280px);
  min-height: 600px;
}

/* SIDEBAR */
.portal-sidebar {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  padding: 16px;
  border-bottom: 1px solid #ece8e0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-head input,
.sidebar-head select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}
.sidebar-head input:focus,
.sidebar-head select:focus {
  outline: none;
  border-color: #b08a4f;
}

.product-library {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  align-content: start;
}

.library-item {
  background: #faf8f3;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px;
  cursor: grab;
  transition: all 0.2s;
  text-align: center;
  user-select: none;
}
.library-item:hover {
  border-color: #b08a4f;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(176,138,79,0.2);
}
.library-item:active { cursor: grabbing; }
.library-item img {
  width: 100%;
  height: 70px;
  object-fit: contain;
  margin-bottom: 6px;
  pointer-events: none;
}
.library-item span {
  display: block;
  font-size: 0.78rem;
  color: #4a3f30;
  line-height: 1.3;
  font-weight: 500;
}
.library-item.hidden { display: none; }

/* CANVAS AREA */
.portal-canvas-area {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-toolbar {
  padding: 14px 20px;
  border-bottom: 1px solid #ece8e0;
  display: flex;
  align-items: center;
  gap: 16px;
  background: #faf8f3;
  flex-wrap: wrap;
}

.upload-btn {
  background: #2d2419;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.2s;
}
.upload-btn:hover { background: #1a1a1a; }

.canvas-hint {
  flex: 1;
  color: #7a6f5e;
  font-size: 0.88rem;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}
.toolbar-actions button {
  background: #fff;
  border: 1px solid #ddd;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.toolbar-actions button:hover:not(:disabled) {
  border-color: #b08a4f;
  background: #faf8f3;
}
.toolbar-actions button:disabled { opacity: 0.4; cursor: not-allowed; }

/* CANVAS */
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #ece8e0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-empty {
  text-align: center;
  color: #7a6f5e;
  padding: 40px;
}
.canvas-empty .empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.4;
}
.canvas-empty p {
  font-size: 1.1rem;
  margin: 0 0 4px;
  font-weight: 500;
}
.canvas-empty small { opacity: 0.7; }

.canvas-stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: inline-block;
}
.canvas-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.placements {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.placement {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  border: 2px dashed transparent;
  transition: border-color 0.15s;
  user-select: none;
}
.placement:hover,
.placement.selected {
  border-color: #b08a4f;
}
.placement img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.placement .resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #b08a4f;
  border: 2px solid #fff;
  border-radius: 50%;
  bottom: -7px;
  right: -7px;
  cursor: nwse-resize;
}
.placement .delete-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  background: #d44;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: none;
  line-height: 1;
}
.placement.selected .delete-btn { display: flex; align-items: center; justify-content: center; }

/* AI RESULT */
.ai-result {
  position: absolute;
  inset: 0;
  background: #ece8e0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-result img {
  max-width: 100%;
  max-height: calc(100% - 60px);
  object-fit: contain;
}
.ai-result-toolbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(255,255,255,0.95);
  padding: 8px 14px;
  border-radius: 100px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

/* AI LOADING */
.ai-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.ai-spinner {
  width: 64px;
  height: 64px;
  border: 4px solid #ece8e0;
  border-top-color: #b08a4f;
  border-radius: 50%;
  animation: aispin 1s linear infinite;
  margin-bottom: 20px;
}
@keyframes aispin { to { transform: rotate(360deg); } }
.ai-loading p {
  font-size: 1rem;
  color: #4a3f30;
  font-weight: 500;
}

/* BOTTOM BAR */
.canvas-bottom-bar {
  padding: 14px 20px;
  border-top: 1px solid #ece8e0;
  background: #faf8f3;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-ai {
  background: linear-gradient(135deg, #b08a4f 0%, #d4a861 100%);
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(176,138,79,0.3);
}
.btn-ai:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(176,138,79,0.4);
}
.btn-ai:disabled {
  background: #ddd;
  color: #999;
  box-shadow: none;
  cursor: not-allowed;
}

/* MODAL */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.active { display: flex; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
.modal-content {
  position: relative;
  background: #fff;
  border-radius: 16px;
  max-width: 600px;
  width: calc(100% - 32px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-content.small { max-width: 420px; text-align: center; }
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  font-size: 26px;
  cursor: pointer;
  color: #7a6f5e;
}
.modal-content h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.6rem;
  margin: 0 0 8px;
  color: #2d2419;
}
.lang-ar .modal-content h2 { font-family: 'Amiri', serif; }
.modal-content p { color: #7a6f5e; margin: 0 0 20px; }
.modal-content .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-content .form-group { margin-bottom: 14px; }
.modal-content label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #4a3f30;
  margin-bottom: 6px;
}
.modal-content input,
.modal-content textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
}
.modal-content input:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: #b08a4f;
}
.success-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
  color: #fff;
  border-radius: 50%;
  font-size: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
  .portal-layout { grid-template-columns: 260px 1fr; }
}
@media (max-width: 768px) {
  .portal-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .portal-sidebar {
    height: 320px;
    order: 2;
  }
  .portal-canvas-area {
    height: 60vh;
    min-height: 400px;
  }
  .modal-content .form-row { grid-template-columns: 1fr; }
}

/* RTL adjustments */
[dir="rtl"] .placement .delete-btn { right: auto; left: -10px; }
[dir="rtl"] .placement .resize-handle { right: auto; left: -7px; }
