/* Shape library picker + maths keyboard */
body.sp-open { overflow: hidden; }
.sp { position: fixed; inset: 0; z-index: 80; background: #f4f6fa; display: flex; flex-direction: column; }
.sp[hidden] { display: none; }
.sp-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); background: linear-gradient(135deg, #0f766e, #115e59); color: #fff; flex-wrap: wrap; }
.sp-top .ghost { color: #fff; border-color: rgba(255,255,255,.4); padding: 6px 12px; }
.sp-title { font-size: 17px; }
.sp-search { flex: 1; min-width: 160px; border: 0; border-radius: 12px; padding: 10px 14px; font-size: 15px; background: #fff; }
.sp-chips { display: flex; gap: 6px; padding: 8px 12px 2px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.sp-chips::-webkit-scrollbar { display: none; }
.sp-chips button { flex-shrink: 0; border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.sp-chips button.on { background: #0f766e; border-color: #0f766e; color: #fff; }
.sp-grades button { font-size: 12px; padding: 4px 11px; background: #f8fafc; }
.sp-grid { flex: 1; overflow-y: auto; padding: 10px 12px calc(20px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; }
.sp-card { display: flex; flex-direction: column; align-items: center; gap: 4px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 8px; min-height: 140px; }
.sp-card:hover, .sp-card:active { border-color: #0f766e; box-shadow: 0 2px 10px rgba(15,118,110,.18); }
.sp-thumb { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; max-height: 110px; overflow: hidden; direction: ltr; }
.sp-thumb svg { max-width: 100%; max-height: 108px; width: auto; height: auto; }
.sp-name { font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.35; }
.sp-empty { grid-column: 1 / -1; text-align: center; padding: 40px 0; }

.sp-detail { flex: 1; overflow-y: auto; display: flex; gap: 14px; padding: 14px; flex-wrap: wrap; align-content: flex-start; }
.sp-detail[hidden] { display: none; }
.sp-prev { flex: 1 1 320px; min-height: 220px; background: #fff; border: 1px solid var(--border); border-radius: 14px; display: flex; align-items: center; justify-content: center; padding: 12px; overflow: auto; direction: ltr; }
.sp-prev svg { max-width: 100%; height: auto; }
.sp-side { flex: 1 1 300px; display: flex; flex-direction: column; gap: 8px; }
.sp-side h4 { margin: 0; font-size: 17px; }
.sp-labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; max-height: 38vh; overflow-y: auto; padding: 2px; }
.sp-labels label { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 3px 8px; }
.sp-labels label span { color: var(--muted); font-size: 11px; min-width: 14px; }
.sp-labels input { border: 0; outline: 0; width: 100%; padding: 7px 2px; font-size: 15px; font-family: "Times New Roman", serif; background: transparent; }
.sp-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.sp-row label { font-size: 12.5px; font-weight: 600; }
.sp-row select, .sp-row input[type=range] { display: block; margin-top: 4px; }
.sp-row .primary { flex: 1; padding: 12px; }
.sp-row .ghost { padding: 12px; }

/* "من المكتبة" button inside the figure dialog */
.fig-lib { width: 100%; margin: 6px 0 10px; padding: 11px !important; border-radius: 12px; border-style: dashed; font-weight: 700; color: #0f766e; }

/* maths keyboard (emoji-style) */
.mp { margin: 8px 0; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: #fff; }
.mp-search { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 9px 12px; font-size: 14px; outline: 0; }
.mp-tabs { display: flex; overflow-x: auto; background: #f1f5f9; scrollbar-width: none; }
.mp-tabs::-webkit-scrollbar { display: none; }
.mp-tabs button { flex-shrink: 0; border: 0; background: none; padding: 8px 11px; font-size: 13px; font-weight: 600; white-space: nowrap; color: #475569; border-bottom: 3px solid transparent; }
.mp-tabs button.on { color: #0f766e; background: #fff; border-bottom-color: #0f766e; }
.mp-grid { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px; max-height: 210px; overflow-y: auto; direction: ltr; align-content: flex-start; }
.mp-key { min-width: 46px; height: 44px; padding: 0 8px; border: 1px solid var(--border); background: #fff; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.mp-key:hover, .mp-key:active { border-color: #0f766e; background: #f0fdfa; }
.mp-key .katex { font-size: 1.05em; }
.mp-empty { padding: 18px; color: var(--muted); font-size: 13px; width: 100%; text-align: center; direction: rtl; }

/* scanner save dialog */
.sv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 6px 0 10px; }
.sv-fmt { border: 2px solid var(--border); border-radius: 12px; background: #fff; padding: 10px 6px; text-align: center; font-weight: 700; font-size: 14px; }
.sv-fmt small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.sv-fmt.on { border-color: #0f766e; background: #f0fdfa; color: #0f766e; }
.sv-note { background: #f8fafc; border-radius: 10px; padding: 8px 10px; font-size: 12.5px; color: var(--muted); }

body.app-shell .sp-grid { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 760px) { .sp-detail { flex-wrap: nowrap; } }
