/* madaf-shelf-planner — planner.css v1.2.0 */

/* ── Layout ──────────────────────────────────────────── */
.madaf-sp-wrap {
    display: grid;
    grid-template-columns: 220px 1fr 260px;
    gap: 16px;
    direction: rtl;
    font-family: inherit;
    box-sizing: border-box;
    --sp-cell: 24px;
}

.madaf-sp-sidebar {
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 72vh;
}

.madaf-sp-main {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.madaf-sp-summary {
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Inputs bar ──────────────────────────────────────── */
.madaf-sp-inputs {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.madaf-sp-input-label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: #374151;
    gap: 3px;
}

.madaf-sp-input-label input {
    width: 70px;
    padding: 5px 8px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    font-size: 14px;
    text-align: center;
    direction: ltr;
}

.madaf-sp-input-label input:focus {
    outline: 2px solid #3B82F6;
    border-color: transparent;
}

.madaf-sp-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-right: auto;
}

.madaf-sp-scale-label {
    font-size: 11px;
    color: #9CA3AF;
}

/* ── Buttons ─────────────────────────────────────────── */
.madaf-sp-undo-btn,
.madaf-sp-clear-btn,
.madaf-sp-rotate-btn,
.madaf-sp-door-btn,
.madaf-sp-pillar-btn {
    padding: 6px 10px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
    white-space: nowrap;
}

.madaf-sp-undo-btn:hover,
.madaf-sp-clear-btn:hover,
.madaf-sp-rotate-btn:hover:not(:disabled),
.madaf-sp-door-btn:hover,
.madaf-sp-pillar-btn:hover {
    background: #F3F4F6;
    border-color: #9CA3AF;
}

.madaf-sp-rotate-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.madaf-sp-rotate-btn.rotated {
    background: #EFF6FF;
    border-color: #3B82F6;
    color: #1D4ED8;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}

.madaf-sp-door-btn.active {
    background: #FEF3C7;
    border-color: #F59E0B;
    color: #92400E;
    box-shadow: 0 0 0 2px rgba(245,158,11,0.2);
}

/* ── Grid area ───────────────────────────────────────── */
.madaf-sp-grid-scroll {
    overflow: auto;
    max-height: 62vh;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
}

/* CRITICAL: direction ltr so cell c=0 is always on the LEFT
   matching the overlay pixel-math (left = c * step) */
.madaf-sp-grid-wrap {
    position: relative;
    width: fit-content;
    direction: ltr;
}

.madaf-sp-grid {
    display: grid;
    gap: 1px;
    background: #D1D5DB;
    width: fit-content;
    user-select: none;
    direction: ltr;
}

/* Overlay layer sits on top of grid — pointer-events:none so clicks reach cells */
.madaf-sp-overlay-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
    direction: ltr;
}

/* ── Cells ───────────────────────────────────────────── */
.madaf-sp-cell {
    width:  var(--sp-cell, 24px);
    height: var(--sp-cell, 24px);
    background: #fff;
    cursor: crosshair;
    box-sizing: border-box;
    transition: background 0.07s;
}

/* Border (wall) cells — always subtly distinct so user sees the walls */
.madaf-sp-cell.border:not(.occupied):not(.door) {
    background: #F8F9FA;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.07);
}

.madaf-sp-cell.occupied {
    cursor: pointer;
    background: rgba(0,0,0,0.04);
}

/* Hover preview — footprint ghost before click */
.madaf-sp-cell.preview-ok {
    background: rgba(59, 130, 246, 0.22) !important;
    outline: 1px solid rgba(59, 130, 246, 0.55);
    outline-offset: -1px;
    cursor: copy;
}

.madaf-sp-cell.preview-bad {
    background: rgba(239, 68, 68, 0.18) !important;
    outline: 1px solid rgba(239, 68, 68, 0.45);
    outline-offset: -1px;
    cursor: not-allowed;
}

/* Door cells — diagonal stripe */
.madaf-sp-cell.door {
    background: repeating-linear-gradient(
        45deg,
        #FEF3C7 0px, #FEF3C7 4px,
        #FDE68A 4px, #FDE68A 8px
    );
    cursor: pointer;
}

/* Door mode: highlight clickable border cells more strongly */
.madaf-sp-wrap.door-mode .madaf-sp-cell.border:not(.door):not(.occupied) {
    background: rgba(245, 158, 11, 0.18);
    outline: 1px dashed #F59E0B;
    outline-offset: -1px;
    cursor: cell;
}

.madaf-sp-wrap.door-mode .madaf-sp-cell:not(.border):not(.door) {
    cursor: not-allowed;
    opacity: 0.6;
}

/* ── Placement overlay blocks ────────────────────────── */
.madaf-sp-placement {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 3px;
    border-radius: 2px;
    opacity: 0.9;
    box-sizing: border-box;
    transition: filter 0.1s;
}

.madaf-sp-placement:hover {
    filter: brightness(0.88);
}

.madaf-sp-placement-dim {
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.65);
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
}

.madaf-sp-placement-name {
    font-size: 9px;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 0 3px rgba(0,0,0,0.55);
    line-height: 1.1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* ── Sidebar product cards ───────────────────────────── */
.madaf-sp-product-card {
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: border-color 0.12s, box-shadow 0.12s;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 5px;
    text-align: right;
    flex-shrink: 0;
}

.madaf-sp-product-card:hover:not(.out-of-stock):not(.height-exceeded) {
    border-color: #D1D5DB;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.madaf-sp-product-card.active {
    border-color: var(--sp-active-color, #3B82F6);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.madaf-sp-product-card.out-of-stock,
.madaf-sp-product-card.height-exceeded {
    opacity: 0.45;
    cursor: not-allowed;
}

.madaf-sp-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.madaf-sp-card-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    display: inline-block;
}

.madaf-sp-card-img {
    width: 100%;
    height: 75px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.madaf-sp-card-name {
    font-size: 11px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.madaf-sp-card-dims { font-size: 10px; color: #6B7280; }
.madaf-sp-card-price { font-size: 12px; color: #059669; font-weight: 600; }

.madaf-sp-card-warn {
    font-size: 10px;
    color: #DC2626;
    background: #FEF2F2;
    border-radius: 3px;
    padding: 2px 4px;
    text-align: center;
}

.madaf-sp-empty-msg {
    color: #9CA3AF;
    font-size: 13px;
    text-align: center;
    padding: 20px 0;
}

/* ── Legend ──────────────────────────────────────────── */
.madaf-sp-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    min-height: 16px;
    direction: rtl;
}

.madaf-sp-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #374151;
}

.madaf-sp-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ── Summary ─────────────────────────────────────────── */
.madaf-sp-summary-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    color: #111827;
}

.madaf-sp-plan-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
    max-height: 35vh;
}

.madaf-sp-plan-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: #374151;
}

.madaf-sp-plan-color { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.madaf-sp-plan-name  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.madaf-sp-plan-count { font-weight: 700; color: #111827; white-space: nowrap; }
.madaf-sp-plan-price { color: #059669; font-size: 12px; white-space: nowrap; }

.madaf-sp-plan-empty {
    color: #9CA3AF;
    font-size: 12px;
    text-align: center;
    padding: 16px 8px;
    line-height: 1.6;
}

.madaf-sp-total {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    border-top: 1px solid #E5E7EB;
    padding-top: 10px;
}

.madaf-sp-summary-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Add-to-cart button ──────────────────────────────── */
.madaf-sp-add-btn {
    width: 100%;
    padding: 12px;
    background: #2563EB;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    text-align: center;
    direction: rtl;
}

.madaf-sp-add-btn:hover:not(:disabled) { background: #1D4ED8; }
.madaf-sp-add-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.madaf-sp-add-btn.loading { background: #93C5FD; }
.madaf-sp-add-btn.added   { background: #059669; }

/* Share / print button */
.madaf-sp-share-btn {
    width: 100%;
    padding: 8px;
    background: #fff;
    color: #374151;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s;
    text-align: center;
}

.madaf-sp-share-btn:hover { background: #F3F4F6; }

/* ── Auto-fill suggestions ───────────────────────────── */
.madaf-sp-suggestions {
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 14px;
    background: #FAFAFA;
}

.madaf-sp-sugg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.madaf-sp-sugg-title {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    flex: 1;
}

.madaf-sp-sugg-refresh {
    padding: 4px 10px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    color: #374151;
    transition: background 0.12s;
}
.madaf-sp-sugg-refresh:hover { background: #F3F4F6; }

.madaf-sp-sugg-sub {
    font-size: 11px;
    color: #9CA3AF;
    margin: 0 0 10px;
}

.madaf-sp-sugg-loading,
.madaf-sp-sugg-empty {
    font-size: 12px;
    color: #9CA3AF;
    text-align: center;
    padding: 12px 0;
    margin: 0;
}

.madaf-sp-sugg-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.madaf-sp-sugg-card {
    flex: 1;
    min-width: 150px;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 10px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 7px;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.madaf-sp-sugg-card:hover {
    border-color: #93C5FD;
    box-shadow: 0 2px 8px rgba(59,130,246,0.1);
}

.madaf-sp-sugg-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.madaf-sp-sugg-card-label {
    font-size: 12px;
    font-weight: 700;
    color: #111827;
    flex: 1;
    line-height: 1.3;
}

.madaf-sp-sugg-badge {
    font-size: 10px;
    font-weight: 700;
    background: #EFF6FF;
    color: #1D4ED8;
    border-radius: 10px;
    padding: 2px 7px;
    white-space: nowrap;
}

.madaf-sp-sugg-card-desc {
    font-size: 11px;
    color: #6B7280;
    margin: 0;
    line-height: 1.4;
}

.madaf-sp-sugg-canvas {
    display: block;
    border-radius: 4px;
    border: 1px solid #F3F4F6;
    width: 100%;
    image-rendering: pixelated;
    max-height: 90px;
    object-fit: contain;
}

.madaf-sp-sugg-stats {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #374151;
}

.madaf-sp-sugg-cost {
    font-weight: 700;
    color: #059669;
}

.madaf-sp-sugg-apply {
    width: 100%;
    padding: 7px;
    background: #2563EB;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s;
}
.madaf-sp-sugg-apply:hover:not(:disabled) { background: #1D4ED8; }
.madaf-sp-sugg-apply:disabled { background: #E5E7EB; color: #9CA3AF; cursor: not-allowed; }

/* ── Pillar cells ─────────────────────────────────────── */
.madaf-sp-cell.pillar {
    background: #374151 !important;
    cursor: pointer;
    position: relative;
}
.madaf-sp-cell.pillar::after {
    content: '';
    position: absolute;
    inset: 3px;
    border: 2px solid rgba(255,255,255,0.35);
    border-radius: 2px;
}
.madaf-sp-wrap.pillar-mode .madaf-sp-cell:not(.border):not(.pillar):not(.occupied) {
    cursor: cell;
}
.madaf-sp-wrap.pillar-mode .madaf-sp-cell.pillar {
    cursor: pointer;
}

.madaf-sp-pillar-btn.active {
    background: #F3F4F6;
    border-color: #6B7280;
    color: #111827;
    box-shadow: 0 0 0 2px rgba(107,114,128,0.2);
}

/* ── Shelf add-on row in plan list ───────────────────── */
.madaf-sp-plan-addon {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #6B7280;
    padding-right: 18px;
    direction: rtl;
}
.madaf-sp-addon-label { flex: 1; }
.madaf-sp-addon-ctrl  { display: flex; align-items: center; gap: 4px; }
.madaf-sp-addon-btn   {
    width: 20px; height: 20px;
    border: 1px solid #D1D5DB;
    border-radius: 4px;
    background: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.1s;
}
.madaf-sp-addon-btn:hover { background: #F3F4F6; }
.madaf-sp-addon-val {
    min-width: 20px;
    text-align: center;
    font-weight: 700;
    color: #111827;
    font-size: 12px;
}
.madaf-sp-addon-price { color: #059669; font-size: 11px; white-space: nowrap; }

/* ── Editor placeholder ──────────────────────────────── */
.madaf-sp-editor-preview { display: block !important; }

/* ── Print ───────────────────────────────────────────── */
@media print {
    .madaf-sp-wrap {
        display: block !important;
    }
    .madaf-sp-sidebar,
    .madaf-sp-inputs,
    .madaf-sp-actions,
    .madaf-sp-add-btn,
    .madaf-sp-share-btn {
        display: none !important;
    }
    .madaf-sp-main,
    .madaf-sp-summary {
        display: block !important;
        break-inside: avoid;
    }
    .madaf-sp-grid-scroll {
        max-height: none !important;
        overflow: visible !important;
    }
}

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .madaf-sp-wrap {
        grid-template-columns: 1fr;
    }
    .madaf-sp-sidebar {
        flex-direction: row;
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
    }
    .madaf-sp-product-card {
        min-width: 120px;
        max-width: 130px;
    }
    .madaf-sp-plan-list { max-height: 180px; }
    .madaf-sp-grid-scroll { max-height: 50vh; }
}

@media (max-width: 480px) {
    .madaf-sp-inputs { gap: 8px; }
    .madaf-sp-input-label input { width: 60px; }
    .madaf-sp-add-btn { font-size: 14px; padding: 10px; }
}
