/* ==========================================================
   Eden – مخطط 3D (plan3d.html) — يكمّل css/style.css
   ========================================================== */
.p3-views { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--card-border); }
.p3-view { min-height: 40px; padding: 4px 20px; border-radius: 999px; font-size: 16px; color: var(--text-soft); transition: all .2s; }
.p3-view.is-active { background: var(--btn-bg); color: var(--btn-text); font-weight: 700; }
[dir="ltr"] .p3-view { font-size: 14px; }

.p3-frame { display: block; height: min(72svh, 720px); min-height: 380px; background: var(--bg-alt); }
.p3-frame > canvas, .p3-3d, .p3-3d canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; max-height: none !important; }
.p3-frame > canvas { cursor: crosshair; touch-action: none; }
.p3-3d { touch-action: none; }
.p3-3d canvas { cursor: grab; touch-action: none; }
.p3-3d.is-dragging canvas { cursor: grabbing; }
.p3-frame.is-drop { outline: 2px dashed var(--wine); outline-offset: -8px; }

/* أشرطة الأدوات فوق المساحة */
.p3-toolbar { position: absolute; top: 10px; inset-inline-start: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 5px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 90%, transparent); border: 1px solid var(--card-border); box-shadow: 0 10px 24px -16px rgba(0, 0, 0, .5); backdrop-filter: blur(6px); z-index: 3; max-width: calc(100% - 20px); }
.p3-toolbar[hidden] { display: none; }
.p3-tool { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--text); transition: background .2s; }
.p3-tool svg, .p3-selbar svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.p3-tool:hover { background: var(--bg-alt); }
.p3-tool.is-active { background: var(--btn-bg); color: var(--btn-text); }
.p3-sep { width: 1px; height: 24px; background: var(--line); margin-inline: 2px; }
.p3-chip { min-height: 36px; padding: 2px 12px; border-radius: 999px; font-size: 14.5px; color: var(--text-soft); }
[dir="ltr"] .p3-chip { font-size: 13px; }
.p3-chip.is-active { background: var(--btn-bg); color: var(--btn-text); font-weight: 700; }

.p3-selbar { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 5px 6px 5px 12px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--card-border); box-shadow: 0 14px 28px -16px rgba(0, 0, 0, .55); z-index: 4; white-space: nowrap; max-width: calc(100% - 20px); overflow-x: auto; }
[dir="rtl"] .p3-selbar { padding: 5px 12px 5px 6px; }
.p3-selbar[hidden] { display: none; }
.p3-selbar b { font-size: 15px; margin-inline-end: 6px; max-width: 26ch; overflow: hidden; text-overflow: ellipsis; }
.p3-selbar button { display: grid; place-items: center; min-width: 38px; height: 38px; border-radius: 10px; font: 600 20px/1 var(--font-en); color: var(--text); }
.p3-selbar button:hover { background: var(--bg-alt); }
.p3-selbar button[hidden] { display: none; }
.p3-selbar .is-danger { color: var(--wine); }

.p3-scale { position: absolute; top: 64px; inset-inline-start: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--wine); box-shadow: var(--shadow); z-index: 5; font-size: 15px; }
.p3-scale[hidden] { display: none; }
.p3-scale input { width: 90px; min-height: 40px; padding: 4px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--field-bg); color: var(--text); font: 500 16px var(--font-en); }
.p3-scale i { font-style: normal; font-family: var(--font-en); color: var(--text-soft); }

.p3-frame .stage-hint { z-index: 2; inset: auto 12px 12px 12px; }
.p3-frame .stage-hint:empty { display: none; }
.p3-frame.has-sel .stage-hint { display: none; }
.p3-frame .stage-loading { z-index: 6; }
.p3-frame .stage-loading[hidden] { display: none; }

/* البداية: رفع / مثال / فارغ */
.p3-start { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.p3-card { display: grid; justify-items: center; align-content: start; gap: 4px; padding: 12px 6px; border-radius: 12px; border: 1px dashed var(--line); background: var(--bg-alt); text-align: center; cursor: pointer; transition: border-color .2s, transform .2s; }
.p3-card:hover { border-color: var(--wine); transform: translateY(-2px); }
.p3-card.is-active { border: 1px solid var(--wine); }
.p3-card svg { width: 30px; height: 30px; fill: none; stroke: var(--wine); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
[data-theme="dark"] .p3-card svg { stroke: var(--wine-soft); }
.p3-card b { font-size: 15px; line-height: 1.3; }
.p3-card small { font-size: 12px; color: var(--text-soft); line-height: 1.35; }
[dir="ltr"] .p3-card b { font-size: 13.5px; }
.p3-opts { display: grid; gap: 8px; margin-top: 14px; }
.p3-opts .btn { justify-self: start; }
.p3-opts select { width: 100%; min-height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--field-bg); color: var(--text); font: 500 14px var(--font-en); padding: 2px 8px; }
.p3-tip { margin-top: 10px; font-size: 13.5px; line-height: 1.6; }

/* مكتبة الأثاث */
.p3-lib { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-height: 430px; overflow-y: auto; padding: 2px; }
.p3-item { display: grid; gap: 4px; justify-items: center; padding: 8px 4px 6px; border-radius: 12px; border: 1px solid var(--card-border); background: var(--bg); text-align: center; cursor: grab; transition: border-color .2s, transform .2s; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.p3-item:hover { border-color: var(--wine); transform: translateY(-2px); }
.p3-item:active { cursor: grabbing; }
.p3-item svg { width: 100%; height: 58px; }
.p3-item b { font-size: 13.5px; line-height: 1.25; font-weight: 700; }
.p3-item small { font: 400 11px/1.2 var(--font-en); color: var(--text-soft); }
.p3-item.is-set { background: color-mix(in srgb, var(--wine) 7%, var(--bg)); }
.p3-item.is-set b::before { content: "✦ "; color: var(--gold); font-size: 10px; }
[dir="ltr"] .p3-item b { font-size: 12.5px; }
.p3-item svg .o { fill: none; stroke: var(--text); stroke-width: 1.3; vector-effect: non-scaling-stroke; }
.p3-item svg .f { fill: var(--bg-alt); stroke: var(--text); stroke-width: 1.3; vector-effect: non-scaling-stroke; }
.p3-item svg .w { fill: var(--wine); stroke: none; opacity: .85; }
.p3-item svg .g { fill: var(--gold-soft); stroke: var(--text); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* الخامات */
.p3-finish { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.p3-finish .swatch { padding: 4px; }
.p3-finish .sw-name { font-size: 12.5px; text-align: center; }
.p3-paint .chip { border-radius: 50%; }
.p3-sub { margin-top: 14px !important; }
.p3-share { margin-top: 8px; }
.p3-share[hidden] { display: none; }
.p3-credits { margin-top: 14px; }
.p3-credits ul { display: grid; gap: 2px; padding: 0; list-style: none; }
.p3-credits a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

@media (max-width: 960px) {
  .page-plan3d .studio-stage { position: relative; top: 0; }
  .p3-frame { height: 58svh; min-height: 340px; }
  .p3-lib { grid-template-columns: repeat(4, minmax(0, 1fr)); max-height: none; }
}
@media (max-width: 520px) {
  .p3-lib { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .p3-tool { width: 36px; height: 36px; }
  .p3-toolbar-3d { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; inset-inline-end: 10px; }
  .p3-toolbar-3d::-webkit-scrollbar { display: none; }
  .p3-chip { flex: none; min-height: 32px; padding: 2px 9px; font-size: 13px; }
  .p3-finish { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .p3-start small { display: none; }
}

/* الرفع التلقائي: رسالة التقدّم + تصحيح العرض + أزرار نصية */
.p3-frame .stage-loading.has-msg { align-content: center; gap: 14px; background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(3px); }
.p3-frame .stage-loading.has-msg span { width: auto; height: auto; border: 0; border-radius: 0; animation: none; font-size: 17px; font-weight: 600; color: var(--text); position: relative; padding-top: 58px; text-align: center; }
.p3-frame .stage-loading.has-msg span::before { content: ""; position: absolute; top: 0; left: 50%; margin-left: -21px; width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--wine); animation: spin .8s linear infinite; }
.p3-est { position: absolute; top: 60px; inset-inline-start: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--card-border); box-shadow: 0 14px 28px -16px rgba(0, 0, 0, .55); z-index: 4; font-size: 14px; max-width: calc(100% - 20px); }
.p3-est[hidden] { display: none; }
.p3-est input { width: 74px; min-height: 36px; padding: 4px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--field-bg); color: var(--text); font: 500 15px var(--font-en); }
.p3-est i { font-style: normal; font-family: var(--font-en); color: var(--text-soft); }
.p3-selbar .p3-txt { font: 600 13px/1.2 var(--font-ar, inherit); padding: 0 10px; white-space: nowrap; }
.p3-opts #detect { width: 100%; }
@media (max-width: 520px) { .p3-est { top: 56px; padding: 6px 8px; font-size: 13px; } }

/* شاشة المراجعة بعد الرفع التلقائي */
.p3-review { position: absolute; inset: auto 10px 10px 10px; display: grid; gap: 10px; padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--surface) 96%, transparent); border: 1px solid var(--wine); box-shadow: 0 18px 34px -18px rgba(0, 0, 0, .55); z-index: 5; backdrop-filter: blur(6px); }
.p3-review[hidden] { display: none; }
.p3-rev-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.p3-rev-head > div:first-child { display: grid; gap: 2px; min-width: 0; }
.p3-rev-head b { font-size: 17px; }
.p3-rev-head small { font-size: 14px; line-height: 1.5; color: var(--text-soft); }
[dir="ltr"] .p3-rev-head b { font-size: 15px; }
[dir="ltr"] .p3-rev-head small { font-size: 12.5px; }
.p3-rev-head .btn { flex: none; }
.p3-rev-kinds { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.p3-rev-acts { display: flex; align-items: center; gap: 6px; flex: none; }
.p3-rev-acts .p3-chip { border: 1px solid var(--line); }
.p3-rev-kinds[hidden] { display: none; }
.p3-rev-kinds button { display: grid; justify-items: center; gap: 3px; padding: 8px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; font-weight: 700; transition: border-color .2s, background .2s; }
[dir="ltr"] .p3-rev-kinds button { font-size: 12px; }
.p3-rev-kinds button:hover { border-color: var(--wine); }
.p3-rev-kinds button.is-active { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); }
.p3-rev-kinds svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.p3-frame.is-review .stage-hint { display: none; }
.p3-frame.is-review .p3-selbar { bottom: calc(var(--rev-h, 90px) + 20px); }
@media (max-width: 520px) {
  .p3-review { inset: auto 6px 6px 6px; padding: 10px; gap: 8px; }
  .p3-rev-head b { font-size: 15.5px; }
  .p3-rev-head small { font-size: 12.5px; }
  .p3-rev-kinds { gap: 3px; }
  .p3-rev-acts { width: 100%; justify-content: space-between; }
  .p3-frame.is-review { height: 82svh; }
  .p3-frame.is-review .p3-est { display: none; }
  .p3-rev-kinds button { padding: 6px 2px; font-size: 12.5px; }
  .p3-rev-kinds svg { width: 22px; height: 22px; }
}
/* الأشرطة فوق مساحة الرسم، بمساحتها الخاصة (لا تغطي المخطط ولا المنظور) */
.p3-bars { display: grid; gap: 8px; margin-bottom: 10px; min-width: 0; }
.p3-bars .p3-toolbar { position: relative; top: auto; inset-inline-start: auto; inset-inline-end: auto; z-index: auto; width: fit-content; max-width: 100%; box-shadow: none; backdrop-filter: none; }
.p3-bars .p3-toolbar[hidden] { display: none; }
.p3-bars .p3-toolbar-3d { overflow-x: auto; scrollbar-width: none; }
.p3-bars .p3-toolbar-3d::-webkit-scrollbar { display: none; }
.p3-frame .p3-scale { top: 12px; }
.p3-frame .p3-est { top: 12px; }
@media (max-width: 520px) { .p3-frame .p3-est { top: 10px; } }