:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --line: #e4ddd0;
  --ink: #1f2a2e;
  --muted: #6b7275;
  --accent: #0f6e6a;
  --accent-2: #e0f0ee;
  --warn: #b4531f;
  --warn-bg: #fdf0e6;
  --plan-bg: #f7f5f0;
  --radius: 12px;
  font-family: "Cairo", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ===== الشريط العلوي ===== */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: max-content; }
.brand .logo { width: 38px; height: 38px; display: block; flex-shrink: 0; }
.brand strong { display: block; font-size: 17px; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }

.stepper { display: flex; gap: 4px; flex: 1; justify-content: center; overflow-x: auto; scrollbar-width: none; }
.stepper button {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent;
  padding: 6px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap; color: var(--muted); font-size: 14px;
}
.stepper button .n {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; font-weight: 600;
}
.stepper button.done .n { background: var(--accent-2); border-color: var(--accent-2); color: var(--accent); }
.stepper button.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.stepper button.active .n { background: var(--accent); border-color: var(--accent); color: #fff; }

.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 18px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.menu { position: relative; }
.menu-list {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,.12); display: flex; flex-direction: column;
}
.menu-list button { text-align: start; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }

/* ===== الأزرار ===== */
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.danger { background: var(--surface); color: #b3261e; border-color: #f0c9c5; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.big { padding: 14px; font-size: 17px; border-radius: 14px; }
.btn:disabled { opacity: .4; cursor: default; }

/* ===== التخطيط ===== */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 340px; flex-shrink: 0; overflow-y: auto; background: var(--surface);
  border-inline-end: 1px solid var(--line); padding: 18px 18px 90px;
}
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.canvas-wrap { flex: 1; position: relative; min-height: 0; background: var(--plan-bg); }
#plan { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; display: block; }
#view3d { position: absolute; inset: 0; }
#view3d canvas { display: block; width: 100%; height: 100%; }

.hint {
  position: absolute; bottom: 12px; inset-inline-start: 12px; max-width: min(520px, calc(100% - 24px));
  background: rgba(31,42,46,.86); color: #fff; font-size: 13px; padding: 8px 12px; border-radius: 10px; pointer-events: none;
}
.hint:empty { display: none; }

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line); min-height: 52px;
}
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.toolbar .spacer { flex: 1; }
.toolbar label.inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.toolbar select { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--surface); }

.stats { display: flex; gap: 22px; flex-wrap: wrap; padding: 8px 16px; background: var(--surface); border-top: 1px solid var(--line); font-size: 13px; }
.stats div { color: var(--muted); }
.stats b { color: var(--ink); font-weight: 600; margin-inline-start: 4px; }
.stats .over b { color: var(--warn); }

/* ===== اللوحة الجانبية ===== */
.panel h2 { font-size: 20px; margin: 0 0 4px; }
.panel .lead { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.7; }
.panel h3 { font-size: 14px; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input[type=number], .field input[type=text], .field select, .num {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--surface-2); font-size: 15px; width: 100%;
}
.field input:focus, .field select:focus, .num:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.unit { position: relative; }
.unit::after { content: attr(data-unit); position: absolute; inset-inline-end: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.unit input { padding-inline-end: 28px !important; }

.choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice button {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px;
}
.choice button.on { border-color: var(--accent); background: var(--accent-2); color: var(--accent); font-weight: 600; }
.choice button svg { width: 56px; height: 36px; }

.side-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; background: var(--surface-2); }
.side-card.on { border-color: var(--accent); background: #f3faf9; }
.side-card .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-card .head label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; cursor: pointer; }
.side-card .head input[type=number] { width: 92px; }
.side-card .sub { font-size: 12px; color: var(--muted); }

.switch { appearance: none; width: 36px; height: 20px; border-radius: 20px; background: #d5cfc3; position: relative; cursor: pointer; transition: .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { inset-inline-start: 18px; }
.switch:disabled { opacity: .4; cursor: not-allowed; }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=range] { flex: 1; accent-color: var(--accent); }
.range-row .num { width: 90px; flex: none; }

.list { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); cursor: pointer; font-size: 14px;
}
.item.on { border-color: var(--accent); background: #f3faf9; }
.item .dot { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.item .grow { flex: 1; }
.item small { color: var(--muted); }
.item.bad { border-color: #f0c39f; background: var(--warn-bg); }

.templates { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.templates button {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 9px; padding: 7px 9px; cursor: pointer; font-size: 13px; text-align: start;
}
.templates button:hover { border-color: var(--accent); }
.templates .dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

.editor { border: 1.5px solid var(--accent); border-radius: var(--radius); padding: 14px; margin: 14px 0; background: #fbfefd; }
.editor .title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-weight: 700; }
.edges { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; font-size: 13px; color: var(--muted); }
.edges .num { padding: 5px 8px; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.note { font-size: 13px; line-height: 1.7; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.warn { font-size: 13px; line-height: 1.7; color: var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 11px; background: #fff; color: var(--ink); }

.nav { position: sticky; bottom: -90px; display: flex; gap: 8px; margin-top: 24px; padding: 12px 0 0; background: linear-gradient(to bottom, transparent, var(--surface) 30%); }
.nav .btn { flex: 1; }

.gate { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--surface-2); }
.gate .gtitle { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 14px; }
.gate .field { margin: 0; }

.roof-btn { margin-top: 14px; }

.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; z-index: 50;
  padding: 10px 18px; border-radius: 12px; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

.modal { position: fixed; inset: 0; z-index: 60; background: rgba(31,42,46,.35); display: grid; place-items: center; padding: 16px; animation: fade .15s ease-out; }
.modal-card { width: min(380px, 100%); background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.2); animation: pop .18s ease-out; }
.modal-card h3 { margin: 0 0 8px; font-size: 18px; }
.modal-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.8; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; padding: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }

/* ===== عناصر المخطط SVG ===== */
#plan text { font-family: "Cairo", sans-serif; text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: var(--plan-bg); stroke-width: 3px; stroke-linejoin: round; fill: var(--ink); }
#plan .grid { stroke: #e7e2d8; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .grid5 { stroke: #d9d2c4; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .street { fill: #4a4e54; }
#plan .sidewalk { fill: #bdb7ab; }
#plan .street-line { stroke: #f2efe6; stroke-width: 2; stroke-dasharray: 14 12; vector-effect: non-scaling-stroke; fill: none; }
#plan text.street-label { fill: #fff; stroke: #4a4e54; font-weight: 600; }
#plan text.neighbor { fill: #9b937f; }
#plan text.neighbor.plot { fill: #6f6650; font-weight: 600; }
#plan text.plot-own { fill: #0f6e6a; font-weight: 700; opacity: .85; }
#plan .neighbor-area { fill: #ebe5d8; }
#plan .land { fill: #fbfaf6; stroke: #9b937f; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .fence { stroke: #8a7a5c; stroke-width: 5; vector-effect: non-scaling-stroke; fill: none; stroke-linecap: square; }
#plan .gate-line { stroke: #2f3338; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 4 3; }
#plan text.gate-label { fill: #2f3338; }
#plan .foot { fill: rgba(15,110,106,.06); stroke: #2b3438; stroke-linejoin: miter; }
#plan .foot.faint { fill: rgba(15,110,106,.05); stroke: #0f6e6a; stroke-dasharray: .4 .3; }
#plan .foot.faint.pick { cursor: pointer; }
#plan .foot.faint.pick:hover { fill: rgba(15,110,106,.16); }
#plan .foot.edit { fill: rgba(15,110,106,.1); cursor: move; }
#plan .room { stroke: #3b4549; stroke-linejoin: miter; cursor: pointer; }
#plan .room.pool { stroke: #e3dccb; }
#plan .room.open { stroke-width: 2px !important; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
#plan .room.sel { stroke: var(--accent); }
#plan .room.bad { stroke: #c2410c; }
#plan .room-outline { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .fwall { stroke: #3b4549; stroke-linecap: square; cursor: pointer; }
#plan .fwall.sel { stroke: var(--accent); }
#plan .gap { fill: #fbfaf6; }
#plan .door { fill: none; stroke: #7a5536; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#plan .win { stroke: #2d7fa8; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#plan .open-hit { fill: transparent; cursor: pointer; }
#plan .open-sel { fill: rgba(15,110,106,.18); stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#plan .ghost { opacity: .55; }
#plan .vh { fill: #fff; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; cursor: grab; }
#plan .mh { fill: var(--accent); stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: move; opacity: .8; }
#plan .vh.on { fill: var(--accent); stroke: #fff; }
#plan .vdel { cursor: pointer; }
#plan .vdel circle { fill: #c0392b; stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#plan .vdel:hover circle { fill: #a5281c; }
#plan text.vdel-x { fill: #fff; stroke: none; font-weight: 700; }
#plan .mh:hover, #plan .vh:hover { opacity: 1; filter: brightness(1.1); }
#plan text.dim { fill: var(--accent); font-weight: 600; }
#plan text.room-name { font-weight: 600; }
#plan text.room-area { fill: var(--muted); }
#plan text.land-dim { fill: #7d7563; font-weight: 600; }
#plan .guide { stroke: #e0569a; stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
#plan .draw { fill: rgba(15,110,106,.12); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; }
#plan .draw-pt { fill: var(--accent); }
#plan .draw-close { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
#plan.tool-draw { cursor: crosshair; }
#plan.panning { cursor: grabbing; }

/* ===== الأرض: الصك والحدود ===== */
.deed-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; font-size: 15px; border-radius: 12px; box-shadow: 0 4px 14px rgba(15,110,106,.22); }
.deed-btn span { font-size: 18px; }
.note.center { text-align: center; background: none; padding: 6px 4px 0; font-size: 12px; }
.choice.two { grid-template-columns: 1fr 1fr; }
.side-card { position: relative; display: flex; flex-direction: column; gap: 8px; border-inline-start: 4px solid #cfc7b6; }
.side-card.kind-street { border-inline-start-color: #4a4e54; }
.side-card.kind-walk { border-inline-start-color: #c8a777; }
.side-card.kind-garden { border-inline-start-color: #5f9e47; }
.side-card .head input[type=text].plot-in { width: 140px; border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; background: #fff; font-size: 14px; }
.edge-title { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.edge-no { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; display: grid; place-items: center; flex: none; }
.kind-sel { border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: #fff; font-size: 13px; }
.tag { background: var(--accent-2); color: var(--accent); border-radius: 6px; padding: 0 6px; font-size: 11px; font-weight: 600; }
.angle-ctl { display: flex; align-items: center; gap: 6px; }
.angle-ctl input { width: 86px !important; }
.lock { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 15px; }
.lock.on { background: var(--accent-2); border-color: var(--accent); }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); cursor: pointer; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }
.unit.bad input { border-color: #e2a07a; background: var(--warn-bg); }
.okc { color: #2e7d4f; font-weight: 600; }
.badc { color: var(--warn); font-weight: 600; }
.ok { font-size: 13px; color: #2e7d4f; background: #e8f5ec; border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.redx { color: #c0392b; }
.item .row-del { border: 0; background: none; color: #b3261e; cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; opacity: .55; }
.item .row-del:hover { opacity: 1; background: #fbe9e7; }
.btn.small.on { border-color: var(--accent); color: var(--accent); background: var(--accent-2); }

/* شريط الأدوار */
.level-bar { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.level-bar button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 6px; cursor: pointer; font-size: 14px; color: var(--muted); }
.level-bar button.on { background: var(--surface); color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.level-bar .lv-chk { display: flex; align-items: center; gap: 5px; padding: 0 10px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; border-inline-start: 1px solid var(--line); }
.level-bar .lv-chk input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.level-bar button.add { color: var(--accent); border: 1px dashed var(--accent); }

/* نافذة الصك */
.deed-card { width: min(1280px, 100%); max-width: calc(100vw - 24px); min-width: 0; box-sizing: border-box; max-height: calc(100vh - 32px); display: flex; flex-direction: column; padding: 18px 20px; }
.deed-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.deed-head h3 { margin: 0; }
.deed-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; overflow: auto; min-height: 0; padding-bottom: 12px; }
.deed-form { min-width: 0; }
.deed-form .note { margin-bottom: 12px; }
.deed-rows { display: flex; flex-direction: column; gap: 6px; }
.dr-h, .dr { display: grid; grid-template-columns: 26px 96px 86px 110px minmax(150px, 1fr) 118px 82px; gap: 6px; align-items: center; }
.dr-h { font-size: 12px; color: var(--muted); padding: 0 4px; }
.dr { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 4px; }
.dr select, .dr input[type=number], .dr input[type=text] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 7px; background: #fff; font-size: 13px; width: 100%; min-width: 0; }
.dr-n { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; display: grid; place-items: center; }
.dr-x { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; color: var(--muted); align-items: center; }
.dr-x label { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.dr-x input[type=number] { width: 58px; }
.dr-c { display: flex; flex-direction: column; gap: 4px; }
.dr-a { display: flex; gap: 2px; }
.dr-a button { width: 26px; height: 26px; border: 1px solid var(--line); background: #fff; border-radius: 7px; cursor: pointer; font-size: 12px; padding: 0; }
.dr-a button:hover { border-color: var(--accent); }
.deed-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.deed-prev { position: sticky; top: 0; align-self: start; }
.deed-svg { width: 100%; aspect-ratio: 1; background: var(--plan-bg); border: 1px solid var(--line); border-radius: 12px; }
.deed-svg text { font-family: "Cairo", sans-serif; text-anchor: middle; dominant-baseline: middle; fill: var(--ink); font-weight: 600; paint-order: stroke; stroke: var(--plan-bg); stroke-width: .25px; }
.deed-svg .dp-land { fill: #fff; stroke: #9b937f; }
.deed-svg .dp-pt { fill: #fff; stroke: var(--accent); stroke-width: .15; }
.deed-svg .dp-lock { fill: var(--accent); }
.deed-svg .dp-n { fill: var(--muted); font-weight: 500; }
.deed-empty { aspect-ratio: 1; display: grid; place-items: center; color: var(--muted); background: var(--plan-bg); border: 1px dashed var(--line); border-radius: 12px; font-size: 13px; padding: 20px; text-align: center; }
.deed-info { font-size: 13px; color: var(--muted); margin-top: 8px; }
.deed-note { font-size: 12px; color: var(--accent); background: var(--accent-2); border-radius: 8px; padding: 4px 10px; margin-inline-start: auto; margin-inline-end: 10px; }
@media (max-width: 1340px) {
  .deed-body { grid-template-columns: 1fr; }
  .deed-prev { position: static; order: -1; display: grid; grid-template-columns: minmax(0, 300px) 1fr; gap: 14px; align-items: start; }
  .deed-prev .deed-svg, .deed-prev .deed-empty { aspect-ratio: 4 / 3; }
}
@media (max-width: 1100px) {
  .dr-h { display: none; }
  .dr { grid-template-columns: 26px 1fr 1fr 1fr; }
  .dr-x { grid-column: 2 / 4; }
  .dr-c { grid-column: 4; }
  .dr-a { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ===== إضافات المخطط ===== */
#plan .walk { fill: #e2cfae; stroke: #c8ae86; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan text.walk-label { fill: #6e5531; stroke: #e2cfae; font-weight: 600; }
#plan .garden { fill: #cfe3bd; }
#plan .tree { fill: #8cbf6d; stroke: #5f9447; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan text.garden-label { fill: #3d6b2c; stroke: #cfe3bd; font-weight: 700; }
#plan text.land-dim.bad { fill: #c0392b; }
#plan .ang { cursor: pointer; }
#plan .ang rect { fill: #fff; stroke: #c9c1b0; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .ang:hover rect { stroke: var(--accent); }
#plan .ang.locked rect { fill: var(--accent-2); stroke: var(--accent); }
#plan text.ang-t { fill: #6b6352; stroke: none; font-weight: 600; }
#plan .ang.locked text.ang-t { fill: var(--accent); }
#plan .vround { cursor: pointer; }
#plan .vround circle { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#plan .vround text.vdel-x { fill: var(--accent); }
#plan .vround.on circle { fill: var(--accent); }
#plan .vround.on text.vdel-x { fill: #fff; }
#plan .obj-del, #plan .obj-dup { cursor: pointer; }
#plan .obj-del circle { fill: #c0392b; stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
#plan .obj-del:hover circle { fill: #a5281c; }
#plan .obj-dup circle { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#plan .obj-dup text.vdel-x { fill: var(--accent); }
#plan .ghost-floor { fill: none; stroke: #9aa3a6; stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .ghost-room { fill: rgba(120,130,134,.06); stroke: #b9c0c2; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .compass { cursor: grab; }
#plan .compass .c-bg { fill: rgba(255,255,255,.88); stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .compass .c-ring { fill: none; stroke: #c9c1b0; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .compass .c-tick { stroke: #a39b88; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .compass .c-n { fill: #c0392b; }
#plan .compass .c-s { fill: #9aa3a6; }
#plan .compass .c-sun { stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 3 2; }
#plan .compass .c-sun.rise { stroke: #e08a1e; }
#plan .compass .c-sun.set { stroke: #7b5ea7; }
#plan .compass .c-sundot.rise { fill: #f2a634; }
#plan .compass .c-sundot.set { fill: #7b5ea7; }
#plan .compass text.c-l { fill: #4b5356; font-weight: 700; stroke: #fff; }
#plan .compass text.c-l.n { fill: #c0392b; }
#plan .compass text.c-cap { font-weight: 600; stroke: #fff; }
#plan .compass text.c-cap.rise { fill: #c27412; }
#plan .compass text.c-cap.set { fill: #6a4f96; }

@media (max-width: 860px) {
  .deed-body { grid-template-columns: 1fr; }
  .deed-prev { position: static; order: -1; }
  .deed-svg, .deed-empty { aspect-ratio: 4 / 3; }
  .dr-h { display: none; }
  .dr { grid-template-columns: 26px 1fr 1fr; }
  .dr-x { grid-column: 1 / -1; }
  .dr-c { grid-column: 2; }
  .dr-a { grid-column: 3; justify-content: flex-end; }
}

/* ===== الحساب والمشاريع ===== */
.top-actions { position: relative; }
.account { display: flex; align-items: center; gap: 8px; margin-inline-end: 4px; }
.proj-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; max-width: 190px; }
.proj-chip b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.proj-chip small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.proj-chip small.ok { color: #2e7d4f; background: none; padding: 0; margin: 0; border-radius: 0; } /* لا يرث صندوق .ok فيتغير ارتفاع الشريط مع كل حفظ */
.proj-chip small.busy { color: var(--muted); }
.proj-chip small.err { color: var(--warn); }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; font-size: 15px; }
.login-btn { white-space: nowrap; }
.acc-menu { inset-inline-end: auto; inset-inline-start: 0; min-width: 240px; }
.acc-head { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.acc-head small { color: var(--muted); font-size: 12px; direction: ltr; text-align: end; }
.plan { display: inline-block; align-self: flex-start; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); margin-top: 4px; }
.plan.pro { background: #fff6e0; border-color: #f0d48a; color: #8a6510; }

.acc-card { width: min(420px, 100%); }
.acc-card .field input { border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: var(--surface-2); font-size: 15px; }
.acc-card .field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.acc-tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.acc-tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.acc-tabs button.on { background: #fff; color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.acc-lead { color: var(--muted); font-size: 14px; line-height: 1.8; margin: 0 0 14px; }
.acc-lead.center, .center { text-align: center; }
.acc-err { color: #b3261e; background: #fdecea; border-radius: 9px; padding: 8px 10px; font-size: 13px; margin: 0 0 10px !important; }
.acc-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0; }
.acc-or::before, .acc-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; }
.link-btn { display: block; margin: 12px auto 0; border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 13px; }
.link-btn.muted { color: var(--muted); }
.acc-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.acc-title h3 { margin: 0; }
.acc-title .plan { margin: 0; align-self: center; }
.proj-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow: auto; margin-bottom: 12px; }
.proj { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface-2); }
.proj.on { border-color: var(--accent); background: #f3faf9; }
.proj .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.proj .grow b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .grow small { color: var(--muted); font-size: 12px; }
.proj .ren { border: 1px solid var(--accent); border-radius: 8px; padding: 6px 8px; font-size: 14px; width: 100%; }
.proj-ic { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-2); color: var(--accent); display: grid; place-items: center; font-size: 18px; flex: none; }
.proj .cur { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.new-proj { padding: 11px; }
.upg-badge { width: 54px; height: 54px; margin: 0 auto 8px; border-radius: 50%; background: linear-gradient(135deg, #f6d27a, #e0a325); color: #fff; display: grid; place-items: center; font-size: 26px; box-shadow: 0 6px 16px rgba(224,163,37,.35); }
.upg-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.upg-list li { display: flex; gap: 8px; align-items: flex-start; }
.upg-list li::before { content: "✓"; color: var(--accent); font-weight: 700; }

@media (max-width: 860px) {
  .proj-chip { display: none; }
}

/* ===== الجوال ===== */
@media (max-width: 860px) {
  body { overflow: auto; }
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .stepper { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .stepper button .t { display: none; }
  .stepper button.active .t { display: inline; }
  .top-actions { margin-inline-start: auto; }
  .layout { flex-direction: column; flex: none; }
  .stage { order: -1; height: 62vh; flex: none; }
  .panel { width: 100%; border: 0; border-top: 1px solid var(--line); padding: 16px 16px 40px; overflow: visible; }
  .stats { gap: 12px; }
}

/* زر إظهار كلمة المرور */
.pass-wrap { position: relative; display: block; }
.pass-wrap input { width: 100%; box-sizing: border-box; padding-left: 42px !important; }
.pass-wrap input::-ms-reveal { display: none; }
.pass-wrap .eye { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 8px; padding: 0; }
.pass-wrap .eye:hover { color: var(--accent); background: var(--accent-2); }
.ext-note { font-size: 12px; color: var(--muted); margin: 8px 0 2px; line-height: 1.6; }

/* أدوات الضلع المحدد */
#plan .mh.on { fill: #e0a325; opacity: 1; }
#plan .etool { cursor: pointer; }
#plan .etool rect { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; filter: drop-shadow(0 1px 2px rgba(0,0,0,.18)); }
#plan .etool:hover rect { fill: var(--accent); }
#plan text.etool-t { fill: var(--accent); stroke: none; font-weight: 700; pointer-events: none; }
#plan .etool:hover text.etool-t { fill: #fff; }
.shape-tips { display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.7; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }

/* رمز الدرج */
#plan .stair { pointer-events: none; }
#plan .stair-step { fill: rgba(255,255,255,.35); stroke: #6d6656; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .stair-land { fill: rgba(255,255,255,.2); stroke: #6d6656; stroke-width: 1; vector-effect: non-scaling-stroke; }
#plan .stair-arrow { fill: none; stroke: #3d382e; stroke-linejoin: round; }
#plan .stair-dot { fill: #3d382e; }

/* المسافة من الجدار المحدد إلى الجدران المجاورة */
#plan .gap-dim { fill: none; stroke: #b4531f; stroke-width: 1.4; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan text.gap-txt { fill: #b4531f; font-weight: 700; paint-order: stroke; stroke: #fff; stroke-width: 3px; pointer-events: none; }
#plan .glassf { fill: #9fd3ea; stroke: #2d7fa8; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.elev { display: block; width: 100%; max-height: 190px; margin: 4px 0 6px; touch-action: none; }
.elev-wall { fill: #e9e3d6; stroke: #b9ae9c; stroke-width: 1; }
.elev-glass { fill: #9fd3ea; stroke: #2d7fa8; stroke-width: 1.5; }
.elev-door { fill: #c79a6e; stroke: #7a5536; stroke-width: 1.5; }
.elev-h { fill: rgba(15,110,106,.25); cursor: ns-resize; }
.elev-h:hover { fill: rgba(15,110,106,.5); }
.elev-t { font-size: 12px; fill: #1f2a2e; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
#plan .room.pergola { stroke: #8a5a32; stroke-dasharray: 0.3 0.15; }
#plan .pergola line { stroke: #8a5a32; stroke-width: 1.2; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .fall { stroke: #2d9fd8; stroke-linecap: round; pointer-events: none; }
#plan .poolcut { stroke: #fff; stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .amk { pointer-events: none; }
#plan .amk .counter { fill: #f3eee4; stroke: #6b5a45; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
#plan .room.plants { stroke: #4d7d2e; stroke-dasharray: 0.3 0.15; }
#plan .room.paving { stroke: #7d7064; }
#plan circle.plant { fill: #3f7d32; fill-opacity: 0.75; stroke: #2c5a22; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan circle.plant.palm { fill: #6f9a3c; }
#plan circle.plant.cypress { fill: #2f6b3a; }
#plan circle.plant.flowers { fill: #e2668a; stroke: none; }
#plan circle.plant.citrus { fill: #4b8a32; stroke: #f29a1f; }
#plan .room.tent { stroke: #1c1c1c; }
#plan .tentl { stroke: #8a8378; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .tentc { stroke: #1c1c1c; stroke-width: 4; stroke-dasharray: 6 3; vector-effect: non-scaling-stroke; pointer-events: none; }
#plan .room.car { stroke: #55606b; }
#plan .carcab { fill: #1d2a33; fill-opacity: 0.55; pointer-events: none; }
#plan .esteps { fill: #ece8e1; stroke: #8a8172; stroke-width: 0.03; }
#plan .room-dim { fill: #5b6670; }
#plan .furn .ff { fill: #fbfaf7; stroke: #5f5a52; stroke-width: 0.015; }
#plan .furn .fd { fill: #8a7a68; stroke: none; }
#plan .furn .fw { fill: #ffffff; stroke: #8f8a82; stroke-width: 0.012; }
#plan .furn .fblanket { stroke: #5f5a52; stroke-width: 0.012; }
#plan .furn .fshade { fill: #000; fill-opacity: 0.18; stroke: none; }
#plan .furn .frug { stroke: none; }
#plan .furn .frugin { fill: none; stroke: #fff; stroke-opacity: 0.55; stroke-width: 0.04; }
#plan .furn .fl { stroke: #5f5a52; stroke-width: 0.012; fill: none; }
#plan .furn .fburn { fill: none; stroke: #2a2a2a; stroke-width: 0.02; }
#plan .furn .fsteel { fill: #c9ced2; stroke: #6d737a; stroke-width: 0.012; }
#plan .furn .fwater { fill: #cfe8f0; stroke: #8fb3c0; stroke-width: 0.012; }
#plan .furn .fscreen { fill: #1b1f24; }
#plan .furn .fhit { fill: transparent; stroke: none; cursor: move; }
#plan .furn .fsel { fill: rgba(31,122,110,0.08); stroke: #1f7a6e; stroke-width: 0.03; stroke-dasharray: 0.08 0.05; cursor: move; }
.stage:fullscreen { background: var(--bg, #f6f3ec); }
.stage.full { position: fixed; inset: 0; z-index: 900; background: var(--bg, #f6f3ec); height: auto; }
.film-cap { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(20,24,28,0.72); color: #fff; padding: 8px 18px 10px; border-radius: 12px; text-align: center; pointer-events: none; min-width: 200px; }
.film-cap b { display: block; font-size: 15px; margin-bottom: 6px; }
.film-cap i { display: block; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.25); overflow: hidden; }
.film-cap span { display: block; height: 100%; width: 0; background: #e3b04b; }
.timebar { position: absolute; bottom: 12px; inset-inline-end: 12px; display: flex; align-items: center; gap: 6px; background: rgba(31,42,46,.82); color: #fff; padding: 6px 12px; border-radius: 12px; width: min(380px, calc(100% - 24px)); z-index: 5; }
.timebar input { flex: 1; accent-color: #e3b04b; }
.timebar b { font-size: 13px; min-width: 82px; text-align: center; font-weight: 600; }

/* مجموعات خطوة الإنارة: بطاقة قابلة للطي لكل نوع إنارة */
details:has(> .lt-sum) { border: 1px solid var(--line, #e2ddd3); border-radius: var(--radius, 10px); padding: 10px 12px; margin: 10px 0; }
.lt-sum { cursor: pointer; font-weight: 700; list-style-position: inside; }
.lt-sum .lt-on { font-weight: 500; font-size: 12px; color: #b07a12; background: #fff4dc; border-radius: 999px; padding: 1px 8px; margin-inline-start: 6px; }
details[open] > .lt-sum { margin-bottom: 8px; }
.list .item[data-act] { cursor: pointer; }

/* ===== ترتيب الشريط العلوي وشريط الأدوات ===== */
.top.st-compact .stepper button .t { display: none; }
.top.st-compact .stepper button.active .t { display: inline; }
.top.st-row { flex-wrap: wrap; row-gap: 6px; }
.top.st-row .stepper { order: 3; flex-basis: 100%; }
.top.st-row .top-actions { margin-inline-start: auto; }
.stepper { justify-content: safe center; }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.toolbar .btn .ic { display: inline-block; }
.toolbar .btn .ic + .tl { margin-inline-start: 4px; }
.tb-more .menu-list { inset-inline-end: 0; min-width: 230px; }
.tb-more .menu-list button { font-size: 14px; }
.film-cap { pointer-events: auto; }
.film-cap .film-pp { position: absolute; inset-inline-start: -46px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(20,24,28,0.72); color: #fff; font-size: 16px; cursor: pointer; }
.film-cap .film-pp:hover { background: rgba(20,24,28,0.9); }
.film-cap.paused b::after { content: " — متوقف مؤقتاً"; color: #e3b04b; }
.toast-btn { margin-inline-start: 10px; border: 0; border-radius: 8px; padding: 5px 10px; background: #e3b04b; color: #1f2a2e; font-weight: 700; cursor: pointer; font-family: inherit; }
.lt-cols .sw, .lt-custom .sw { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); margin-inline-end: 6px; vertical-align: -2px; }
.lt-custom { position: relative; cursor: pointer; }
.lt-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
@media (max-width: 860px) {
  .toolbar .btn .tl { display: none; }
  .toolbar .btn .ic + .tl { margin: 0; }
  .toolbar .seg { flex-wrap: wrap; }
  .film-cap .film-pp { inset-inline-start: auto; inset-inline-end: -46px; }
}

.top.st-tiny .stepper button.active .t { display: none; }
.top.st-tiny .stepper { justify-content: safe center; gap: 2px; }
.top.st-tiny .stepper button { padding: 6px 7px; }
.menu-list .menu-h { font-size: 12px; color: var(--muted); padding: 4px 10px 2px; }
