/* وصل · الطابع الفنتج */
:root {
  --paper: #F3E7D6; --card: #FBF5EC; --field: #FFFDF8;
  --line: #D8C4A8; --line-soft: #E6D5BC; --line-strong: #B9A283;
  --ink: #2E1F17; --ink-2: #6B5444; --ink-3: #A8968A;
  --clay: #A9472A; --clay-dark: #6E2A16; --peach: #E9B79F;
  --gold: #A07A2E; --teal: #2F5F5C; --teal-dark: #1E3F3D; --teal-soft: #E6EFEC;
  --green: #2E6B3A; --green-dark: #1C4424; --green-soft: #EAF0E3;
  --red: #8E1F1F; --red-soft: #F6E3DF; --yellow: #7A5A0B; --yellow-soft: #F7EDD6;
  --blue: #2B4C7E; --purple: #5B2D8F; --gray: #5A4A40;
  --serif: 'Amiri', serif; --body: 'Noto Naskh Arabic', serif; --ruqaa: 'Aref Ruqaa', serif;
  --nav-h: 62px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: var(--body); color: var(--ink); -webkit-tap-highlight-color: transparent; }
.paper {
  background-color: var(--paper);
  background-image: radial-gradient(rgba(90,60,30,.08) 1px, transparent 1.2px), radial-gradient(rgba(90,60,30,.05) 1px, transparent 1.2px);
  background-size: 7px 7px, 11px 11px; background-position: 0 0, 3px 5px;
  animation: drift 60s linear infinite;
}
@keyframes drift { to { background-position: 140px 70px, -80px 120px; } }
@media (prefers-reduced-motion: reduce) { .paper { animation: none; } * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
a { color: var(--teal); }
button, input, select, textarea { font-family: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; }

/* التخطيط */
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 0 14px calc(var(--nav-h) + 24px); }
.screen.wide { max-width: 1180px; }
.head { padding: 18px 4px 12px; border-bottom: 3px double var(--gold); margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
h1 { margin: 0; font-family: var(--serif); font-size: 28px; font-weight: 700; }
h2 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 700; }
.muted { color: var(--ink-2); font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hide { display: none !important; }
.center { text-align: center; }

/* البطاقات */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 14px; }
.card.framed { box-shadow: inset 0 0 0 5px var(--card), inset 0 0 0 6px var(--line-soft); }
.card.ok { border: 1.5px solid var(--green); background: var(--green-soft); }
.card.warn { border: 1.5px dashed #C9A35B; background: var(--field); }
.card.alert { border: 2px solid var(--red); background: var(--red-soft); }
.dash { border-top: 1.5px dashed var(--line); padding-top: 8px; }
.label { font-size: 14px; font-weight: 700; color: var(--ink-2); }

/* الأزرار */
.btn {
  min-height: 46px; padding: 0 16px; border-radius: 4px; border: 1.5px solid var(--line-strong);
  background: var(--card); font-family: var(--serif); font-size: 18px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--ink);
  box-shadow: 0 3px 0 #C9B394; transition: transform .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(2px) scale(.98); box-shadow: 0 1px 0 #C9B394; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.main { background: var(--clay); color: var(--card); border: none; box-shadow: 0 4px 0 var(--clay-dark); }
.btn.main:active { box-shadow: 0 1px 0 var(--clay-dark); }
.btn.teal { background: var(--teal); color: var(--card); border: none; box-shadow: 0 4px 0 var(--teal-dark); }
.btn.teal:active { box-shadow: 0 1px 0 var(--teal-dark); }
.btn.green { background: var(--green); color: var(--card); border: none; box-shadow: 0 3px 0 var(--green-dark); }
.btn.danger { background: transparent; color: var(--red); border: 1.5px dashed var(--red); box-shadow: none; }
.btn.outline-teal { border-color: var(--teal); color: var(--teal-dark); }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 22px; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 16px; }
.btn.icon { width: 42px; padding: 0; min-height: 42px; }
.pill { min-height: 38px; padding: 0 14px; border-radius: 4px; border: 1.5px solid var(--line-strong); background: var(--card);
  font-family: var(--serif); font-size: 17px; cursor: pointer; white-space: nowrap; }
.pill.on { background: var(--ink); color: var(--card); border-color: var(--ink); font-weight: 700; }
.pill.on.clay { background: var(--clay); border-color: var(--clay); }
.pill.on.teal { background: var(--teal); border-color: var(--teal); }
.pills { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.pills.fill > * { flex: 1; }

/* الحقول */
.field { display: flex; flex-direction: column; gap: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 4px;
  background: var(--field); font-size: 16px; color: var(--ink); transition: border-color .2s, background-color .3s;
}
textarea.input { padding: 10px 12px; min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.input.ok { border: 2px solid var(--green); }
.input.bad { border: 2px solid var(--red); background: #FDF0F0; }
.input.filled { border-color: var(--teal); background: var(--teal-soft); }
.input.phone { font-family: var(--serif); font-size: 21px; letter-spacing: 1px; direction: ltr; text-align: right; }
.hint { font-size: 14px; }
.hint.ok { color: var(--green); } .hint.bad { color: var(--red); font-weight: 700; }
.search { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 4px; background: var(--field); }
.search input { flex: 1; border: none; outline: none; background: transparent; font-size: 15px; min-height: 40px; }

/* الأختام */
.stamp { display: inline-block; padding: 2px 10px; border-radius: 4px; font-family: var(--serif); font-size: 15px; font-weight: 700;
  border: 3px double currentColor; transform: rotate(-5deg); white-space: nowrap; }
.stamp.fill { color: var(--card) !important; border-color: var(--red); background: var(--red); }
.stamp.dash { border-style: dashed; border-width: 2px; }
.stamp-in { animation: stampin .45s cubic-bezier(.2,1.7,.4,1) both; }
@keyframes stampin { 0% { transform: scale(2.6) rotate(-20deg); opacity: 0; } 100% { transform: scale(1) rotate(-8deg); opacity: 1; } }
.seal { width: 56px; height: 56px; border-radius: 50%; background: var(--clay); display: inline-flex; align-items: center; justify-content: center;
  color: var(--card); font-family: var(--ruqaa); font-size: 24px; box-shadow: inset 0 0 0 4px var(--clay), inset 0 0 0 6px var(--peach), 0 3px 0 var(--clay-dark); }
.seal.big { width: 112px; height: 112px; font-size: 40px; animation: sway 6s ease-in-out infinite; }
.seal.teal { background: var(--teal); box-shadow: inset 0 0 0 4px var(--teal), inset 0 0 0 6px #A8C4BE, 0 3px 0 var(--teal-dark); }
@keyframes sway { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }

/* القطع والصور */
.thumb { width: 56px; height: 66px; border-radius: 3px; object-fit: cover; flex-shrink: 0; background: #E9B79F;
  border: 3px solid var(--field); box-shadow: 0 0 0 1px var(--line); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--clay-dark); }
.bigimg { width: 100%; height: 190px; object-fit: cover; background: #E9B79F; display: flex; align-items: center; justify-content: center; color: var(--clay-dark); }
.piece { border-radius: 4px; overflow: hidden; background: var(--card); border: 3px solid var(--line); transition: border-color .3s; }
.piece.done { border-color: var(--green); }
.piece .rel { position: relative; }
.piece .over { position: absolute; top: 50%; left: 50%; margin: -26px 0 0 -70px; width: 140px; text-align: center; padding: 6px 0;
  border: 4px double var(--green); border-radius: 6px; background: rgba(251,245,236,.8); color: var(--green); font-family: var(--serif); font-size: 28px; font-weight: 700; }
.code { font-family: var(--serif); font-size: 28px; font-weight: 700; line-height: 1.2; }
.swatch { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 2px var(--card), 0 0 0 3px var(--line-strong); flex-shrink: 0; }

/* صفوف النسخ */
.copyrow { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 4px; border: 1.5px solid var(--line); background: var(--card); transition: background-color .3s, border-color .3s; }
.copyrow.done { border-color: var(--green); background: var(--green-soft); }
.copyrow .val { font-family: var(--serif); font-size: 19px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copyrow .n { font-size: 12px; color: var(--ink-2); }
.ribbon { height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.ribbon > div { height: 100%; background: var(--gold); transition: width .45s cubic-bezier(.3,1.4,.5,1); }
.ribbon.full > div { background: var(--green); }

/* المخزن */
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.size { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 4px; border: 1.5px solid var(--line-soft); background: var(--field); }
.size.low { border-color: #C9A35B; background: var(--yellow-soft); }
.size.out { border: 1.5px dashed var(--red); background: var(--red-soft); }
.size .q { font-family: var(--serif); font-size: 24px; font-weight: 700; line-height: 1.1; }
.size.low .q { color: var(--yellow); } .size.out .q { color: var(--red); }
.size button { width: 30px; height: 30px; border-radius: 4px; border: 1.5px solid var(--line-strong); background: var(--field); font-size: 18px; cursor: pointer; }
.size button.plus { background: var(--teal); color: var(--card); border: none; }

/* الدردشة */
.msgs { display: flex; flex-direction: column; gap: 10px; padding-bottom: 150px; }
.msg { max-width: 85%; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 4px; background: var(--card); border: 1px solid var(--line); align-self: flex-end; }
.msg.me { align-self: flex-start; background: #F6E1D6; border-color: var(--peach); }
.msg .who { font-family: var(--serif); font-size: 15px; font-weight: 700; color: var(--teal); }
.msg.me .who { color: var(--clay); }
.msg .time { font-size: 12px; color: #8A7565; align-self: flex-end; }
.tagcard { margin: 4px 0; padding: 8px 10px; border: 1.5px dashed var(--gold); border-radius: 4px; background: var(--field); display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: pointer; }
.composer { position: fixed; left: 0; right: 0; bottom: var(--nav-h); background: var(--card); border-top: 3px double var(--gold); padding: 8px 14px 10px; }
.composer .inner { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.mention { color: var(--clay); font-weight: 700; }

/* القائمة السفلية */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); background: var(--ink); display: flex; justify-content: space-around; align-items: center; z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #CBB9A6; text-decoration: none; font-size: 12px; min-width: 56px; position: relative; }
.nav a.on { color: var(--peach); font-weight: 700; }
.nav svg { width: 22px; height: 22px; }
.nav .badge { position: absolute; top: -4px; left: 8px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--clay); color: var(--card); font-size: 11px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* شاشة المدير على الحاسبة */
@media (min-width: 900px) {
  .shell.owner { flex-direction: row; }
  .shell.owner .nav { position: sticky; top: 0; height: 100vh; width: 210px; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 4px; padding: 20px 12px; }
  .shell.owner .nav a { flex-direction: row; gap: 10px; font-size: 16px; padding: 10px 12px; border-radius: 4px; }
  .shell.owner .nav a.on { background: rgba(233,183,159,.12); }
  .shell.owner .nav .brand { display: flex; }
  .shell.owner .screen { padding-bottom: 40px; }
  .shell.owner .composer { right: 210px; bottom: 0; }
  .shell.owner .msgs { padding-bottom: 130px; }
}
.nav .brand { display: none; align-items: center; gap: 10px; color: var(--peach); font-family: var(--ruqaa); font-size: 30px; padding: 0 8px 16px; border-bottom: 1px solid #4A3A30; margin-bottom: 8px; }

/* نوافذ */
.overlay { position: fixed; inset: 0; background: rgba(46,31,23,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; animation: fade .25s ease both; }
.overlay.bottom { align-items: flex-end; padding: 0; }
.dialog { background: var(--card); border-radius: 4px; padding: 26px 22px; width: 100%; max-width: 440px; box-shadow: inset 0 0 0 6px var(--card), inset 0 0 0 7px var(--gold);
  display: flex; flex-direction: column; gap: 12px; max-height: 90vh; overflow-y: auto; }
.dialog.center { align-items: center; text-align: center; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--card); border-top: 3px double var(--gold); padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; max-height: 85vh; overflow-y: auto; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade { animation: fade .3s ease both; }

#toast { position: fixed; left: 14px; right: 14px; bottom: calc(var(--nav-h) + 16px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: var(--ink); color: var(--card); border-radius: 4px; padding: 11px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 15px; animation: fade .25s ease both; }
.toast.bad { background: var(--red); }
.toast button { background: transparent; border: 1.5px solid var(--peach); color: var(--peach); border-radius: 4px; min-height: 36px; padding: 0 12px; font-family: var(--serif); font-size: 16px; font-weight: 700; cursor: pointer; }

/* الدخول */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.login .brandname { font-family: var(--ruqaa); font-size: 64px; color: var(--clay); line-height: 1; }
.login form { width: 100%; max-width: 360px; }

/* لوحة */
.tile { background: var(--card); border: 1px solid var(--line); box-shadow: inset 0 0 0 5px var(--card), inset 0 0 0 6px var(--line-soft); border-radius: 4px; padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.tile .v { font-family: var(--serif); font-size: 36px; font-weight: 700; line-height: 1.2; }
table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
table.t th { text-align: right; font-weight: 500; color: var(--ink-2); font-size: 13px; padding: 6px 4px; border-bottom: 1.5px dashed var(--line); }
table.t td { padding: 8px 4px; border-bottom: 1px solid var(--line-soft); }
.scrollx { overflow-x: auto; }
.empty { padding: 30px 10px; text-align: center; font-family: var(--serif); font-size: 20px; color: var(--ink-2); }
.demo-bar { background: var(--gold); color: var(--card); text-align: center; font-size: 13px; padding: 4px 8px; }
