/* ==========================================================================
   نظام الماجد كلين — نظام التصميم
   Desktop 1440×900 · Mobile 390×844 · RTL
   ========================================================================== */

:root{
  /* ألوان الهوية */
  --navy-900:#0B1526;
  --navy-800:#101F38;
  --navy-700:#16294A;
  --navy-600:#1D3663;

  --brand:#2563EB;
  --brand-600:#1D4ED8;
  --brand-700:#1A43BD;
  --brand-50:#EEF3FF;
  --brand-100:#DCE6FF;

  --teal:#0D9488;
  --teal-50:#E6F6F4;
  --green:#059669;
  --green-50:#E7F6EF;
  --amber:#B45309;
  --amber-50:#FDF3E3;
  --rose:#DC2626;
  --rose-50:#FDECEC;

  /* محايدات */
  --canvas:#F4F6FB;
  --surface:#FFFFFF;
  --surface-2:#FAFBFD;
  --line:#E5E9F2;
  --line-strong:#D3DAE8;
  --ink:#0F172A;
  --ink-2:#334155;
  --muted:#6B7A90;
  --muted-2:#94A3B8;

  /* شكل */
  --r-xs:8px;
  --r-sm:10px;
  --r:14px;
  --r-lg:20px;
  --r-pill:999px;

  --sh-1:0 1px 2px rgba(15,23,42,.05);
  --sh-2:0 2px 4px rgba(15,23,42,.04), 0 8px 20px rgba(15,23,42,.06);
  --sh-3:0 24px 60px rgba(11,21,38,.24);

  --side-w:264px;
  --topbar-h:68px;

  --font:'IBM Plex Sans Arabic','Almarai',system-ui,-apple-system,'Segoe UI',sans-serif;
}

*{box-sizing:border-box; margin:0; padding:0;}
html{-webkit-text-size-adjust:100%;}
body{
  font-family:var(--font);
  background:var(--canvas);
  color:var(--ink);
  min-height:100vh;
  font-size:14px;
  line-height:1.6;
  -webkit-font-smoothing:antialiased;
}
a{color:inherit;}
button,input,select,textarea{font-family:inherit; font-size:inherit; color:inherit;}
::selection{background:var(--brand-100);}

/* ==========================================================================
   1. صفحة الدخول
   ========================================================================== */

.auth{
  min-height:100vh;
  display:grid;
  grid-template-columns:1fr 1fr;
  background:var(--surface);
}

/* اللوحة الزرقاء */
.auth-brand{
  position:relative;
  background:
    radial-gradient(1000px 600px at 100% 0%, rgba(37,99,235,.55), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(13,148,136,.30), transparent 60%),
    linear-gradient(150deg, var(--navy-800), var(--navy-900));
  color:#fff;
  padding:48px;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  overflow:hidden;
}
.auth-brand::after{
  content:"";
  position:absolute;
  inset:0;
  background-image:
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size:56px 56px;
  mask-image:radial-gradient(circle at 70% 30%, #000, transparent 75%);
  -webkit-mask-image:radial-gradient(circle at 70% 30%, #000, transparent 75%);
  pointer-events:none;
}
.auth-brand > *{position:relative; z-index:1;}

.auth-brand-top{display:flex; align-items:center; gap:12px;}
.auth-brand-top img{height:40px; width:auto;}
.auth-brand h1{
  font-size:40px;
  line-height:1.35;
  font-weight:600;
  letter-spacing:-.5px;
  max-width:11ch;
}
.auth-brand h1 em{
  font-style:normal;
  background:linear-gradient(90deg,#7FB0FF,#5EEAD4);
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
}
.auth-brand p{
  margin-top:16px;
  font-size:15px;
  color:rgba(255,255,255,.68);
  max-width:38ch;
  line-height:1.9;
}
.auth-points{margin-top:28px; display:flex; flex-direction:column; gap:12px;}
.auth-point{display:flex; align-items:center; gap:10px; font-size:13.5px; color:rgba(255,255,255,.8);}
.auth-point svg{width:18px; height:18px; flex:none; color:#5EEAD4;}
.auth-foot{font-size:12px; color:rgba(255,255,255,.42);}

/* لوحة الفورم */
.auth-form-wrap{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:40px;
}
.auth-form{width:100%; max-width:368px;}
.auth-kicker{
  font-size:11px; font-weight:700; letter-spacing:2px;
  color:var(--brand); text-transform:uppercase; margin-bottom:14px;
}
.auth-form h2{font-size:26px; font-weight:700; letter-spacing:-.4px;}
.auth-form .sub{color:var(--muted); font-size:13.5px; margin-top:6px; margin-bottom:26px;}

.field{display:block; margin-bottom:16px;}
.field > span{
  display:block; font-size:12.5px; font-weight:600;
  color:var(--ink-2); margin-bottom:7px;
}
.field input, .field select{
  width:100%;
  padding:12px 14px;
  background:var(--surface-2);
  border:1px solid var(--line-strong);
  border-radius:var(--r-sm);
  transition:border-color .15s, box-shadow .15s, background .15s;
}
.field input::placeholder{color:var(--muted-2);}
.field input:focus, .field select:focus{
  outline:none;
  background:var(--surface);
  border-color:var(--brand);
  box-shadow:0 0 0 3px var(--brand-50);
}

.auth-row{
  display:flex; align-items:center; justify-content:space-between;
  gap:12px; margin:4px 0 22px;
}
.check{display:inline-flex; align-items:center; gap:8px; font-size:13px; color:var(--ink-2); cursor:pointer;}
.check input{width:16px; height:16px; accent-color:var(--brand); cursor:pointer;}
.link{color:var(--brand); font-size:13px; text-decoration:none; font-weight:600;}
.link:hover{text-decoration:underline;}

.btn-block{
  width:100%;
  padding:13px;
  background:var(--brand);
  color:#fff;
  border:none;
  border-radius:var(--r-sm);
  font-weight:600;
  font-size:14.5px;
  cursor:pointer;
  transition:background .15s, transform .05s;
}
.btn-block:hover{background:var(--brand-600);}
.btn-block:active{transform:translateY(1px);}

.auth-note{margin-top:22px; text-align:center; font-size:12.5px; color:var(--muted);}

@media (max-width:900px){
  .auth{grid-template-columns:1fr;}
  .auth-brand{
    padding:26px 22px;
    min-height:auto;
  }
  .auth-brand h1{font-size:26px; max-width:none;}
  .auth-brand p, .auth-points{display:none;}
  .auth-foot{display:none;}
  .auth-brand-top{margin-bottom:20px;}
  .auth-form-wrap{padding:32px 22px 48px;}
}

/* ==========================================================================
   2. هيكل التطبيق
   ========================================================================== */

.shell{display:flex; min-height:100vh;}

/* --- الشريط الجانبي --- */
.side{
  width:var(--side-w);
  flex:none;
  background:linear-gradient(180deg, var(--navy-800), var(--navy-900));
  color:#fff;
  padding:20px 16px;
  display:flex;
  flex-direction:column;
  gap:22px;
  position:sticky;
  top:0;
  height:100vh;
}
.side-logo{display:flex; align-items:center; gap:11px; padding:4px 6px 0;}
.side-logo img{height:32px; width:auto;}
.side-logo .t{font-size:14px; font-weight:600; letter-spacing:-.2px;}
.side-logo .s{font-size:10.5px; color:rgba(255,255,255,.45); letter-spacing:1.5px; text-transform:uppercase;}

.side-branch{
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.10);
  border-radius:var(--r-sm);
  padding:11px 12px;
}
.side-branch .lbl{
  font-size:10.5px; color:rgba(255,255,255,.5);
  font-weight:600; letter-spacing:.6px; margin-bottom:6px; display:block;
}
.side-branch select{
  width:100%;
  background:transparent;
  border:none;
  color:#fff;
  font-size:13.5px;
  font-weight:600;
  cursor:pointer;
  padding:0;
}
.side-branch select option{background:var(--navy-800); color:#fff;}
.side-branch .fixed{font-size:13.5px; font-weight:600;}

.side-nav{display:flex; flex-direction:column; gap:3px; flex:1;}
.side-nav .grp{
  font-size:10px; font-weight:700; letter-spacing:1.4px;
  color:rgba(255,255,255,.32); padding:14px 12px 6px; text-transform:uppercase;
}
.nav-item{
  display:flex; align-items:center; gap:11px;
  padding:11px 12px;
  border-radius:var(--r-sm);
  color:rgba(255,255,255,.72);
  text-decoration:none;
  font-size:13.5px;
  font-weight:500;
  transition:background .15s, color .15s;
}
.nav-item svg{width:18px; height:18px; flex:none; opacity:.85;}
.nav-item:hover{background:rgba(255,255,255,.07); color:#fff;}
.nav-item.active{
  background:var(--brand);
  color:#fff;
  font-weight:600;
  box-shadow:0 6px 16px rgba(37,99,235,.35);
}
.nav-item.active svg{opacity:1;}

.side-user{
  border-top:1px solid rgba(255,255,255,.09);
  padding-top:14px;
  display:flex; align-items:center; gap:11px;
}
.avatar{
  width:36px; height:36px; flex:none;
  border-radius:11px;
  background:linear-gradient(135deg,var(--brand),var(--teal));
  display:grid; place-items:center;
  font-weight:700; font-size:14px; color:#fff;
  text-transform:uppercase;
}
.side-user .meta{flex:1; min-width:0;}
.side-user .em{
  font-size:12.5px; font-weight:600;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.side-user .rl{font-size:11px; color:rgba(255,255,255,.45);}
.side-user .out{
  color:rgba(255,255,255,.55);
  display:grid; place-items:center;
  width:32px; height:32px; border-radius:9px;
  text-decoration:none; flex:none;
  transition:background .15s, color .15s;
}
.side-user .out:hover{background:rgba(220,38,38,.18); color:#FCA5A5;}
.side-user .out svg{width:17px; height:17px;}

/* --- المنطقة الرئيسية --- */
.content{flex:1; min-width:0; display:flex; flex-direction:column;}

.topbar{
  height:var(--topbar-h);
  background:rgba(255,255,255,.85);
  backdrop-filter:blur(8px);
  border-bottom:1px solid var(--line);
  display:flex; align-items:center; justify-content:space-between;
  gap:16px;
  padding:0 28px;
  position:sticky; top:0; z-index:20;
}
.topbar h1{font-size:18px; font-weight:700; letter-spacing:-.3px;}
.topbar .crumb{font-size:12px; color:var(--muted); margin-top:1px;}
.topbar-actions{display:flex; align-items:center; gap:10px;}
.burger{
  display:none;
  width:40px; height:40px;
  border:1px solid var(--line-strong);
  background:var(--surface);
  border-radius:var(--r-sm);
  place-items:center; cursor:pointer;
}
.burger svg{width:20px; height:20px;}

.page{padding:24px 28px 40px; flex:1;}
.page-inner{max-width:1180px; margin:0 auto;}

/* ==========================================================================
   3. مكونات
   ========================================================================== */

.card{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r);
  box-shadow:var(--sh-1);
}
.card-pad{padding:22px;}
.card-head{
  display:flex; align-items:center; justify-content:space-between;
  gap:14px; flex-wrap:wrap;
  padding:18px 22px;
  border-bottom:1px solid var(--line);
}
.card-head h2{font-size:15.5px; font-weight:700;}
.card-head .sub{font-size:12px; color:var(--muted); font-weight:500;}

.alert{
  padding:12px 16px; border-radius:var(--r-sm);
  font-size:13.5px; font-weight:500; margin-bottom:18px;
  display:flex; align-items:center; gap:10px;
  border:1px solid transparent;
}
.alert.ok{background:var(--green-50); color:var(--green); border-color:#BFE7D4;}
.alert.err{background:var(--rose-50); color:var(--rose); border-color:#F6C9C9;}

/* أزرار */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  padding:10px 18px;
  background:var(--brand); color:#fff;
  border:1px solid var(--brand);
  border-radius:var(--r-sm);
  font-weight:600; font-size:13.5px;
  cursor:pointer; text-decoration:none;
  white-space:nowrap;
  transition:background .15s, border-color .15s, color .15s;
}
.btn svg{width:16px; height:16px;}
.btn:hover{background:var(--brand-600); border-color:var(--brand-600);}
.btn.ghost{background:var(--surface); color:var(--ink-2); border-color:var(--line-strong);}
.btn.ghost:hover{background:var(--surface-2); border-color:var(--muted-2); color:var(--ink);}
.btn.soft{background:var(--brand-50); color:var(--brand-600); border-color:transparent;}
.btn.soft:hover{background:var(--brand-100);}
.btn.danger{background:var(--rose); border-color:var(--rose);}
.btn.danger:hover{background:#B91C1C; border-color:#B91C1C;}
.btn.sm{padding:7px 13px; font-size:12.5px;}
.btn-row{display:flex; gap:10px; flex-wrap:wrap;}

.icon-btn{
  background:none; border:none; cursor:pointer;
  color:var(--muted-2);
  width:30px; height:30px; border-radius:8px;
  display:inline-grid; place-items:center;
  transition:background .15s, color .15s;
}
.icon-btn svg{width:16px; height:16px;}
.icon-btn:hover{background:var(--rose-50); color:var(--rose);}
.icon-btn.edit:hover{background:var(--brand-50); color:var(--brand);}

/* بطاقات الأرقام */
.stats{display:grid; grid-template-columns:repeat(auto-fit,minmax(210px,1fr)); gap:16px;}
.stat{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r);
  padding:18px 20px;
  box-shadow:var(--sh-1);
  position:relative;
  overflow:hidden;
}
.stat::before{
  content:""; position:absolute; inset-inline-start:0; top:0; bottom:0;
  width:3px; background:var(--brand);
}
.stat.pos::before{background:var(--green);}
.stat.neg::before{background:var(--rose);}
.stat.warn::before{background:var(--amber);}
.stat .lbl{
  font-size:11.5px; font-weight:600; color:var(--muted);
  display:flex; align-items:center; gap:7px;
}
.stat .lbl svg{width:15px; height:15px;}
.stat .val{font-size:27px; font-weight:700; letter-spacing:-.8px; margin-top:6px; line-height:1.2;}
.stat .val .cur{font-size:14px; font-weight:600; color:var(--muted); letter-spacing:0;}
.stat.pos .val{color:var(--green);}
.stat.neg .val{color:var(--rose);}
.stat .foot{font-size:11.5px; color:var(--muted); margin-top:6px;}
.stat .foot.warn{color:var(--amber); font-weight:600;}

/* تخطيط قائمة + تفاصيل */
.split{display:grid; grid-template-columns:280px 1fr; gap:20px; align-items:start;}

.panel{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r);
  box-shadow:var(--sh-1);
  overflow:hidden;
}
.panel-head{
  padding:15px 16px 12px;
  border-bottom:1px solid var(--line);
  display:flex; align-items:center; justify-content:space-between;
}
.panel-head h2{font-size:11.5px; font-weight:700; color:var(--muted); letter-spacing:1px; text-transform:uppercase;}
.panel-head .count{
  font-size:11px; font-weight:700; color:var(--brand);
  background:var(--brand-50); padding:2px 9px; border-radius:var(--r-pill);
}
.panel-list{padding:8px; display:flex; flex-direction:column; gap:2px; max-height:min(58vh,520px); overflow-y:auto;}
.panel-foot{padding:10px; border-top:1px solid var(--line); background:var(--surface-2);}

.list-item{
  display:flex; align-items:center; gap:11px;
  padding:10px 11px;
  border-radius:var(--r-sm);
  text-decoration:none;
  color:inherit;
  transition:background .15s;
}
.list-item:hover{background:var(--surface-2);}
.list-item.active{background:var(--brand-50);}
.list-item .ini{
  width:34px; height:34px; flex:none;
  border-radius:10px;
  background:var(--surface-2);
  border:1px solid var(--line);
  display:grid; place-items:center;
  font-size:13px; font-weight:700; color:var(--muted);
}
.list-item.active .ini{background:var(--brand); border-color:var(--brand); color:#fff;}
.list-item .txt{min-width:0; flex:1;}
.item-name{display:block; font-weight:600; font-size:13.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.item-sub{display:block; font-size:11.5px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.list-item.active .item-name{color:var(--brand-700);}

.add-link{
  display:flex; align-items:center; justify-content:center; gap:7px;
  width:100%; padding:10px;
  background:var(--surface);
  border:1px dashed var(--line-strong);
  border-radius:var(--r-sm);
  font-size:13px; font-weight:600; color:var(--brand);
  cursor:pointer; text-decoration:none;
  transition:background .15s, border-color .15s;
}
.add-link svg{width:15px; height:15px;}
.add-link:hover{background:var(--brand-50); border-color:var(--brand);}

/* رأس السجل */
.record-head{
  display:flex; align-items:flex-start; justify-content:space-between;
  gap:20px; flex-wrap:wrap;
  padding:20px 22px;
  border-bottom:1px solid var(--line);
}
.record-title{display:flex; align-items:center; gap:14px;}
.record-title .ini{
  width:48px; height:48px; flex:none;
  border-radius:14px;
  background:linear-gradient(135deg,var(--navy-700),var(--brand));
  color:#fff;
  display:grid; place-items:center;
  font-size:18px; font-weight:700;
}
.record-title h2{font-size:19px; font-weight:700; letter-spacing:-.3px;}
.record-title .who{font-size:12.5px; color:var(--muted);}

.meta-row{display:flex; gap:10px; flex-wrap:wrap;}
.meta-field{
  background:var(--surface-2);
  border:1px solid var(--line);
  border-radius:var(--r-sm);
  padding:8px 13px;
  min-width:132px;
}
.meta-label{display:block; font-size:10.5px; font-weight:600; color:var(--muted); letter-spacing:.3px;}
.meta-value{display:block; font-size:14px; font-weight:700; margin-top:1px;}
.meta-value form{display:inline-flex; align-items:center; gap:4px;}
.meta-value input{
  width:74px; padding:1px 4px;
  border:none; border-bottom:1.5px dashed var(--brand);
  background:none; color:var(--brand-700);
  font-weight:700; font-size:14px;
}
.meta-value input:focus{outline:none; border-bottom-style:solid;}
.meta-value input[type=number]{width:56px;}

/* الفلاتر */
.filters{display:flex; gap:10px; flex-wrap:wrap; align-items:center;}
.filters select, .filters input[type=text], .filters input[type=date], .filters input[type=month]{
  padding:9px 13px;
  background:var(--surface);
  border:1px solid var(--line-strong);
  border-radius:var(--r-sm);
  font-size:13px;
  min-width:130px;
}
.filters select:focus, .filters input:focus{
  outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-50);
}
.search{position:relative; flex:1; min-width:180px; max-width:280px;}
.search svg{
  position:absolute; inset-inline-start:12px; top:50%; transform:translateY(-50%);
  width:15px; height:15px; color:var(--muted-2); pointer-events:none;
}
.search input{width:100%; padding-inline-start:34px !important;}

/* الجداول */
.table-wrap{overflow-x:auto;}
table{width:100%; border-collapse:collapse; font-size:13.5px;}
thead th{
  text-align:right;
  font-size:11px; font-weight:700; color:var(--muted);
  letter-spacing:.5px; text-transform:uppercase;
  padding:12px 16px;
  background:var(--surface-2);
  border-bottom:1px solid var(--line);
  white-space:nowrap;
}
tbody td{
  padding:13px 16px;
  border-bottom:1px solid var(--line);
  vertical-align:middle;
}
tbody tr:last-child td{border-bottom:none;}
tbody tr{transition:background .12s;}
tbody tr:hover{background:var(--surface-2);}
td.num{font-weight:700; white-space:nowrap; font-variant-numeric:tabular-nums;}
td.actions{width:1%; white-space:nowrap; text-align:left;}

.empty{
  padding:44px 20px;
  text-align:center;
  color:var(--muted);
}
.empty svg{width:38px; height:38px; color:var(--line-strong); margin-bottom:10px;}
.empty .t{font-size:14px; font-weight:600; color:var(--ink-2);}
.empty .s{font-size:12.5px; margin-top:3px;}
.hint{font-size:12.5px; color:var(--muted); line-height:1.8;}

/* شارات */
.tag{
  display:inline-flex; align-items:center; gap:5px;
  font-size:11.5px; font-weight:600;
  padding:4px 11px;
  border-radius:var(--r-pill);
  white-space:nowrap;
}
.tag::before{content:""; width:5px; height:5px; border-radius:50%; background:currentColor;}
.tag.green{background:var(--green-50); color:var(--green);}
.tag.rose{background:var(--rose-50); color:var(--rose);}
.tag.amber{background:var(--amber-50); color:var(--amber);}
.tag.blue{background:var(--brand-50); color:var(--brand-600);}
.tag.grey{background:#F1F4F9; color:var(--muted);}
.amt-pos{color:var(--green); font-weight:700;}
.amt-neg{color:var(--rose); font-weight:700;}
.muted{color:var(--muted);}
.day-name{font-size:12px; color:var(--muted);}

/* السلف */
.loan{
  display:flex; align-items:center; justify-content:space-between;
  gap:18px; flex-wrap:wrap;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r);
  padding:16px 18px;
  margin-bottom:10px;
}
.loan-main{display:flex; align-items:center; gap:20px; flex-wrap:wrap; flex:1; min-width:220px;}
.loan-amt{font-size:17px; font-weight:700; letter-spacing:-.4px;}
.loan-amt .cur{font-size:12px; font-weight:600; color:var(--muted);}
.loan-note{font-size:12px; color:var(--muted);}
.progress{flex:1; min-width:170px; max-width:320px;}
.bar{height:7px; border-radius:var(--r-pill); background:#EDF1F7; overflow:hidden;}
.bar-fill{height:100%; border-radius:var(--r-pill); background:linear-gradient(90deg,var(--brand),var(--teal)); transition:width .3s;}
.progress .sub{font-size:11.5px; color:var(--muted); margin-top:6px;}
.loan-actions{display:flex; gap:8px; flex-wrap:wrap;}

/* الجرد */
.summary{
  background:var(--surface-2);
  border:1px solid var(--line);
  border-radius:var(--r-sm);
  padding:6px 16px;
  margin-top:14px;
}
.summary-row{
  display:flex; justify-content:space-between; align-items:center; gap:14px;
  padding:11px 0;
  border-bottom:1px dashed var(--line);
  font-size:13.5px;
}
.summary-row:last-child{border-bottom:none;}
.summary-row .amt{font-weight:700; font-variant-numeric:tabular-nums;}
.summary-row.total{
  border-top:1.5px solid var(--line-strong);
  border-bottom:none;
  margin-top:4px;
  font-weight:700;
  font-size:15px;
}

/* شريط التاريخ */
.daybar{
  display:flex; align-items:center; justify-content:space-between;
  gap:14px; flex-wrap:wrap;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r);
  padding:14px 18px;
  box-shadow:var(--sh-1);
  margin-bottom:20px;
}
.daybar-left{display:flex; align-items:center; gap:12px; flex-wrap:wrap;}
.daypill{
  font-size:12.5px; font-weight:700;
  color:var(--brand-600); background:var(--brand-50);
  padding:6px 14px; border-radius:var(--r-pill);
}

/* النوافذ المنبثقة */
dialog.modal{
  border:none;
  border-radius:var(--r-lg);
  padding:0;
  width:min(500px, calc(100vw - 28px));
  max-height:min(88vh,700px);
  box-shadow:var(--sh-3);
  color:var(--ink);
  overflow:visible;
}
dialog.modal::backdrop{background:rgba(11,21,38,.5); backdrop-filter:blur(3px);}
dialog.modal > form{padding:26px; max-height:inherit; overflow-y:auto;}
dialog.modal h3{font-size:17px; font-weight:700; margin-bottom:4px; letter-spacing:-.3px;}
dialog.modal .modal-sub{font-size:12.5px; color:var(--muted); margin-bottom:20px;}
.grid2{display:grid; grid-template-columns:1fr 1fr; gap:14px;}
.grid2 label{display:flex; flex-direction:column; gap:7px; font-size:12.5px; font-weight:600; color:var(--ink-2);}
.grid2 label.full{grid-column:1/-1;}
.grid2 input, .grid2 select{
  padding:11px 13px;
  background:var(--surface-2);
  border:1px solid var(--line-strong);
  border-radius:var(--r-sm);
  font-weight:500;
  transition:border-color .15s, box-shadow .15s, background .15s;
}
.grid2 input:focus, .grid2 select:focus{
  outline:none; background:var(--surface);
  border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-50);
}
.modal-actions{display:flex; justify-content:flex-end; gap:10px; margin-top:22px;}
.modal-note{
  margin-top:14px; padding:11px 14px;
  background:var(--brand-50); border-radius:var(--r-sm);
  font-size:12.5px; color:var(--brand-700); line-height:1.7;
}

/* درج الموبايل */
.drawer-backdrop{
  display:none;
  position:fixed; inset:0; z-index:60;
  background:rgba(11,21,38,.5);
  backdrop-filter:blur(2px);
}
.drawer-backdrop.open{display:block;}

/* ==========================================================================
   4. الموبايل — 390×844
   ========================================================================== */

@media (max-width:1024px){
  .split{grid-template-columns:240px 1fr; gap:16px;}
}

@media (max-width:860px){
  .side{
    position:fixed; z-index:70;
    inset-inline-end:0; top:0;
    height:100dvh;
    width:min(282px,86vw);
    transform:translateX(100%);
    transition:transform .25s ease;
    box-shadow:var(--sh-3);
  }
  [dir=rtl] .side{transform:translateX(-100%);}
  .side.open{transform:translateX(0) !important;}
  .burger{display:grid;}

  .topbar{padding:0 16px; height:60px;}
  .topbar h1{font-size:16px;}
  .page{padding:16px 16px 90px;}

  .split{grid-template-columns:1fr;}
  .panel-list{max-height:none;}

  .record-head{padding:16px; gap:14px;}
  .record-title .ini{width:42px; height:42px; font-size:16px;}
  .record-title h2{font-size:17px;}
  .meta-row{width:100%;}
  .meta-field{flex:1; min-width:calc(50% - 5px);}

  .stats{grid-template-columns:1fr 1fr; gap:12px;}
  .stat{padding:14px 16px;}
  .stat .val{font-size:22px;}

  .card-head{padding:15px 16px;}
  .card-pad{padding:16px;}

  /* الجداول تبقى كروت */
  .table-cards thead{display:none;}
  .table-cards tbody tr{
    display:grid;
    grid-template-columns:1fr auto;
    gap:4px 10px;
    padding:13px 16px;
    border-bottom:1px solid var(--line);
  }
  .table-cards tbody tr:hover{background:transparent;}
  .table-cards tbody td{
    display:flex; align-items:center; justify-content:space-between; gap:12px;
    padding:2px 0; border:none;
  }
  .table-cards tbody td::before{
    content:attr(data-label);
    font-size:11.5px; font-weight:600; color:var(--muted);
    flex:none;
  }
  .table-cards tbody td[data-label=""]::before{display:none;}
  .table-cards tbody td.head-cell{
    grid-column:1/-1;
    font-weight:700; font-size:14px;
    padding-bottom:4px;
  }
  .table-cards tbody td.head-cell::before{display:none;}
  .table-cards tbody td.actions{
    position:absolute;
    inset-inline-end:12px;
    margin-top:2px;
  }
  .table-cards tbody tr{position:relative;}
  .table-cards tbody td.actions::before{display:none;}
  .table-cards .empty-row td{display:block; padding:0;}

  .loan{padding:14px; gap:12px;}
  .progress{max-width:none;}
  .loan-actions{width:100%;}
  .loan-actions form{flex:1;}
  .loan-actions .btn{width:100%;}

  .filters{width:100%;}
  .filters select, .filters input{flex:1; min-width:0;}
  .search{max-width:none; width:100%;}

  dialog.modal{
    width:100vw;
    max-width:100vw;
    max-height:92dvh;
    margin:auto 0 0;
    border-radius:var(--r-lg) var(--r-lg) 0 0;
    position:fixed; inset:auto 0 0 0;
  }
  dialog.modal > form{padding:22px 18px calc(22px + env(safe-area-inset-bottom));}
  .grid2{grid-template-columns:1fr;}
  .modal-actions{flex-direction:column-reverse;}
  .modal-actions .btn{width:100%;}

  .daybar{padding:12px 14px;}
  .daybar .btn{width:100%;}

  /* شريط تنقل سفلي */
  .tabbar{
    display:grid;
    position:fixed; inset-inline:0; bottom:0; z-index:50;
    background:rgba(255,255,255,.94);
    backdrop-filter:blur(10px);
    border-top:1px solid var(--line);
    padding:8px 6px calc(8px + env(safe-area-inset-bottom));
  }
  .tabbar a{
    display:flex; flex-direction:column; align-items:center; gap:4px;
    text-decoration:none;
    font-size:10.5px; font-weight:600;
    color:var(--muted);
    padding:4px 2px;
    border-radius:var(--r-xs);
  }
  .tabbar a svg{width:20px; height:20px;}
  .tabbar a.active{color:var(--brand);}
}

@media (min-width:861px){
  .tabbar{display:none;}
}

@media (max-width:400px){
  .stats{grid-template-columns:1fr;}
  .meta-field{min-width:100%;}
}

/* ==========================================================================
   5. الطباعة
   ========================================================================== */

@media print{
  .side, .topbar, .tabbar, .btn, .icon-btn, .add-link, .filters{display:none !important;}
  body{background:#fff;}
  .page{padding:0;}
  .card, .panel{border:none; box-shadow:none;}
}

/* ==========================================================================
   6. تصحيحات الشعار على الخلفيات الداكنة
   ========================================================================== */

/* اللوجو ملوّن على خلفية بيضا، فبيتحط في شريحة بيضا بدل أي فلتر */
.logo-chip{
  background:#fff;
  border-radius:10px;
  padding:6px 9px;
  display:inline-flex;
  align-items:center;
  box-shadow:0 2px 10px rgba(0,0,0,.18);
  flex:none;
}
.logo-chip img{display:block; width:auto; filter:none !important;}
.auth-brand-top .logo-chip img{height:34px;}
.side-logo .logo-chip img{height:28px;}
.side-logo{gap:10px;}

/* حقول التعديل السريع في رأس السجل — صناديق صغيرة بدل الخط المتقطع */
.meta-field{min-width:auto;}
.meta-value input{
  width:auto;
  min-width:86px;
  padding:5px 9px;
  border:1px solid var(--line-strong);
  border-bottom-style:solid;
  border-radius:var(--r-xs);
  background:var(--surface);
  color:var(--ink);
  font-weight:700;
  font-size:13.5px;
}
.meta-value input:focus{
  outline:none;
  border-color:var(--brand);
  box-shadow:0 0 0 3px var(--brand-50);
}
.meta-value input[type=number]{min-width:72px; width:auto;}
.meta-value form{gap:6px;}
.meta-value input{flex:none; width:98px; min-width:0;}
.meta-value input[type=number]{width:98px; min-width:0;}
.meta-value input[name="due_day"]{width:66px;}
.meta-field{width:auto;}

/* الشريط العلوي على الموبايل: أزرار أصغر */
@media (max-width:860px){
  .topbar-actions .btn{padding:8px 12px; font-size:12.5px;}
  .tabbar a{font-size:10px;}
}

/* كروت الجدول على الموبايل: زرار الإجراء جنب العنوان بدل ما يكون مطلق */
@media (max-width:860px){
  .table-cards tbody tr{position:static; grid-template-columns:1fr auto;}
  .table-cards tbody td{grid-column:1/-1;}
  .table-cards tbody td.head-cell{grid-column:1; grid-row:1; padding-inline-end:8px;}
  .table-cards tbody td.actions{
    position:static;
    grid-column:2; grid-row:1;
    justify-content:flex-end;
    margin:0;
    width:auto;
  }
  .table-cards tbody td.actions form{display:flex;}
}

/* الموبايل: اللوحة الزرقاء تبقى ترويسة فوق الفورم */
@media (max-width:900px){
  .auth{grid-template-columns:1fr; align-content:start; min-height:100dvh;}
  .auth-brand{order:-1; border-radius:0 0 var(--r-lg) var(--r-lg);}
  .auth-brand h1{font-size:23px; line-height:1.5;}
  .auth-brand-top{margin-bottom:16px;}
  .auth-form-wrap{order:0; padding:30px 22px 40px; align-items:flex-start;}
}

/* ==========================================================================
   7. النوافذ المنبثقة — أصغر وفي نص الشاشة على الكمبيوتر والموبايل
   ========================================================================== */

dialog.modal{
  width:min(420px, calc(100vw - 32px));
  max-width:420px;
  max-height:min(84vh, 620px);
  margin:auto;
  position:fixed;
  inset:0;
  border-radius:16px;
  overflow:hidden;
}
dialog.modal > form{padding:22px; max-height:min(84vh, 620px); overflow-y:auto;}
dialog.modal h3{font-size:16px; margin-bottom:3px;}
dialog.modal .modal-sub{font-size:12px; margin-bottom:16px;}
.grid2{gap:12px;}
.grid2 label{font-size:12px; gap:6px;}
.grid2 input, .grid2 select{padding:9px 12px; font-size:13.5px;}
.modal-note{margin-top:12px; padding:10px 12px; font-size:12px;}
.modal-actions{margin-top:18px;}
.modal-actions .btn{padding:9px 16px; font-size:13px;}

@media (max-width:860px){
  dialog.modal{
    width:calc(100vw - 28px);
    max-width:420px;
    max-height:86dvh;
    margin:auto;
    inset:0;
    position:fixed;
    border-radius:16px;
  }
  dialog.modal > form{
    padding:20px 18px;
    max-height:86dvh;
  }
  .modal-actions{flex-direction:row; justify-content:stretch; gap:8px;}
  .modal-actions .btn{flex:1; width:auto;}
}

/* ==========================================================================
   8. أيقونات مضبوطة + رسالة صغيرة (توست) + نوافذ من غير شريط تمرير
   ========================================================================== */

/* أي أيقونة مالهاش مقاس محدد متتمددش */
svg{flex:none;}
.alert svg, .toast svg{width:18px; height:18px; flex:none;}

/* --- التوست: كارت صغير تحت على الشمال --- */
.toast{
  position:fixed;
  left:20px;
  bottom:20px;
  z-index:200;
  display:flex;
  align-items:center;
  gap:10px;
  max-width:min(340px, calc(100vw - 32px));
  padding:12px 14px;
  background:var(--surface);
  border:1px solid var(--line);
  border-inline-start:4px solid var(--green);
  border-radius:12px;
  box-shadow:0 10px 30px rgba(15,23,42,.16);
  font-size:13px;
  font-weight:500;
  color:var(--ink-2);
  animation:toast-in .22s ease-out;
}
.toast.err{border-inline-start-color:var(--rose);}
.toast .ic{
  width:28px; height:28px; flex:none;
  border-radius:9px;
  display:grid; place-items:center;
  background:var(--green-50); color:var(--green);
}
.toast.err .ic{background:var(--rose-50); color:var(--rose);}
.toast .tx{flex:1; line-height:1.6;}
.toast .x{
  background:none; border:none; cursor:pointer;
  color:var(--muted-2); font-size:20px; line-height:1;
  padding:0 2px; flex:none;
}
.toast .x:hover{color:var(--ink);}
.toast.out{animation:toast-out .22s ease-in forwards;}

@keyframes toast-in{
  from{opacity:0; transform:translateY(12px);}
  to{opacity:1; transform:translateY(0);}
}
@keyframes toast-out{
  to{opacity:0; transform:translateY(12px);}
}

@media (max-width:860px){
  .toast{
    left:12px;
    right:12px;
    bottom:calc(74px + env(safe-area-inset-bottom));
    max-width:none;
  }
}

/* --- النوافذ المنبثقة: على المقاس بالظبط من غير أي شريط تمرير --- */
dialog.modal{
  width:min(420px, calc(100vw - 28px));
  max-width:420px;
  height:auto;
  max-height:calc(100dvh - 32px);
  margin:auto;
  inset:0;
  position:fixed;
  border-radius:16px;
  overflow:auto;
  overscroll-behavior:contain;
  scrollbar-width:none;          /* فايرفوكس */
  -ms-overflow-style:none;       /* إيدج القديم */
}
dialog.modal::-webkit-scrollbar{width:0; height:0; display:none;}
dialog.modal > form{
  padding:22px;
  max-height:none;
  overflow:visible;
  width:100%;
}
dialog.modal *{min-width:0;}
.grid2{width:100%;}
.grid2 input, .grid2 select{width:100%; max-width:100%;}

@media (max-width:860px){
  dialog.modal{
    width:calc(100vw - 24px);
    max-width:420px;
    max-height:calc(100dvh - 24px);
    border-radius:16px;
  }
  dialog.modal > form{padding:20px 16px;}
}

/* الارتفاع يتفصّل على المحتوى — من غير كده بيتمدد لطول الشاشة */
dialog.modal{height:fit-content;}

/* ==========================================================================
   9. مفيش أي شريط تمرير ظاهر في النظام كله
   ========================================================================== */

html, body, *{
  scrollbar-width:none;        /* فايرفوكس */
  -ms-overflow-style:none;     /* إيدج القديم */
}
html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar{
  width:0 !important;
  height:0 !important;
  display:none !important;
}

/* ومع كده نمنع أي محتوى إنه يطلع بره عرض الشاشة أصلًا */
/* clip مش hidden — علشان hidden بيكسر ثبات الشريط الجانبي عند الاسكرول */
html, body{max-width:100%; overflow-x:clip;}
.page, .page-inner, .card, .panel, .split, .stats{max-width:100%; min-width:0;}
table{table-layout:auto;}
td, th{word-break:break-word;}

/* الحقول اللي جوه الجداول متفضلش أوسع من الخلية */
td form{max-width:100%; flex-wrap:wrap;}
td input, td select{max-width:100%; min-width:0;}

@media (max-width:860px){
  /* الجداول بقت كروت، فمفيش سبب لتمرير أفقي خالص */
  .table-wrap{overflow-x:visible;}
  .table-cards tbody td > form{width:100%;}
  .table-cards tbody td input,
  .table-cards tbody td select{flex:1; width:100%; min-width:0;}
  .table-cards tbody td{flex-wrap:wrap;}
  .table-cards tbody td::before{white-space:nowrap;}
}

/* ==========================================================================
   10. اللوجو من غير مربع أبيض — بيتحط مباشرة على الخلفية الغامقة
   ========================================================================== */

.logo-chip{background:none !important; padding:0 !important; box-shadow:none !important;}

.logo-mark{display:block; width:auto; height:34px; flex:none;}
.side-logo .logo-mark{height:30px;}
.auth-brand-top .logo-mark{height:38px;}

/* الشعار الملون بيفضل في الكشف المطبوع بس لأن خلفيته بيضا */
@media (max-width:860px){
  .auth-brand-top .logo-mark{height:32px;}
}
/* الشعار المؤقت مربّع، فبيتظبط بمقاس متساوي */
.side-logo .logo-mark{height:32px;}
.auth-brand-top .logo-mark{height:40px;}
/* اللوجو الأصلي عريض، فالارتفاع بيتظبط والعرض بيمشي معاه */
.side-logo .logo-mark{height:30px;}
.auth-brand-top .logo-mark{height:38px;}
@media (max-width:860px){ .auth-brand-top .logo-mark{height:32px;} }

/* ==========================================================================
   11. الشريط الجانبي ثابت مع الاسكرول + شارة الطلبات
   ========================================================================== */

@media (min-width:861px){
  /* موضع ثابت بدل sticky — مضمون مهما كان طول الصفحة */
  .side{
    position:fixed;
    top:0;
    inset-inline-start:0;
    height:100dvh;
    width:var(--side-w);
    z-index:40;
  }
  .content{margin-inline-start:var(--side-w);}
}

/* قايمة الأقسام بتتمرر لوحدها لو طولت، من غير ما تدفع كارت المستخدم لتحت */
.side-nav{overflow-y:auto; min-height:0;}

.nav-badge{
  margin-inline-start:auto;
  min-width:20px;
  height:20px;
  padding:0 6px;
  border-radius:var(--r-pill);
  background:var(--rose);
  color:#fff;
  font-size:11px;
  font-weight:700;
  display:inline-grid;
  place-items:center;
  flex:none;
}
.nav-item.active .nav-badge{background:#fff; color:var(--brand-700);}

/* الفلاتر: القوايم تاخد عرض مريح بعد شيل خانة البحث */
.filters select{min-width:170px; flex:0 1 auto;}
@media (max-width:860px){
  .filters select{min-width:0; flex:1 1 45%;}
}

/* ==========================================================================
   12. تصحيحات الموبايل: المساحة فوق، وتكبير الخانات في الآيفون
   ========================================================================== */

/* 1) مساحة أمان فوق عشان الساعة والبطارية مايركبوش على العنوان */
.topbar{
  padding-top:calc(env(safe-area-inset-top, 0px) + 8px);
  padding-bottom:8px;
  height:auto;
  min-height:var(--topbar-h);
}
.side{padding-top:calc(env(safe-area-inset-top, 0px) + 20px);}
.auth-brand{padding-top:calc(env(safe-area-inset-top, 0px) + 48px);}

@media (max-width:860px){
  .topbar{
    padding-top:calc(env(safe-area-inset-top, 0px) + 14px);
    padding-bottom:12px;
    min-height:auto;
  }
  .auth-brand{padding-top:calc(env(safe-area-inset-top, 0px) + 26px);}
  .page{padding-top:18px;}
}

/* 2) الآيفون بيكبّر الصفحة لو الخانة خطها أصغر من 16، فبنثبّتها على 16 */
@media (max-width:860px){
  input, select, textarea,
  .grid2 input, .grid2 select,
  .field input, .field select,
  .filters input, .filters select,
  .meta-value input,
  td input, td select{
    font-size:16px !important;
  }
  .grid2 label, .field > span{font-size:13px;}
}

/* 3) خانة مخفية بتمسك التركيز أول ما النافذة تفتح،
      عشان الآيفون مايفتحش القائمة المنسدلة لوحدها */
.focus-catch{
  position:absolute;
  width:1px; height:1px;
  opacity:0;
  pointer-events:none;
  outline:none;
}

/* ---------- 13) أيقونة شخص بدل حرف الاسم ---------- */
/* الدواير دي كانت فيها أول حرف من الاسم، وبقت أيقونة موحّدة */
.list-item .ini svg{width:18px; height:18px;}
.record-title .ini svg{width:24px; height:24px;}
.avatar svg{width:19px; height:19px;}
