:root {
  --bg: #f6f3ef;
  --card: #fff;
  --text: #2a2420;
  --muted: #7a6f66;
  --border: #e7dfd6;
  --primary: #8a5a2b;
  --primary-dark: #6f4620;
  --danger: #c43b3b;
  --success: #1f8a4c;
  --warning: #b97a0a;
  --radius: 10px;
}
* { box-sizing: border-box; }
/* ممنوع سكرول جانبي بالصفحة — الجداول العريضة بتتمرّر جوا مكانها */
html, body { overflow-x: clip; max-width: 100%; } /* clip مش hidden: hidden بيخرّب sticky (اللوحة اللي بتنزل مع السكرول) */
img, svg, canvas, video { max-width: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
  padding-bottom: 70px;
}
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: #3b2a1c; color: #fff; padding: 10px 20px;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: #e6d8c8; padding: 7px 12px; border-radius: 8px; text-decoration: none; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar .account { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .account .muted { color: #d9c9b6; }
.sync { font-size: 12.5px; color: #d9c9b6; }
.sync.ok { color: #9fe0b4; }
.sync.bad { color: #ffb4a0; font-weight: 700; }

/* ===== الصلاحيات ===== */
/* المهندس: بدون أي سعر. الشغيلة: أوراق القص بس */
body:not(.role-admin) .admin-only { display: none !important; }
body.role-worker .no-worker { display: none !important; }
body:not(.role-admin) .price-only { display: none !important; }
body:not(.role-admin) .extras th:nth-child(4), body:not(.role-admin) .extras td:nth-child(4) { display: none; }
body:not(.role-admin) #bottombar > div:first-child { display: none; }
body.role-worker #bottombar, body.role-worker [data-tab="design"] { display: none !important; }
.status-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; background: #f6f1ea; border: 1px solid #e5dccf; }
.status-bar.sent { background: #e9f5ee; border-color: #bfe2cd; }
.locked-note { background: #fff4e0; border: 1px solid #f0d9a8; color: #7a5300; border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; }

main { max-width: 1150px; margin: 0 auto; padding: 18px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 4px 0 10px; font-size: 15px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.row-head h2 { margin: 0; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit;
}
.btn:hover { background: #f5efe8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f0c9c9; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
input, select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 9px;
  border: 1px solid var(--border); border-radius: 8px; font: inherit; color: var(--text); background: #fff;
}
select.inline { display: inline-block; width: auto; margin: 0; padding: 5px 8px; font-size: 13px; }
input:focus, select:focus { outline: 2px solid #e2c9ad; border-color: var(--primary); }
input[type=number] { direction: ltr; text-align: right; }
input[type=checkbox] { width: auto; display: inline-block; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }

.setup { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 12px; }
select.need { border: 2px dashed var(--warning); background: #fff8ea; }
.setup .q { font-weight: 700; margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid #cdb89f; background: #fff; border-radius: 8px; padding: 9px 14px; font: inherit; cursor: pointer; color: var(--text); }
.seg button.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.seg button:not(.on):hover { background: #f6ede2; }
.seg.missing button { border-color: var(--warning); border-style: dashed; }
.setup .hint { margin-top: 6px; }
.ai-card { border: 2px solid #d9c2a6; }
.ai-grid { display: grid; grid-template-columns: 230px 1fr; gap: 16px; margin-top: 12px; }
.ai-grid > * { min-width: 0; }
.ai-img { transition: transform .25s; }
.ai-prev svg.eng { max-height: 330px; }
.ai-grid img { width: 100%; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.ai-summary { background: #fbf8f4; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; line-height: 1.7; }
.conf { display: inline-block; border-radius: 10px; padding: 1px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.conf.high { background: #dff3e6; color: #1f7a45; }
.conf.medium { background: #fff1d6; color: #8a5a00; }
.conf.low { background: #fde2e2; color: #a12d2d; }
.conf.edited { background: #e2ecfb; color: #1d4f9c; }
.ai-units input { width: 62px; padding: 4px 6px; }
.ai-units td { white-space: nowrap; }
.ai-units td.seen { white-space: normal; min-width: 160px; }
.ai-units td.ai-name input, .ai-units td.ai-name select { width: 170px; margin: 0 0 4px; padding: 4px 6px; font-size: 13px; }
.ai-units td.ai-name input { font-weight: 700; }
.seen { color: var(--muted); font-size: 13px; }
.aq { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.aq.done { border-color: #b9dcc6; background: #f7fcf9; }
.aq .t { font-weight: 700; margin-bottom: 2px; }
.aq .why { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.wide-warn { color: #a35d00; font-size: 12px; font-weight: 700; margin: 4px 0 2px; }
.seg button.learned { border-color: #d4a017; background: #fff9e6; }
.seg button.learned.on { background: var(--primary); border-color: var(--primary); }
.notes { background: #f3f8ff; border-color: #cfe0f5; }
.notes ul { margin: 6px 0 0; padding-right: 20px; }
.len-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.len-row input { width: 110px; margin: 0; font-size: 16px; font-weight: 700; }
.ai-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
@media (max-width: 720px) { .ai-grid { grid-template-columns: 1fr; } .ai-grid img { max-width: 260px; } }
.sections { display: flex; flex-wrap: wrap; gap: 8px; }
.sec-chip { display: flex; align-items: center; gap: 6px; border: 2px solid var(--sc, #cdb89f); border-radius: 10px; padding: 4px 8px; background: #fff; }
.sec-chip .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--sc); flex: none; }
.sec-chip input { width: auto; max-width: 320px; margin: 0; padding: 4px 6px; border: 0; font-weight: 700; }
.sec-chip .cnt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.sec-head { display: flex; align-items: center; gap: 8px; margin: 18px 4px 8px; font-size: 17px; font-weight: 700; }
.sec-head .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--sc); }
.type-grid.locked { opacity: .4; pointer-events: none; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.type-btn {
  border: 1px dashed #cdb89f; background: #fbf8f4; border-radius: 10px; padding: 12px 8px;
  cursor: pointer; font: inherit; color: var(--text); text-align: center;
}
.type-btn:hover { border-style: solid; border-color: var(--primary); background: #f6ede2; }
.type-btn span { display: block; font-size: 22px; margin-bottom: 4px; }

/* بطاقة القطعة */
.unit { display: grid; grid-template-columns: 1fr 150px; gap: 14px; }
.unit-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.unit-head .num { background: var(--primary); color: #fff; border-radius: 6px; padding: 2px 9px; font-weight: 700; }
.unit-head .type { font-weight: 700; }
.unit-head input { width: auto; flex: 1; min-width: 140px; margin: 0; }
.unit-head .qty { width: 70px; flex: none; }
.unit-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 0 10px; }
.unit-fields label { margin-bottom: 6px; }
.unit-fields .wide { grid-column: span 2; }
.sketch { display: flex; align-items: center; justify-content: center; background: #fbf8f4; border-radius: 8px; border: 1px solid var(--border); }
.sketch svg { width: 100%; height: auto; max-height: 220px; }
.warn { background: #fff6e5; border: 1px solid #f0d9a8; color: #7a5208; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; }

/* جداول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #fbf8f4; }
td input, td select { margin: 0; padding: 5px 7px; }
td.num, th.num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
tr.grand td { font-weight: 700; font-size: 17px; color: var(--primary); }
table.extras td:nth-child(2), table.extras td:nth-child(4) { width: 110px; }
table.extras td:nth-child(3) { width: 110px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.main { background: var(--primary); color: #fff; border-color: var(--primary); }
.stat.main .label { color: #f0e1d0; }

.hw-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.hw { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fbf8f4; }
.hw b { font-size: 20px; display: block; }

.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.sheet { border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.sheet .cap { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.sheet svg { width: 100%; height: auto; display: block; }

svg.eng { width: 100%; height: auto; max-height: 560px; display: block; background: #fff; border: 1px solid var(--border); border-radius: 8px; direction: ltr; }
svg.eng.box { max-width: 620px; }
.eng text { fill: #2a2420; font-family: "Segoe UI", Tahoma, Arial, sans-serif; }
.eng .dimg line { stroke: #b0482c; stroke-width: 0.35; }
.eng .dimg text { fill: #b0482c; }
.eng .badge circle { fill: #3b2a1c; }
.eng .badge text { fill: #fff; font-weight: 700; }
.sec-card { border-top: 5px solid var(--sc); }
.sec-card h3 { margin: 16px 0 8px; }
.sec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--sc); margin-left: 4px; }
details.box-d { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; background: #fffdfa; }
details.box-d summary { cursor: pointer; font-weight: 700; }
details.box-d[open] summary { margin-bottom: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; font-size: 13px; }
.pc rect { fill: var(--pf, #e8cfae); stroke: #6f4620; stroke-width: .5; cursor: pointer; }
.pc text { fill: #3b2a1c; pointer-events: none; }
.pc text.dim { fill: #5a4a3c; }
.pc:hover rect, .pc.hl rect { fill: #f2b45c; }
tr[data-row] { cursor: pointer; }
tr.hl td { background: #fdebcf; }
.pno { display: inline-block; min-width: 26px; text-align: center; background: #3b2a1c; color: #fff; border-radius: 6px; padding: 1px 6px; font-weight: 700; }
.pc-tip {
  position: fixed; z-index: 50; background: #2a2420; color: #fff; border-radius: 8px; padding: 8px 12px;
  font-size: 13px; line-height: 1.6; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 260px;
}
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border);
  display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 10px 20px; z-index: 9;
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.bottombar b { font-size: 20px; color: var(--primary); }

#printArea { display: none; }

@media (max-width: 720px) {
  main { padding: 10px; }
  .grid3, .setup { grid-template-columns: 1fr; }
  .unit { grid-template-columns: 1fr; }
  .sketch { max-width: 200px; }
  .bottombar #liveInfo { display: none; }
}

/* عرض السعر للزبون */
.q-sec { margin-bottom: 22px; break-inside: avoid; }
.q-sec h2 { font-size: 18px; margin: 10px 0; border-bottom: 3px solid var(--sc); padding-bottom: 4px; }
.q-sec .sec-dot { --sc: inherit; }
.q-views { display: grid; grid-template-columns: 1fr; gap: 10px; }
.q-views > div:last-child svg { max-width: 80%; }
.q-cap { font-weight: 700; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.q-units { margin-top: 10px; font-size: 13px; }
.q-total { border: 2px solid #000; border-radius: 8px; padding: 12px 16px; margin-top: 16px; display: grid; gap: 6px; }
.q-price { font-size: 22px; font-weight: 800; }

/* الطباعة */
.p-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
.p-head h1 { margin: 0; font-size: 22px; }
@media print {
  body { background: #fff; padding: 0; }
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing #printArea { display: block; }
  .sheet { break-inside: avoid; }
  table { font-size: 12px; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
