/**
 * استایل بوم گرید کارت — embedded در صفحه اصلی ModuleHub
 * Card canvas styles — absolute grid inside home page layout.
 */

.card-canvas {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: var(--card-canvas-min-height, 280px);
  margin: 0 auto;
  padding: 0 2rem 2rem;
  touch-action: pan-y;
  overflow: hidden;
  border-radius: 1.25rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(45, 90, 130, 0.12), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 100%);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.card-canvas--edit-mode {
  touch-action: none;
}

body.dark .card-canvas {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(45, 90, 130, 0.2), transparent 70%),
    linear-gradient(180deg, rgba(15, 23, 42, 0.5) 0%, rgba(15, 23, 42, 0.2) 100%);
}

.card-canvas--navigating {
  opacity: 0.92;
  transform: scale(0.99);
}

.ghost-layer,
.cards-wrapper {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ghost-layer {
  z-index: 5;
}

.cards-wrapper {
  z-index: 10;
  pointer-events: none;
}

.cards-wrapper .card-canvas-item,
.cards-wrapper .back-card {
  pointer-events: auto;
}

.snap-ghost {
  display: none;
  position: absolute;
  border: 2px dashed rgba(255, 200, 90, 0.9);
  border-radius: 18px;
  background: rgba(255, 200, 90, 0.07);
  box-shadow: 0 0 0 1px rgba(255, 200, 90, 0.2);
  transition:
    left 0.2s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.2s cubic-bezier(0.22, 1, 0.36, 1),
    width 0.2s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.card-canvas-item,
.card-canvas .back-card {
  position: absolute;
  margin: 0;
  min-height: 0;
  transition:
    left 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    width 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.card-canvas .card-canvas-item:hover,
.card-canvas .back-card:hover {
  transform: translateY(-4px) scale(1.01);
  border-color: #06b6d4;
  box-shadow: var(--card-hover-shadow), 0 0 15px rgba(6, 182, 212, 0.2);
}

.card-canvas--edit-mode .card-canvas-item {
  cursor: grab;
}

.card-canvas-item.is-dragging,
.card-canvas-item.is-resizing,
.card-canvas-item.is-settling {
  will-change: left, top, width, height;
}

.card-canvas-item.is-dragging,
.card-canvas-item.is-resizing {
  cursor: grabbing;
  transform: scale(1.01);
  z-index: 30;
  transition: none;
  box-shadow: 0 0 0 2px rgba(255, 220, 100, 0.85), 0 22px 40px -14px rgba(0, 0, 0, 0.35);
}

.card-canvas-item.is-settling {
  z-index: 25;
}

.card-canvas-item.snap-preview {
  outline: 2px dashed rgba(255, 210, 90, 0.75);
  outline-offset: 3px;
}

.card-canvas-item .card-content {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0.9rem 2.2rem;
}

.card-canvas-item .card-title {
  font-size: clamp(0.75rem, 2vw, 1.05rem);
  margin-bottom: 4px;
}

.card-canvas-item .card-desc {
  font-size: clamp(0.65rem, 1.8vw, 0.78rem);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.card-resource-hint {
  font-size: 0.6rem;
  margin-top: 4px;
  color: var(--text-secondary);
}

.card-canvas-item.card--edit-mode .gear-icon {
  display: none;
}

.card-canvas-item .card-bg-btn {
  font-size: 0.85rem;
  color: #66819b;
  background: var(--gear-bg);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: 0.2s;
  pointer-events: auto;
}

.card-canvas-item .card-bg-btn:hover {
  background: var(--gear-hover);
  color: #1f3f57;
}

/* Physical bottom-left — grid snap uses LTR pixel coords, not logical RTL edges */
.resize-handle {
  position: absolute;
  left: 4px;
  bottom: 4px;
  width: 21px;
  height: 21px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: rgba(100, 130, 155, 0.75);
  cursor: nesw-resize;
  z-index: 25;
  display: block;
  line-height: 0;
  pointer-events: auto;
  box-shadow: none;
}

.resize-handle:hover,
.resize-handle:focus-visible {
  background: transparent;
  color: rgba(6, 182, 212, 0.95);
  outline: none;
}

body.dark .resize-handle {
  color: rgba(180, 210, 230, 0.7);
}

body.dark .resize-handle:hover,
body.dark .resize-handle:focus-visible {
  color: rgba(94, 234, 212, 0.95);
}

.resize-icon {
  display: block;
  width: 21px;
  height: 21px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  fill: none;
  pointer-events: none;
}

.card-canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
  pointer-events: none;
}

.card-canvas-height-handle {
  position: absolute;
  left: 50%;
  bottom: 6px;
  z-index: 50;
  width: 72px;
  height: 20px;
  margin-left: -36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  color: rgba(148, 163, 184, 0.85);
  pointer-events: auto;
  touch-action: none;
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease;
}

.card-canvas-height-handle:hover,
.card-canvas-height-handle.is-dragging {
  color: #06b6d4;
  background: rgba(6, 182, 212, 0.08);
}

.card-canvas-height-handle svg {
  width: 48px;
  height: 12px;
}

.card-canvas-height-handle line {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

@media (max-width: 640px) {
  .card-canvas {
    padding: 0 1rem 1.5rem;
    --card-canvas-min-height: 220px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-canvas .card-canvas-item:hover,
  .card-canvas .back-card:hover {
    transform: none;
  }
  .card-canvas--navigating {
    opacity: 1;
    transform: none;
  }
}
