/* RAYVO 3D Viewer — app.css (dark glass theme, mobile first, RTL aware) */
:root {
  --bg: #070b17;
  --bg2: #0d1428;
  --panel: rgba(16, 23, 42, 0.92);
  --panel-solid: #101a31;
  --card: rgba(255, 255, 255, 0.05);
  --blue: #3b82f6;
  --cyan: #22d3ee;
  --violet: #8b5cf6;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.2);
  --danger: #f87171;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Sans", sans-serif; font-size: 15px;
  -webkit-user-select: none; user-select: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

#app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

/* ---------- top bar ---------- */
#topbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + var(--sat)) calc(12px + var(--sar)) 8px calc(12px + var(--sal));
  background: linear-gradient(180deg, rgba(13, 20, 40, .96), rgba(7, 11, 23, .9));
  border-bottom: 1px solid var(--border); z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.logo-text { font-weight: 800; letter-spacing: 3px; font-size: 18px;
  background: linear-gradient(90deg, var(--cyan), var(--blue), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.app-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 12px;
  padding: 0 14px; height: 38px; font-weight: 600; font-size: 14px; background: transparent; transition: transform .08s, background .15s; }
.btn:active { transform: scale(.96); }
.btn-primary { background: linear-gradient(135deg, var(--blue), var(--violet)); color: #fff; box-shadow: 0 4px 14px rgba(59, 130, 246, .35); }
.btn-soft { background: var(--card); border-color: var(--border); }
.btn-icon { width: 38px; padding: 0; background: var(--card); border-color: var(--border); }
.btn-small { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 10px; }
.btn-small.btn-icon { width: 32px; padding: 0; }
.btn-large { height: 48px; padding: 0 26px; font-size: 16px; border-radius: 14px; }
.btn.toggle-on { background: rgba(34, 211, 238, .18); border-color: rgba(34, 211, 238, .55); color: var(--cyan); }
.btn.danger { color: var(--danger); }

/* ---------- viewport ---------- */
#viewportWrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: var(--bg); }
#viewport { position: absolute; inset: 0; }
#viewport canvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }

#fileChip { position: absolute; top: 10px; inset-inline-start: 50%; transform: translateX(-50%); max-width: 70%;
  display: flex; gap: 8px; align-items: center; padding: 6px 12px; border-radius: 20px; font-size: 12px;
  background: var(--panel); border: 1px solid var(--border); pointer-events: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
html[dir="rtl"] #fileChip { transform: translateX(50%); }
#fileChipName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
#fileChipMeta { color: var(--muted); white-space: nowrap; }

#emptyState { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 24px; pointer-events: none; z-index: 2; }
#emptyState .btn { pointer-events: auto; }
.empty-logo { font-size: 44px; font-weight: 800; letter-spacing: 8px;
  background: linear-gradient(90deg, var(--cyan), var(--blue), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(34, 211, 238, .35)); }
.empty-sub { margin: 0; font-size: 17px; }
.empty-formats { margin: 0; font-size: 12px; color: var(--muted); max-width: 320px; line-height: 1.6; }
.empty-offline { margin: 0; font-size: 12px; color: var(--cyan); }
#viewportWrap.has-model #emptyState { display: none; }

/* floating buttons */
#sideBtns { position: absolute; top: 48px; inset-inline-end: calc(10px + var(--sar)); display: flex; flex-direction: column; gap: 10px; z-index: 5; }
#viewportWrap:not(.has-model) #sideBtns { display: none; }
.fab { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--border);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.fab:active { transform: scale(.94); }
.fab[aria-pressed="true"] { color: var(--cyan); border-color: rgba(34, 211, 238, .6); background: rgba(34, 211, 238, .14); }

/* animation bar */
#animBar { position: absolute; inset-inline: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--border); z-index: 6; flex-wrap: wrap; }
#animBar select { height: 34px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); padding: 0 6px; max-width: 34%; }
#animBar select option { color: #000; }
#animScrub { flex: 1 1 100px; min-width: 80px; accent-color: var(--cyan); }
#animTime { font-size: 11px; color: var(--muted); }

/* chips */
#selChip, #previewChip { position: absolute; inset-inline: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; padding: 6px 8px; flex-wrap: wrap;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--border); z-index: 6; }
#selName, #previewTitle { flex: 1 1 80px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.has-anim #selChip { bottom: 64px; }

/* loading */
#loadingOverlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(7, 11, 23, .72); z-index: 30; }
.loader-card { width: min(320px, 82%); padding: 22px; border-radius: 20px; background: var(--panel-solid); border: 1px solid var(--border); text-align: center; }
.loader-logo { font-weight: 800; letter-spacing: 5px; font-size: 22px; color: var(--cyan); margin-bottom: 8px; }
.loader-file { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; }
.loader-stage { margin: 10px 0 12px; font-size: 14px; }
.loader-track { height: 6px; border-radius: 6px; background: rgba(255,255,255,.1); overflow: hidden; }
.loader-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--blue), var(--violet)); transition: width .25s; }
.loader-pct { margin-top: 8px; font-size: 12px; color: var(--muted); }

#toast { position: fixed; bottom: calc(90px + var(--sab)); inset-inline: 0; margin-inline: auto; width: max-content; max-width: 86%; padding: 10px 16px; border-radius: 14px;
  background: rgba(15, 23, 42, .96); border: 1px solid var(--border); font-size: 13px; z-index: 95; text-align: center; white-space: pre-line; }

/* ---------- dock ---------- */
#dock { flex: none; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; justify-content: safe center;
  padding: 6px calc(8px + var(--sar)) calc(6px + var(--sab)) calc(8px + var(--sal));
  background: linear-gradient(0deg, rgba(13, 20, 40, .97), rgba(7, 11, 23, .92)); border-top: 1px solid var(--border); z-index: 20; }
#dock::-webkit-scrollbar { display: none; }
.dk { flex: 1 1 0; max-width: 92px; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 7px 4px; border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; }
.dk span { white-space: nowrap; }
.dk:active { background: var(--card); }
.dk.toggle[aria-pressed="true"], .dk.active { color: var(--cyan); background: rgba(34, 211, 238, .1); }
#dock.disabled .dk { opacity: .45; pointer-events: none; }

/* ---------- bottom sheet ---------- */
#sheetBackdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; }
#sheet { position: fixed; inset-inline: 0; bottom: 0; max-height: 78dvh; display: flex; flex-direction: column; z-index: 60;
  background: var(--panel-solid); border-top: 1px solid var(--border); border-radius: 22px 22px 0 0;
  transform: translateY(105%); transition: transform .26s cubic-bezier(.2, .8, .2, 1); padding-bottom: var(--sab);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .5); }
#sheet.open { transform: translateY(0); }
.sheet-handle { width: 42px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.22); margin: 8px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 8px; flex: none; }
.sheet-head h2 { margin: 0; font-size: 17px; }
#sheetContent { overflow-y: auto; padding: 0 14px 18px; -webkit-overflow-scrolling: touch; user-select: text; -webkit-user-select: text; }

.panel-section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin: 8px 0; overflow: hidden; }
.panel-section > summary { list-style: none; padding: 12px 14px; font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.panel-section > summary::-webkit-details-marker { display: none; }
.panel-section > summary::after { content: "▾"; color: var(--muted); transition: transform .2s; }
.panel-section[open] > summary::after { transform: rotate(180deg); }
.panel-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.row > label { flex: 1 1 40%; font-size: 13px; color: #cbd5e1; }
.row input[type="range"] { flex: 1.6 1 0; accent-color: var(--cyan); min-width: 0; height: 28px; }
.row .val { width: 42px; text-align: end; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row input[type="color"] { width: 44px; height: 32px; border: 1px solid var(--border); border-radius: 8px; background: transparent; padding: 0; }
.row input[type="number"], .row select { flex: 1.4 1 0; min-width: 0; height: 36px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); padding: 0 10px; }
.row select option, .row select optgroup { color: #000; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-width: 0; height: 34px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); font-size: 13px; padding: 0 10px; }
.seg button.active { background: rgba(34, 211, 238, .18); border-color: rgba(34, 211, 238, .6); color: var(--cyan); font-weight: 700; }
.hint { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.55; }
.center { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.04); min-width: 0; }
.stat b { font-size: 11px; color: var(--muted); font-weight: 600; }
.stat span { font-size: 13px; overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }
.tree-item { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.tree-item .tname { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: start; }
.btn-block { width: 100%; }

/* ---------- error modal ---------- */
#errorModal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .6); z-index: 100; padding: 20px; }
.error-card { width: min(380px, 100%); background: var(--panel-solid); border: 1px solid var(--border); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.error-card h2 { margin: 0; font-size: 18px; color: var(--danger); }
.error-card p { margin: 0; line-height: 1.6; }
.error-card pre { max-height: 140px; overflow: auto; font-size: 11px; white-space: pre-wrap; background: rgba(0,0,0,.35); padding: 8px; border-radius: 8px; user-select: text; -webkit-user-select: text; direction: ltr; }
.error-card summary { color: var(--muted); font-size: 13px; }

@media (min-width: 700px) {
  #sheet { inset-inline: auto; inset-inline-end: 16px; width: 420px; bottom: 76px; border-radius: 22px; max-height: 70dvh; }
}
@media (max-width: 480px) { .app-name { display: none; } }
@media (max-height: 420px) { #sheet { max-height: 92dvh; } .empty-logo { font-size: 28px; } }

select.full { width: 100%; height: 40px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); padding: 0 10px; direction: ltr; text-align: start; }
select.full option { color: #000; }

/* ---------- compact dropdown ---------- */
.dd-btn { width: 100%; height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px; margin: 4px 0 8px;
  border-radius: 10px; background: var(--card); border: 1px solid var(--border); font-size: 13px; direction: ltr; text-align: start; }
.dd-btn .dd-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn svg { flex: 0 0 auto; color: var(--muted); }
.dd-list { position: fixed; z-index: 200; overflow-y: auto; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0,0,0,.55); padding: 4px; -webkit-overflow-scrolling: touch; }
.dd-item { display: block; width: 100%; text-align: start; border: 0; background: transparent; color: var(--text); font-size: 12.5px; line-height: 1.2; padding: 9px 10px; border-radius: 8px; }
.dd-item:active { background: rgba(255,255,255,.08); }
.dd-item.on { background: rgba(34, 211, 238, .16); color: var(--cyan); }

.tree-item .sw { width: 12px; height: 12px; border-radius: 4px; flex: 0 0 auto; }
.tree-item.sel { background: rgba(34, 211, 238, .12); border-radius: 10px; }
.tree-item small { color: var(--muted); font-size: 11px; }
input[type="range"][data-k="explode"] { flex: 1.4 1 0; accent-color: var(--cyan); }

/* ---------- report preview ---------- */
#reportModal { position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; background: var(--bg); }
#reportModal[hidden] { display: none; }
.rm-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(8px + var(--sat)) 12px 8px; border-bottom: 1px solid var(--border); background: var(--panel-solid); }
.rm-head #reportTitle { flex: 1; text-align: center; font-weight: 600; font-size: 14px; }
.rm-zoom { display: flex; gap: 6px; }
#reportPages { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 10px; background: #1a2238; touch-action: pan-x pan-y; }
#reportPages img { display: block; width: 100%; height: auto; margin: 0 auto 12px; background: #fff; border-radius: 4px; box-shadow: 0 4px 18px rgba(0,0,0,.5); }
.rm-foot { display: flex; gap: 10px; padding: 10px 12px calc(10px + var(--sab)); border-top: 1px solid var(--border); background: var(--panel-solid); }
.rm-foot .btn { flex: 1; height: 44px; }
#sideBtns { max-height: calc(100% - 56px); overflow-y: auto; scrollbar-width: none; } #sideBtns::-webkit-scrollbar { display: none; }
