/* ============================================================================
   Masahati - 3D planner structure (Phase 3B)
   Loaded AFTER style.css (and theme-pink.css). Contains ONLY the rules the
   3D-only workspace needs, so it works with whichever style.css is deployed.
   ============================================================================ */

/* Workspace: the Konva container (kept alive in the background for PNG export)
   and the 3D container share one stack. Konva keeps real layout dimensions via
   visibility:hidden - never display:none - so its stage stays correctly sized. */
.canvas-stack {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.canvas-stack > .canvas-container {
    position: absolute;
    inset: 0;
    flex: none;
}

.canvas-stack > .canvas-container.is-hidden {
    visibility: hidden;
    pointer-events: none;
}

/* 3D view */
.canvas-container.three-view {
    display: flex;
    flex-direction: column;
    background-color: #F3E9E4;
}

.three-view-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(90deg, #F6DDE3, #F1C9C0);
    color: #5A3D47;
    font-size: 13px;
    border-bottom: 1px solid #E8C7C2;
}

.three-hint {
    opacity: 0.95;
    text-align: center;
}

.three-canvas-host {
    flex: 1;
    position: relative;
    min-height: 0;
    background-color: #F3E9E4;
}

.three-canvas-host canvas {
    display: block;
    outline: none;
    /* No text selection / long-press callouts while dragging furniture or looking around */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* ---- Properties panel on narrower screens ----
   style.css hides .right-panel (the furniture properties: rotation, size,
   duplicate, delete) at 1200px and below. In a 3D-only planner that panel is the
   ONLY place to edit a selected piece, so it must stay reachable: it drops to a full-width row under the
   workspace. (Nothing else about the existing layout changes.) */
@media (max-width: 1200px) {
    .planner-container {
        height: auto;
    }

    .left-panel,
    .canvas-area {
        height: calc(100vh - 120px);
        min-height: 460px;
    }

    .right-panel {
        display: block;
        grid-column: 1 / -1;
        max-height: none;
        overflow-y: visible;
    }
}

@media (max-width: 768px) {
    .three-view-bar {
        font-size: 11.5px;
        padding: 0.4rem 0.5rem;
    }

    /* Small screens stack everything in one column. The older rule fixed the
       whole workspace at 400px, which the header, hint bar and ad slot almost
       entirely consumed - leaving the 3D view ~95px tall. Give the 3D stack its
       own real height and show the room first, controls below it. */
    .canvas-area {
        height: auto;
        min-height: 0;
        order: -2;
    }

    .left-panel {
        height: auto;
        min-height: 0;
    }

    .right-panel {
        grid-column: auto;
        order: -1;
    }

    .canvas-stack {
        flex: none;
        height: 62vh;
        min-height: 340px;
        max-height: 560px;
    }
}

/* ---- Precise rotation control (Phase 3C): layout only, colors come from the active theme ---- */
.rotation-buttons {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    direction: ltr;               /* row reads  -15°  |  90°  |  +15°  left-to-right, even inside the RTL panel */
}

.rotation-buttons .btn {
    flex: 1;
    width: auto;
    margin-bottom: 0;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
    min-height: 40px;             /* comfortable touch target */
    direction: ltr;               /* keep "-15°  90°  +15°" reading left-to-right, minus on the left */
    white-space: nowrap;
}

.rotation-readout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    direction: ltr;
}

.rotation-readout input[type="number"] {
    width: 6.5rem;
    text-align: center;
    font-weight: 600;
}

.rotation-unit {
    font-weight: 600;
}

/* ---- Room colors, doors list, field hints (Phase 4): layout only ---- */
.swatch-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.swatch {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(90, 61, 71, 0.28);
    cursor: pointer;
}

.swatch:hover { transform: scale(1.08); }

.swatch.is-active {
    box-shadow: 0 0 0 3px #AD5C75;
    border-color: #ffffff;
}

.color-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.9em;
    cursor: pointer;
}

.color-custom input[type="color"] {
    width: 46px;
    height: 30px;
    padding: 0;
    border-radius: 6px;
    cursor: pointer;
}

.doors-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.6rem;
}

.doors-list .door-item.is-selected {
    background-color: #AD5C75;
    border-color: #8F5868;
    color: #ffffff;
}

.field-hint {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.85em;
    opacity: 0.8;
}

/* ---- Planner page: single H1 (looks like the old title) and the crawlable how-to text ---- */
.canvas-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--primary-color, #8F5868);
}

.planner-about {
    max-width: 900px;
    margin: 1.5rem auto 0;
    padding: 0 1rem;
    line-height: 1.9;
}

.planner-about h2 { font-size: 1.2rem; color: var(--primary-color, #8F5868); margin-bottom: 0.5rem; }
.planner-about ol { padding-inline-start: 1.4rem; margin: 0.5rem 0; }
.planner-about a { color: var(--secondary-color, #AD5C75); font-weight: 600; }

/* Adsterra Native Banner under the 3D canvas: layout containment only - the ad can never be wider than its
   slot or push the planner layout sideways. (The widget itself is not modified.) */
[data-ad-slot="planner-below-canvas"] > div[id^="container-"] {
    max-width: 100%;
    overflow: hidden;
}

/* ============================================================================
   PLANNER-FIRST LAYOUT
   The 3D room gets the width and a viewport-relative height. The two former
   sidebars become drawers (overlay on desktop/laptop, bottom sheets on phones)
   and never shrink the workspace. Scoped to .planner-page so nothing else is affected.
   ============================================================================ */
.planner-page { --pf-line: #EAD8DE; --pf-text: var(--m-text, #5A3D47); --pf-plum: var(--m-plum, #8F5868); --pf-rose: var(--m-rose, #AD5C75); }

.planner-page .planner-container {
    display: block;
    grid-template-columns: none;
    height: auto;
    min-height: 0;
    max-width: none;
    margin: 0 0 16px;
    padding: 8px clamp(8px, 1.2vw, 18px) 0;
    gap: 0;
}

/* ---------- toolbar ---------- */
.planner-page .planner-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 2px 2px 10px; }
.planner-page .pt-title { margin: 0 0 0 8px; font-size: 1.1rem; font-weight: 600; line-height: 1.3; color: var(--pf-plum); white-space: nowrap; }
.planner-page .pt-group { display: flex; align-items: center; gap: 8px; }
.planner-page .pt-group--actions { margin-inline-start: auto; }
.planner-page .pt-more { display: none; margin-inline-start: auto; }
.planner-page .pt-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 16px; border-radius: 12px;
    border: 1.5px solid #E6A9B8; background: #fff; color: var(--pf-plum);
    font: inherit; font-size: 15px; font-weight: 600; line-height: 1; cursor: pointer; position: relative;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.planner-page .pt-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.planner-page .pt-btn svg circle[r="1.6"] { fill: currentColor; stroke: none; }
.planner-page .pt-btn:hover:not(:disabled) { background: var(--m-blush-pale, #FBEFF3); border-color: var(--pf-rose); }
.planner-page .pt-btn.is-open, .planner-page .pt-btn.is-open:hover:not(:disabled) { background: var(--pf-rose); border-color: var(--pf-rose); color: #fff; }
.planner-page .pt-btn:disabled { opacity: .5; cursor: not-allowed; }
.planner-page .pt-btn--ghost { border-color: var(--pf-line); }
.planner-page .pt-btn.has-selection:not(.is-open)::after { content: ""; position: absolute; top: 6px; inset-inline-start: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--pf-rose); }
.planner-page .pt-btn:focus-visible, .planner-page .drawer-close:focus-visible, .planner-page .stepper-btn:focus-visible, .planner-page .pt-menu button:focus-visible { outline: 3px solid var(--pf-plum); outline-offset: 2px; }
.planner-page .pt-short { display: none; }
.planner-page .pt-menu-wrap { position: relative; }
.planner-page .pt-menu { position: absolute; top: calc(100% + 6px); inset-inline-end: 0; min-width: 200px; padding: 6px; background: #fff; border: 1px solid var(--pf-line); border-radius: 12px; box-shadow: 0 14px 36px rgba(90, 61, 71, .22); z-index: 96; }
.planner-page .pt-menu[hidden] { display: none; }
.planner-page .pt-menu button { display: block; width: 100%; min-height: 44px; padding: 0 14px; border: 0; border-radius: 8px; background: none; color: var(--pf-text); font: inherit; font-size: 15px; text-align: start; cursor: pointer; }
.planner-page .pt-menu button:hover { background: var(--m-blush-pale, #FBEFF3); }

/* ---------- the workspace: the 3D room is the page ---------- */
.planner-page .canvas-area {
    display: flex; flex-direction: column;
    width: 100%; height: clamp(480px, calc(100vh - 150px), 1000px); min-height: 0;
    padding: 0; margin: 0; overflow: hidden; border-radius: 16px;
    background: #F3E9E4; border: 1px solid var(--pf-line); box-shadow: 0 8px 28px rgba(143, 88, 104, .14);
}
@supports (height: 100dvh) { .planner-page .canvas-area { height: clamp(480px, calc(100dvh - 150px), 1000px); } }
.planner-page .canvas-stack { flex: 1; height: auto; min-height: 0; max-height: none; }
/* the usage hint floats over the canvas instead of taking a bar of height */
.planner-page .three-view-bar {
    position: absolute; z-index: 3; top: 10px; left: 50%; transform: translateX(-50%);
    width: max-content; max-width: calc(100% - 24px); padding: 6px 14px; border: 0; border-radius: 999px;
    background: rgba(255, 248, 250, .9); box-shadow: 0 2px 10px rgba(90, 61, 71, .12); pointer-events: none; font-size: 13px;
}

/* ---------- Native Banner: directly after the workspace, in normal flow (not sticky, not overlaid) ---------- */
.planner-page .planner-ad { max-width: 1200px; margin-inline: auto; border-radius: 12px; }
/* ---------- Desktop sidebar: the Native Banner sits in its own narrow column at the far left of the workspace (>= 1200px only) ----------
   Below 1200px nothing changes: the banner stays in normal flow under the planner. The layout is a plain two-column grid
   (no fixed / sticky positioning); the ad is never scaled, cropped or clipped. Safety: the workspace is stacked ABOVE the ad column,
   so whatever the ad script injects (even content wider than its column or absolutely positioned) can never sit on top of the
   3D canvas or intercept drags/taps; the Properties drawer is kept clear of the ad column. */
@media (min-width: 1200px) {
    .planner-page .planner-layout { --ad-col-w: 200px; display: grid; grid-template-columns: minmax(0, 1fr) var(--ad-col-w); align-items: start; column-gap: 0; }
    /* RTL page: column 1 is the right side, so the sidebar column 2 is the far LEFT */
    .planner-page .planner-layout > .planner-container { grid-column: 1; grid-row: 1; min-width: 0; }
    .planner-page .planner-layout > .planner-ad {
        grid-column: 2; grid-row: 1; min-width: 0; width: auto; max-width: none; box-sizing: border-box;
        position: relative; z-index: 0;
        margin: 8px 0 0 clamp(8px, 1.2vw, 18px) !important;
        padding: 8px !important; border: 1px dashed #ccc !important;
    }
    .planner-page .planner-layout > .planner-ad > div[id^="container-"] { max-width: none; margin: 0; }
    .planner-page .planner-layout .canvas-area { position: relative; z-index: 1; }
    /* the Properties drawer opens at the left edge of the workspace: keep it clear of the banner column, and slightly
       narrower than elsewhere (340px) so, with the ad column taking 200px, it hides no larger a share of the room
       than before and furniture stays draggable while it is open */
    .planner-page .planner-layout .right-panel { inset-inline-end: calc(10px + var(--ad-col-w) + clamp(8px, 1.2vw, 18px)); width: min(340px, calc(100vw - 20px)); }
}
.planner-page [data-ad-slot="planner-below-canvas"] > div[id^="container-"] { max-width: 970px; margin-inline: auto; }

/* ---------- drawers ---------- */
.planner-page .left-panel, .planner-page .right-panel {
    display: block; position: fixed; z-index: 95; top: 124px; bottom: 10px;
    width: min(400px, calc(100vw - 20px)); height: auto; max-height: none; min-height: 0;
    grid-column: auto; margin: 0; padding: 0 16px 24px; overflow-y: auto; overscroll-behavior: contain;
    background: #fff; border: 1px solid var(--pf-line); border-radius: 16px; box-shadow: 0 20px 56px rgba(90, 61, 71, .3);
    font-size: 15px;
    visibility: hidden; opacity: 0;
    transition: transform .22s ease, opacity .18s ease, visibility 0s linear .22s;
}
.planner-page .left-panel  { inset-inline-start: 10px; transform: translateX(28px); }
.planner-page .right-panel { inset-inline-end: 10px;   transform: translateX(-28px); }
/* opacity .9999, not 1 (a 0.01% difference, invisible): a fully opaque fixed scroller can make the WebGL canvas underneath stop painting in some compositors */
.planner-page .left-panel[data-open="true"], .planner-page .right-panel[data-open="true"] { visibility: visible; opacity: .9999; transform: none; transition-delay: 0s; }
.planner-page .left-panel[data-mode="room"] [data-group="furniture"], .planner-page .left-panel[data-mode="room"] [data-group="openings"],
.planner-page .left-panel[data-mode="furniture"] [data-group="room"], .planner-page .left-panel[data-mode="furniture"] [data-group="openings"],
.planner-page .left-panel[data-mode="openings"] [data-group="room"], .planner-page .left-panel[data-mode="openings"] [data-group="furniture"] { display: none; }
/* the drawer title already says «الأبواب والنوافذ» */
.planner-page .left-panel[data-mode="openings"] [data-group="openings"] > h3 { display: none; }
.planner-page .drawer-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 -16px 8px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--pf-line); }
.planner-page .drawer-title { font-size: 1.15rem; font-weight: 600; color: var(--pf-plum); }
.planner-page .drawer-close { width: 44px; height: 44px; flex: none; border: 1.5px solid var(--pf-line); border-radius: 12px; background: #fff; color: var(--pf-plum); font-size: 26px; line-height: 1; cursor: pointer; }
.planner-page .drawer-close:hover { background: var(--m-blush-pale, #FBEFF3); }

/* comfortable controls inside the drawers */
.planner-page .control-panel label { font-size: 14.5px; }
.planner-page .control-panel input:not([type="color"]), .planner-page .control-panel select { min-height: 44px; font-size: 16px; }
.planner-page .control-panel .btn { min-height: 44px; font-size: 15px; }
.planner-page #furnitureCategories button, .planner-page #furnitureList button { min-height: 44px; font-size: 15px; }
.planner-page .control-panel .input-group { display: flex; align-items: stretch; gap: 8px; }
.planner-page .control-panel .input-group select { width: auto; min-width: 72px; }

/* furniture library inside the drawer: category tabs and items wrap into grids at every width */
.planner-page #furnitureCategories { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow: visible; white-space: normal; flex-wrap: wrap; max-height: none; }
.planner-page #furnitureCategories button { width: 100%; min-width: 0; padding: 8px 10px; white-space: normal; line-height: 1.3; }
.planner-page #furnitureList { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; overflow: visible; white-space: normal; max-height: none; margin-top: 10px; }
.planner-page #furnitureList button { width: 100%; min-width: 0; padding: 8px; white-space: normal; line-height: 1.35; text-align: center; }

/* ---------- number steppers:  [ - ]  value  [ + ] ---------- */
.planner-page input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.planner-page input[type="number"]::-webkit-inner-spin-button, .planner-page input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.planner-page .stepper { display: flex; align-items: stretch; gap: 6px; direction: ltr; flex: 1; min-width: 0; }
.planner-page .stepper input { flex: 1; min-width: 0; width: auto; text-align: center; font-weight: 600; direction: ltr; }
.planner-page .stepper-btn { flex: none; width: 44px; min-height: 44px; border: 1.5px solid #E6A9B8; border-radius: 12px; background: var(--m-blush-pale, #FBEFF3); color: var(--pf-plum); font: inherit; font-size: 24px; font-weight: 500; line-height: 1; cursor: pointer; }
.planner-page .stepper-btn:hover { background: #F6DDE3; border-color: var(--pf-rose); }
.planner-page .stepper-btn:active { background: var(--pf-rose); color: #fff; }

/* ---------- breakpoints (designed, not scaled) ---------- */
@media (max-width: 900px) {
    /* the H1 stays in the page for SEO/screen readers; visually it gives its room to the buttons */
    .planner-page .pt-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-width: 768px) {
    .planner-page .planner-container { padding-top: 6px; }
    .planner-page .planner-toolbar { flex-wrap: nowrap; gap: 8px; padding-bottom: 8px; }
    .planner-page .pt-group--panels { flex: 1; min-width: 0; }
    .planner-page .pt-group--panels .pt-btn { flex: 1; min-width: 0; padding: 0 8px; }
    .planner-page .pt-group--actions { display: none; }
    .planner-page .pt-more { display: block; margin-inline-start: 0; }
    .planner-page .pt-more .pt-btn { width: 44px; padding: 0; }
    /* a little shorter than the viewport so the page can always be scrolled from the strip below the canvas / the toolbar */
    .planner-page .canvas-area { border-radius: 14px; height: clamp(400px, calc(100vh - 205px), 1000px); }
    @supports (height: 100dvh) { .planner-page .canvas-area { height: clamp(400px, calc(100dvh - 205px), 1000px); } }
    /* the hint becomes a bar under the canvas: touching it scrolls the PAGE (the canvas itself captures touches for looking/dragging) */
    .planner-page .three-view-bar {
        position: static; transform: none; order: 2; flex: none; width: auto; max-width: none; border-radius: 0;
        flex-wrap: wrap; row-gap: 0; padding: 6px 12px; min-height: 44px; font-size: 12px; text-align: center;
        background: linear-gradient(90deg, #F6DDE3, #F1C9C0); border-top: 1px solid #E8C7C2; box-shadow: none;
        pointer-events: auto; touch-action: pan-y;
    }
    .planner-page .three-view-bar::after { content: "\2195  مرّري الصفحة بالسحب من هنا"; flex-basis: 100%; font-size: 11.5px; color: var(--pf-plum, #8F5868); opacity: .85; }
    /* drawers become bottom sheets */
    .planner-page .left-panel, .planner-page .right-panel {
        top: auto; bottom: 0; left: 0; right: 0; inset-inline: 0; width: 100%; max-height: min(58vh, 560px);
        border-radius: 20px 20px 0 0; border-bottom: 0; padding: 0 16px calc(24px + env(safe-area-inset-bottom, 0px));
        transform: translateY(104%);
    }
    .planner-page .left-panel[data-open="true"], .planner-page .right-panel[data-open="true"] { transform: none; }
}
@media (max-width: 520px) {
    .planner-page .pt-long { display: none; }
    .planner-page .pt-short { display: inline; }
    .planner-page .pt-btn { font-size: 14px; }
    /* four panel buttons across a phone: icon above a (wrapping) label so «الأبواب والنوافذ» fits without clipping */
    .planner-page .pt-group--panels .pt-btn { flex-direction: column; justify-content: center; gap: 2px; height: auto; min-height: 52px; padding: 4px 3px; font-size: 12px; line-height: 1.2; text-align: center; }
    .planner-page .pt-group--panels { align-items: stretch; }
    .planner-page .pt-group--panels .pt-btn svg { width: 18px; height: 18px; }
    .planner-page .pt-group--panels .pt-btn span { white-space: normal; overflow-wrap: anywhere; }
}
@media (prefers-reduced-motion: reduce) {
    .planner-page .left-panel, .planner-page .right-panel, .planner-page .pt-btn { transition: none; }
}

/* ---------- first-visit tooltips (never interactive, never covers a control) ---------- */
.planner-tip {
    position: absolute; z-index: 90; box-sizing: border-box; padding: 10px 14px; border: 1.5px solid #E6A9B8; border-radius: 14px;
    background: #FFF8FA; color: var(--m-text, #5A3D47); font: inherit; font-size: 14px; line-height: 1.7; text-align: right;
    box-shadow: 0 8px 24px rgba(143, 88, 104, .22); pointer-events: none; opacity: 0;
}
.planner-tip.is-visible { opacity: 1; }
.planner-tip::before, .planner-tip::after { content: ""; position: absolute; top: -8px; inset-inline-start: auto; left: calc(var(--arrow-x, 50%) - 8px); width: 14px; height: 14px; transform: rotate(45deg); }
.planner-tip::before { top: -9px; background: #E6A9B8; }
.planner-tip::after { top: -7px; background: #FFF8FA; }
@media (prefers-reduced-motion: no-preference) { .planner-tip { transition: opacity .25s ease; } }


/* ---- Windows sub-section in the Doors & Windows panel: layout only ---- */
.subsection-title {
    margin: 1.4rem 0 0.8rem;
    padding: 0.55rem 0.8rem;
    border-top: 1px solid rgba(143, 88, 104, 0.22);
    border-radius: 8px;
    background: rgba(246, 218, 212, 0.45);
    font-size: 1.05rem;
    font-weight: 700;
    color: #8F5868;
}
.subsection-title--first { margin-top: 0.2rem; }
/* breathing room between the Doors block and the Windows heading */
#doorsList { margin-bottom: 0.4rem; }
