* { box-sizing: border-box; margin: 0; }
:root { --blue: #1766c4; --blue-d: #11508f; --bg: #f4f6f9; --card: #fff; --text: #1c2733; --muted: #67707c; }
body { font-family: 'Tajawal', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  background: var(--blue); color: #fff; padding: 12px 16px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.brand { font-size: 1.2rem; font-weight: 700; }
.cart-btn { background: rgba(255,255,255,.15); border: none; color: #fff; font-size: 1rem; padding: 8px 14px; border-radius: 20px; cursor: pointer; }
.cart-btn:hover { background: rgba(255,255,255,.25); }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.card { background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.08); display: flex; flex-direction: column; }
.card img, .card .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; background: #e8eef5; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: #b3c2d1; }
.card .body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .name { font-weight: 600; font-size: .95rem; }
.card .price { color: var(--blue); font-weight: 700; }
.card button { margin-top: auto; background: var(--blue); color: #fff; border: none; padding: 8px; border-radius: 8px; cursor: pointer; font-family: inherit; }
.card button:hover { background: var(--blue-d); }

.panel { background: var(--card); border-radius: 12px; padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.panel h2 { margin-bottom: 12px; font-size: 1.1rem; }
.line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #eef1f5; }
.line .n { flex: 1; }
.line .qty { display: flex; align-items: center; gap: 6px; }
.line .qty button { width: 26px; height: 26px; border: 1px solid #d4dbe3; background: #fff; border-radius: 6px; cursor: pointer; }
.total { display: flex; justify-content: space-between; font-weight: 700; padding: 12px 0; font-size: 1.05rem; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea { width: 100%; padding: 10px; border: 1px solid #d4dbe3; border-radius: 8px; font-family: inherit; font-size: 1rem; }
.btn-primary { width: 100%; background: var(--blue); color: #fff; border: none; padding: 12px; border-radius: 8px; font-size: 1rem; cursor: pointer; font-family: inherit; }
.btn-primary:hover { background: var(--blue-d); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-link { background: none; border: none; color: var(--blue); cursor: pointer; font-family: inherit; padding: 8px 0; }

/* ---- product page + 3D viewer ---- */
.fade-in { animation: fadein .3s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card .media { position: relative; cursor: pointer; }
.card .media img { transition: transform .25s ease; display: block; }
.card:hover .media img { transform: scale(1.04); }
.card .name { cursor: pointer; }
.badge3d { position: absolute; top: 8px; inset-inline-start: 8px; background: var(--blue); color: #fff;
  font-size: .7rem; font-weight: 700; padding: 3px 8px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.card button.added { background: #1e9e4a; }

.product h2 { margin-top: 12px; }
.product .desc { color: var(--muted); font-size: .92rem; margin: 6px 0; line-height: 1.6; }
.product .big-price { font-size: 1.3rem; font-weight: 800; color: var(--blue); margin: 8px 0 12px; }
.hero { width: 100%; max-height: 55vh; object-fit: contain; border-radius: 12px; background: #eef3f8; }

.viewer-wrap, .parts { position: relative; }
model-viewer { width: 100%; height: clamp(260px, 55vh, 480px); background: #eef3f8; border-radius: 12px;
  touch-action: pan-y; }
.parts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: 12px; }
.parts-grid model-viewer { height: clamp(200px, 34vh, 300px); }
.part .pname { text-align: center; padding: 8px 4px; font-weight: 600; font-size: .9rem; }
.qtytag { background: var(--blue); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: .78rem; }
.hint { position: absolute; bottom: 10px; inset-inline-start: 50%; transform: translateX(50%);
  background: rgba(28,39,51,.75); color: #fff; font-size: .78rem; padding: 6px 12px; border-radius: 16px;
  pointer-events: none; white-space: nowrap; max-width: 95%; overflow: hidden; text-overflow: ellipsis; }
.hint-top { position: static; display: block; transform: none; margin: 0 auto 10px; width: fit-content; }

.notice { text-align: center; color: var(--muted); padding: 40px 0; }
.success { text-align: center; padding: 30px 10px; }
.success .big { font-size: 3rem; }
.err { color: #c0392b; font-size: .9rem; margin-top: 8px; }
