:root{
    --bg-main:#0f1117; --surface-1:#1a1d26; --surface-2:#242936; --surface-3:#2a3040;
    --border:#2d3343; --border-soft:#242938;
    --text-primary:#f3f4f6; --text-secondary:#9ca3af; --text-muted:#6b7280;
    --text-success:#10b981; --text-danger:#ef4444; --text-warning:#f59e0b; --text-accent:#fbbf24;
    --bg-success:rgba(16,185,129,.12); --bg-danger:rgba(239,68,68,.12); --bg-warning:rgba(245,158,11,.12); --bg-accent:rgba(251,191,36,.1);
    --primary:#d97706; --primary-hover:#b45309;
    --radius:12px; --radius-sm:8px;
    --font-sans:'Cairo',sans-serif; --font-mono:'JetBrains Mono',monospace;
    --shadow:0 10px 25px -5px rgba(0,0,0,.35),0 8px 10px -6px rgba(0,0,0,.3);
    --maxw:1180px;
  }
  :root[data-theme="light"]{
    --bg-main:#f4f5f7; --surface-1:#ffffff; --surface-2:#f1f2f5; --surface-3:#e7e9ee;
    --border:#e2e4ea; --border-soft:#ececf1;
    --text-primary:#181b22; --text-secondary:#5b6472; --text-muted:#8891a0;
    --text-success:#059669; --text-danger:#dc2626; --text-warning:#b45309; --text-accent:#b45309;
    --bg-success:rgba(16,185,129,.12); --bg-danger:rgba(239,68,68,.12); --bg-warning:rgba(245,158,11,.12); --bg-accent:rgba(217,119,6,.1);
    --primary:#d97706; --primary-hover:#b45309;
    --shadow:0 10px 25px -5px rgba(20,20,30,.08),0 8px 10px -6px rgba(20,20,30,.05);
  }
  *{box-sizing:border-box;}
  html{-webkit-tap-highlight-color:transparent;}
  body{
    font-family:var(--font-sans); background:var(--bg-main); color:var(--text-primary);
    margin:0; min-height:100vh;
    background-image:radial-gradient(circle at 50% 0%, #1f2430 0%, #0f1117 70%);
  }
  :root[data-theme="light"] body{
    background-image:radial-gradient(circle at 50% 0%, #ffffff 0%, #f4f5f7 70%);
  }
  .theme-menu-wrap{position:fixed; top:16px; left:16px; z-index:5000;}
  .theme-toggle{
    position:relative;
    width:40px; height:40px; border-radius:50%;
    background:var(--surface-2); border:1px solid var(--border); color:var(--text-accent);
    display:flex; align-items:center; justify-content:center; cursor:pointer; font-size:17px;
    box-shadow:var(--shadow);
  }
  .theme-toggle:hover{border-color:var(--text-accent);}
  .theme-menu-dropdown{
    position:absolute; top:48px; left:0; min-width:180px;
    background:var(--surface-1); border:1px solid var(--border); border-radius:10px;
    box-shadow:var(--shadow); padding:6px; display:flex; flex-direction:column; gap:2px;
  }
  .theme-menu-item{
    display:flex; align-items:center; gap:8px; width:100%; text-align:right;
    padding:9px 12px; border-radius:7px; font-size:13px; font-family:inherit;
    color:var(--text-primary); text-decoration:none; background:none; border:none; cursor:pointer;
  }
  .theme-menu-item:hover{background:var(--surface-2);}
  .wrap{max-width:var(--maxw); margin:0 auto; padding:16px;}
  .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;}

  /* Top app bar */
  .appbar{
    display:flex; align-items:center; justify-content:space-between; gap:12px;
    padding:14px 4px 18px; flex-wrap:wrap;
  }
  .brand{display:flex; align-items:center; gap:10px;}
  .brand .mark{
    width:38px;height:38px;border-radius:10px;background:linear-gradient(135deg,#fbbf24,#b45309);
    display:flex;align-items:center;justify-content:center;font-weight:800;color:#151005;font-size:15px;
    box-shadow:0 4px 14px rgba(217,119,6,.35);
  }
  .brand h1{font-size:16px;font-weight:700;margin:0;}
  .brand p{font-size:11px;color:var(--text-secondary);margin:1px 0 0;}

  .live-pill{
    font-size:12px;color:var(--text-secondary);display:flex;align-items:center;gap:6px;
    background:var(--surface-2);padding:6px 12px;border-radius:20px;border:1px solid var(--border);
  }
  .live-dot{width:7px;height:7px;background:var(--text-success);border-radius:50%;display:inline-block;animation:pulse 2s infinite;}
  @keyframes pulse{
    0%{box-shadow:0 0 0 0 rgba(16,185,129,.6);} 70%{box-shadow:0 0 0 6px rgba(16,185,129,0);} 100%{box-shadow:0 0 0 0 rgba(16,185,129,0);}
  }

  /* Role switcher */
  .role-switch{
    display:flex; background:var(--surface-1); border:1px solid var(--border); border-radius:12px; padding:4px; gap:4px;
    margin-bottom:18px;
  }
  .role-btn{
    flex:1; background:transparent; border:none; color:var(--text-secondary); font-family:var(--font-sans);
    font-weight:700; font-size:13px; padding:10px 12px; border-radius:9px; cursor:pointer; display:flex; align-items:center; justify-content:center; gap:8px;
  }
  .role-btn.active{background:var(--surface-2); color:var(--text-accent); box-shadow:inset 0 0 0 1px var(--border);}
  .role-btn i{font-size:16px;}

  .panel{display:none;}
  .panel.active{display:block; animation:fadein .25s ease;}

  /* Developer dashboard sub-tabs */
  .dev-tab-nav{
    display:flex; flex-wrap:wrap; gap:6px; background:var(--surface-1); border:1px solid var(--border);
    border-radius:12px; padding:6px; margin-bottom:16px;
  }
  .dev-tab-btn{
    background:transparent; border:none; color:var(--text-secondary); font-family:var(--font-sans);
    font-weight:700; font-size:12px; padding:8px 12px; border-radius:8px; cursor:pointer;
    display:flex; align-items:center; gap:6px; white-space:nowrap;
  }
  .dev-tab-btn.active{background:var(--surface-2); color:var(--text-accent); box-shadow:inset 0 0 0 1px var(--border);}
  .dev-subpanel{display:none;}
  .dev-subpanel.active{display:block; animation:fadein .2s ease;}

  .alert-item{
    display:flex; align-items:flex-start; gap:10px; background:var(--surface-2); border:1px solid var(--border);
    border-radius:9px; padding:10px 12px; margin-bottom:8px;
  }
  .alert-item .icon{font-size:18px; flex-shrink:0;}
  .alert-item.sev-high .icon{color:var(--text-danger);}
  .alert-item.sev-med .icon{color:var(--text-warning);}
  .alert-item.sev-low .icon{color:var(--text-secondary);}

  .role-card{
    background:var(--surface-2); border:1px solid var(--border); border-radius:12px; padding:14px; margin-bottom:10px;
  }
  .role-card h3{font-size:13px; margin:0 0 6px; color:var(--text-accent);}
  .role-card p{font-size:12px; color:var(--text-secondary); margin:0;}

  /* Registration pending / success screen */
  #regPendingScreen{
    min-height:100vh; display:flex; align-items:center; justify-content:center; padding:16px;
  }
  .reg-pending-card{
    width:100%; max-width:460px; background:var(--surface-1); border:1px solid var(--border);
    border-radius:18px; padding:28px 24px; box-shadow:var(--shadow); text-align:center;
  }
  .reg-pending-icon{
    width:64px; height:64px; border-radius:50%; background:var(--bg-accent);
    display:flex; align-items:center; justify-content:center; margin:0 auto 18px;
    font-size:28px; color:var(--text-accent); border:2px solid rgba(251,191,36,.3);
  }
  .reg-pending-card h2{font-size:18px; font-weight:800; margin:0 0 10px;}
  .reg-pending-card p{font-size:13px; color:var(--text-secondary); line-height:1.7; margin:0 0 8px;}
  .reg-pending-meta{
    background:var(--surface-2); border:1px solid var(--border); border-radius:10px;
    padding:12px 14px; margin:16px 0; font-size:12px; color:var(--text-secondary); text-align:right;
  }
  .reg-pending-meta .row{display:flex; justify-content:space-between; gap:10px; margin-bottom:4px;}
  .reg-pending-meta .row:last-child{margin-bottom:0;}
  .reg-pending-steps{display:flex; flex-direction:column; gap:8px; margin:16px 0; text-align:right;}
  .reg-step{display:flex; align-items:center; gap:10px; font-size:12px; color:var(--text-secondary);}
  .reg-step .dot{width:22px; height:22px; border-radius:50%; background:var(--surface-2); border:1px solid var(--border); display:flex; align-items:center; justify-content:center; font-size:11px; font-weight:700; flex-shrink:0;}
  .reg-step.done .dot{background:var(--bg-success); color:var(--text-success); border-color:rgba(16,185,129,.4);}
  .reg-step.active .dot{background:var(--bg-warning); color:var(--text-warning); border-color:rgba(245,158,11,.4);}
  .pulse-ring{animation:pulse 2s infinite;}
  @keyframes fadein{from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:translateY(0);}}

  .card{
    background:var(--surface-1); border:1px solid var(--border); border-radius:16px; padding:18px;
    box-shadow:var(--shadow); margin-bottom:16px;
  }
  .card h2{font-size:14px; font-weight:700; margin:0 0 12px; color:var(--text-primary); display:flex; align-items:center; gap:8px;}
  .card h2 i{color:var(--text-accent); font-size:16px;}

  select, input{
    background:var(--surface-2); border:1px solid var(--border); color:var(--text-primary);
    padding:10px 14px; border-radius:8px; font-family:var(--font-sans); font-size:14px; outline:none; width:100%;
  }
  select:focus, input:focus{border-color:var(--primary); box-shadow:0 0 0 2px rgba(217,119,6,.2);}
  label.field{display:flex; flex-direction:column; gap:6px; font-size:12px; color:var(--text-secondary); font-weight:600;}

  button.primary{
    background:linear-gradient(135deg,var(--primary),#b45309); color:#fff; border:none; padding:12px;
    border-radius:9px; font-family:var(--font-sans); font-weight:700; font-size:14px; cursor:pointer;
    box-shadow:0 4px 12px rgba(217,119,6,.3); width:100%;
  }
  button.primary:hover{opacity:.95; transform:translateY(-1px);}
  button.primary:active{transform:translateY(0);}
  button.ghost{
    background:var(--surface-2); border:1px solid var(--border); color:var(--text-primary); font-family:var(--font-sans);
    font-weight:700; font-size:13px; padding:9px 12px; border-radius:8px; cursor:pointer;
  }
  button.ghost:hover{border-color:var(--text-accent); color:var(--text-accent);}
  button.accept{background:var(--bg-success); color:var(--text-success); border:1px solid rgba(16,185,129,.35); font-weight:700; font-family:var(--font-sans); padding:9px 12px; border-radius:8px; cursor:pointer; font-size:13px;}
  button.reject{background:var(--bg-danger); color:var(--text-danger); border:1px solid rgba(239,68,68,.35); font-weight:700; font-family:var(--font-sans); padding:9px 12px; border-radius:8px; cursor:pointer; font-size:13px;}

  .badge{padding:3px 9px; border-radius:6px; font-size:11px; font-weight:700; white-space:nowrap;}
  .badge-success{background:var(--bg-success); color:var(--text-success);}
  .badge-warning{background:var(--bg-warning); color:var(--text-warning);}
  .badge-danger{background:var(--bg-danger); color:var(--text-danger);}
  .badge-muted{background:var(--surface-3); color:var(--text-secondary);}

  .mono{font-family:var(--font-mono);}

  /* ملاحظة امتثال: تنبيه بضرورة مطابقة اسم صاحب الحساب المُحوِّل مع الجهة المسجّلة، بجانب كل حقل رفع إثبات حوالة */
  .transfer-name-note{
    display:flex; align-items:flex-start; gap:6px; font-size:11px; line-height:1.6;
    color:var(--text-warning); background:var(--bg-warning); border:1px solid rgba(245,158,11,.3);
    border-radius:7px; padding:7px 9px; margin:8px 0;
  }
  .transfer-name-note i{ font-size:14px; flex-shrink:0; margin-top:1px; }

  /* Responsive grids */
  .grid-3{display:grid; grid-template-columns:repeat(auto-fit, minmax(120px,1fr)); gap:10px;}
  .grid-2{display:grid; grid-template-columns:repeat(auto-fit, minmax(220px,1fr)); gap:12px;}
  .grid-form{display:grid; grid-template-columns:repeat(3,1fr); gap:10px;}
  @media (max-width:520px){ .grid-form{grid-template-columns:1fr 1fr;} .grid-form > *:nth-child(3){grid-column:span 2;} }

  .price-tile{background:var(--surface-2); border-radius:var(--radius); padding:10px 12px; border:1px solid var(--border); display:flex; align-items:baseline; gap:6px; flex-wrap:wrap; white-space:nowrap;}
  .price-tile .k{font-size:12px; color:var(--text-secondary); margin:0; font-weight:600; flex-shrink:0;}
  .price-tile .v{font-size:clamp(14px,3.4vw,17px); font-weight:800; margin:0;}
  .price-tile .d{font-size:11px; margin:0; font-weight:700; color:var(--text-secondary);}
  #shopSpotPricesGrid.grid-3, #supplierSpotPricesGrid.grid-3{grid-template-columns:repeat(auto-fit, minmax(190px,1fr));}

  .supplier-row{
    display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:14px;
    background:var(--surface-2); border-radius:var(--radius); padding:14px; border:1px solid var(--border);
  }
  .supplier-row .stock-center{display:flex; justify-content:center;}
  .supplier-row .prices{display:flex; justify-content:flex-end; gap:16px; font-size:13px; color:var(--text-secondary); font-weight:600;}
  .supplier-row .prices strong{color:var(--text-primary); font-size:18px; font-weight:800;}
  .badge-lg{font-size:14px; padding:7px 18px;}
  @media (max-width:640px){
    .supplier-row{grid-template-columns:1fr;}
    .supplier-row .stock-center{justify-content:flex-start;}
    .supplier-row .prices{justify-content:flex-start;}
  }

  .req-item{
    display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:10px;
    background:var(--surface-2); border:1px solid var(--border); border-radius:var(--radius); padding:12px 14px;
  }
  .req-item .meta{font-size:12px; color:var(--text-secondary);}
  .req-item .meta strong{color:var(--text-primary);}
  .req-actions{display:flex; gap:8px;}

  .stat-tile{background:var(--surface-2); border:1px solid var(--border); border-radius:var(--radius); padding:14px;}
  .stat-tile .lbl{font-size:11px; color:var(--text-secondary); font-weight:600; margin:0 0 6px;}
  .stat-tile .val{font-size:clamp(18px,4vw,22px); font-weight:800; margin:0;}

  .divider{border:none; border-top:1px dashed var(--border); margin:14px 0;}
  .empty{font-size:13px; color:var(--text-muted); text-align:center; padding:18px 0;}

  .stock-select-row{display:flex; align-items:center; gap:10px; justify-content:space-between; padding:8px 0;}
  .stock-select-row .name{font-size:13px; font-weight:700;}

  /* Small screens: stack row items */
  @media (max-width:420px){
    .req-item, .supplier-row{flex-direction:column; align-items:stretch;}
    .req-actions{width:100%;}
    .req-actions button{flex:1;}
  }
  @media (min-width:900px){
    .two-col{display:grid; grid-template-columns:1.1fr .9fr; gap:16px; align-items:start;}
  }
  ::selection{background:rgba(251,191,36,.3);}

  /* ---------------- Login screen ---------------- */
  #loginScreen{
    min-height:100vh; display:flex; align-items:center; justify-content:center; padding:16px;
  }
  .login-card{
    width:100%; max-width:440px; background:var(--surface-1); border:1px solid var(--border);
    border-radius:18px; padding:26px 22px; box-shadow:var(--shadow);
  }
  .login-card .mark{
    width:48px;height:48px;border-radius:12px;background:linear-gradient(135deg,#fbbf24,#b45309);
    display:flex;align-items:center;justify-content:center;font-weight:800;color:#151005;font-size:17px;
    margin:0 auto 14px; box-shadow:0 4px 14px rgba(217,119,6,.35);
  }
  .login-card h1{font-size:17px; font-weight:800; text-align:center; margin:0 0 4px;}
  .login-card p.sub{font-size:12px; color:var(--text-secondary); text-align:center; margin:0 0 18px;}

  .acct-type-switch{display:flex; gap:8px; background:var(--surface-2); border:1px solid var(--border); border-radius:11px; padding:4px; margin-bottom:18px;}
  .acct-type-opt{
    flex:1; display:flex; align-items:center; justify-content:center; gap:6px; cursor:pointer;
    font-size:13px; font-weight:700; color:var(--text-secondary); padding:9px 10px; border-radius:8px;
  }
  .acct-type-opt input{position:absolute; opacity:0; width:0; height:0;}
  .acct-type-opt.active{background:var(--surface-3); color:var(--text-accent); box-shadow:inset 0 0 0 1px var(--border);}

  .login-grid{display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:14px;}
  @media (max-width:480px){ .login-grid{grid-template-columns:1fr;} }
  .login-error{
    display:none; background:var(--bg-danger); color:var(--text-danger); border:1px solid rgba(239,68,68,.35);
    border-radius:8px; padding:9px 12px; font-size:12px; font-weight:600; margin-bottom:12px;
  }
  .login-foot{font-size:11px; color:var(--text-muted); text-align:center; margin-top:14px;}

  /* ---------------- Document upload section ---------------- */
  .upload-section{margin-bottom:16px;}
  .upload-title{font-size:12px; font-weight:700; color:var(--text-secondary); margin:0 0 8px; display:flex; align-items:center; gap:6px;}
  .upload-title i{color:var(--text-accent);}
  .upload-row{
    position:relative; display:flex; align-items:center; gap:10px; background:var(--surface-2);
    border:1px solid var(--border); border-radius:9px; padding:9px 10px; margin-bottom:8px; cursor:pointer;
  }
  .upload-row:hover{border-color:var(--text-accent);}
  .upload-row input[type="file"]{position:absolute; inset:0; opacity:0; cursor:pointer; padding:0;}
  .upload-icon{
    width:30px; height:30px; border-radius:8px; background:var(--bg-accent); color:var(--text-accent);
    display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size:14px;
  }
  .upload-text{display:flex; flex-direction:column; gap:2px; flex:1; min-width:0;}
  .upload-label{font-size:12px; font-weight:700; color:var(--text-primary);}
  .upload-filename{font-size:11px; color:var(--text-muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
  .upload-filename.chosen{color:var(--text-success);}
  .upload-btn{font-size:11px; font-weight:700; color:var(--text-accent); background:var(--surface-3); padding:5px 10px; border-radius:6px; flex-shrink:0;}

  .dev-login-link{margin-top:14px; padding-top:14px; border-top:1px solid var(--border);}
  .dev-login-link button{width:100%;}

  /* ---------------- Developer dashboard table ---------------- */
  .dev-table-wrap{overflow-x:auto; -webkit-overflow-scrolling:touch;}
  table.dev-table{width:100%; border-collapse:collapse; font-size:12.5px; min-width:640px;}
  table.dev-table th{
    text-align:right; color:var(--text-secondary); font-weight:700; font-size:11px; text-transform:uppercase;
    padding:8px 10px; border-bottom:1px solid var(--border); white-space:nowrap;
  }
  table.dev-table td{padding:9px 10px; border-bottom:1px solid var(--border-soft); white-space:nowrap;}
  table.dev-table tr:last-child td{border-bottom:none;}

  /* Doc preview modal */
  #docPreviewModal{
    display:none; position:fixed; inset:0; z-index:9000;
    background:rgba(0,0,0,.75); backdrop-filter:blur(4px);
    align-items:center; justify-content:center; padding:16px;
  }
  #docPreviewModal.open{ display:flex; }
  #aboutUsModal{
    display:none; position:fixed; inset:0; z-index:9000;
    background:rgba(0,0,0,.75); backdrop-filter:blur(4px);
    align-items:center; justify-content:center; padding:16px;
  }
  #aboutUsModal.open{ display:flex; }
  #productDetailModal{
    display:none; position:fixed; inset:0; z-index:9000;
    background:var(--bg-main); overflow-y:auto;
  }
  #productDetailModal.open{ display:block; }
  .doc-modal-inner{
    background:var(--surface-1); border:1px solid var(--border); border-radius:16px;
    max-width:800px; width:100%; max-height:90vh; overflow-y:auto;
    box-shadow:0 20px 60px rgba(0,0,0,.5); padding:20px;
  }
  .doc-modal-header{
    display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:16px;
  }
  .doc-modal-header h3{font-size:15px; font-weight:700; margin:0;}
  .doc-modal-close{
    background:var(--surface-2); border:1px solid var(--border); color:var(--text-secondary);
    width:30px; height:30px; border-radius:8px; cursor:pointer; font-size:16px;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
  }
  .doc-modal-close:hover{ color:var(--text-primary); }
  .doc-modal-img{ width:100%; border-radius:10px; display:block; }
  .doc-modal-pdf-note{
    font-size:12px; color:var(--text-secondary); background:var(--surface-2);
    border:1px solid var(--border); border-radius:8px; padding:14px; text-align:center;
  }
  .doc-preview-thumb{
    display:inline-flex; align-items:center; gap:5px; background:var(--bg-accent);
    border:1px solid rgba(251,191,36,.3); color:var(--text-accent); border-radius:7px;
    padding:4px 8px; font-size:11px; font-weight:700; cursor:pointer; margin:3px;
  }
  .doc-preview-thumb:hover{ background:rgba(251,191,36,.2); }
  .filter-row{display:flex; gap:10px; flex-wrap:wrap; align-items:flex-end; margin-bottom:12px;}
  .filter-row label.field{min-width:150px; flex:1;}
  .user-chip{display:flex; align-items:center; gap:8px;}
  .user-chip .dot{width:8px;height:8px;border-radius:50%;}

  .mode-btn.active-mode{background:var(--surface-3); color:var(--text-accent); box-shadow:inset 0 0 0 1px var(--text-accent);}

  /* Materials market page (سوق الخامات — صفحة كاملة عامة على /Market) */
  .market-tab-btn.active-mode{background:var(--surface-3); color:var(--text-accent); box-shadow:inset 0 0 0 1px var(--text-accent);}
  .market-cat-chip{
    padding:6px 14px; border-radius:20px; font-size:12px; font-weight:700; cursor:pointer;
    background:var(--surface-2); border:1px solid var(--border); color:var(--text-secondary);
  }
  .market-cat-chip.active-mode{background:var(--bg-accent); color:var(--text-accent); border-color:var(--text-accent);}

  /* مجموعة اختيار عيارات/ألوان متعددة (checkboxes) لمنتجات سوق الخامات */
  .checkbox-row{ display:flex; gap:8px; flex-wrap:wrap; }
  .checkbox-chip{
    display:flex; align-items:center; gap:5px; padding:6px 12px; border-radius:20px;
    font-size:12px; font-weight:700; cursor:pointer; background:var(--surface-2);
    border:1px solid var(--border); color:var(--text-secondary); user-select:none;
  }
  .checkbox-chip input{ accent-color:var(--text-accent); cursor:pointer; margin:0; }
  .checkbox-chip:has(input:checked){ background:var(--bg-accent); color:var(--text-accent); border-color:var(--text-accent); }
  .market-product-card{
    background:var(--surface-2); border:1px solid var(--border); border-radius:12px;
    overflow:hidden; display:flex; flex-direction:column;
  }
  .market-product-img{width:100%; aspect-ratio:1/1; object-fit:cover; background:var(--surface-3); display:block;}
  .market-product-body{padding:12px; display:flex; flex-direction:column; gap:6px; flex:1;}
  .market-product-body .title{font-weight:700; font-size:13.5px; margin:0;}
  .market-product-body .meta{font-size:11.5px; color:var(--text-secondary); margin:0;}

  /* تذييل سوق الخامات */
  .market-footer{ margin-top:28px; padding-top:24px; border-top:1px solid var(--border-soft); }
  .market-footer-cols{ display:flex; flex-wrap:wrap; gap:28px; justify-content:space-between; }
  .market-footer-col{ min-width:150px; flex:1; }
  .market-footer-col h4{ font-size:13px; font-weight:700; margin:0 0 12px; color:var(--text-primary); }
  .market-footer-col a{
    display:block; font-size:12.5px; color:var(--text-secondary); text-decoration:none;
    cursor:pointer; margin-bottom:9px; width:fit-content;
  }
  .market-footer-col a:hover{ color:var(--text-accent); }
  .market-footer-col-social{ min-width:170px; }
  .market-footer-social{ display:flex; gap:8px; margin-bottom:14px; }
  .market-footer-social a{
    width:34px; height:34px; border-radius:50%; background:var(--surface-2); border:1px solid var(--border);
    display:flex; align-items:center; justify-content:center; color:var(--text-secondary); font-size:16px;
    transition:color .15s, border-color .15s;
  }
  .market-footer-social a:hover{ color:var(--text-accent); border-color:var(--text-accent); }
  .market-footer-legal{ font-size:11px; color:var(--text-muted); margin:0; line-height:1.7; }

  /* شاشة تفاصيل المنتج في سوق الخامات (نافذة موسّعة على هيئة صفحة منتج) */
  .product-detail-inner{
    background:var(--surface-1); max-width:1180px; width:100%; min-height:100vh;
    margin:0 auto; padding-top:20px; position:relative;
  }
  .product-detail-close{
    position:absolute; top:24px; left:24px; z-index:2;
    background:var(--surface-2); border:1px solid var(--border); color:var(--text-secondary);
    width:32px; height:32px; border-radius:8px; cursor:pointer; font-size:16px;
    display:flex; align-items:center; justify-content:center;
  }
  .product-detail-close:hover{ color:var(--text-primary); }
  .product-detail-breadcrumb{
    font-size:12px; color:var(--text-muted); margin:0; padding:18px 24px 0;
  }
  .product-detail-breadcrumb a{ color:var(--text-secondary); cursor:pointer; }
  .product-detail-breadcrumb a:hover{ color:var(--text-accent); }
  .product-detail-grid{
    display:grid; grid-template-columns:1fr 1fr; column-gap:28px; row-gap:20px; padding:18px 24px 24px;
    grid-template-areas:
      "gallery info"
      "specs   info";
    align-items:start;
  }
  @media (max-width:760px){
    .product-detail-grid{
      grid-template-columns:1fr;
      grid-template-areas:
        "gallery"
        "info"
        "specs";
    }
    .product-detail-gallery{ flex-direction:column-reverse !important; align-items:stretch !important; }
    .product-detail-thumbs{ flex-direction:row !important; flex-wrap:wrap; }
  }
  .product-detail-gallery{ grid-area:gallery; display:flex; flex-direction:row; align-items:flex-start; gap:10px; min-width:0; }
  .product-detail-main-img{
    flex:1; min-width:0; aspect-ratio:1/1; object-fit:cover; border-radius:12px;
    background:var(--surface-3); border:1px solid var(--border);
  }
  .product-detail-thumbs{ display:flex; flex-direction:column; gap:8px; flex-shrink:0; }
  .product-detail-thumbs img{
    width:64px; height:64px; object-fit:cover; border-radius:8px; cursor:pointer;
    border:1px solid var(--border); transition:border-color .15s;
  }
  .product-detail-thumbs img:hover, .product-detail-thumbs img.active-thumb{ border-color:var(--text-accent); }
  .product-detail-info{ grid-area:info; display:flex; flex-direction:column; min-width:0; }
  .product-detail-info h2{ font-size:19px; font-weight:800; margin:0 0 4px; }
  .product-detail-subtitle{ font-size:12px; color:var(--text-muted); margin:0 0 8px; }
  .product-detail-price{ font-size:26px; font-weight:800; color:var(--text-accent); margin:0 0 14px; }
  .product-detail-meta-box{
    background:var(--surface-2); border:1px solid var(--border); border-radius:10px;
    padding:10px 12px; font-size:12.5px; color:var(--text-secondary); margin:0 0 14px;
    display:flex; flex-direction:column; gap:4px;
  }
  .product-detail-total-box{
    background:var(--bg-accent); border:1px solid rgba(251,191,36,.3); border-radius:10px;
    padding:10px 12px; margin:10px 0 12px;
  }
  .product-detail-total-box p{ margin:0; }
  .product-detail-buy-btn{ font-size:14px; padding:12px; }
  .product-detail-trust-row{
    display:flex; flex-wrap:wrap; gap:14px; margin-top:16px; padding-top:14px;
    border-top:1px dashed var(--border-soft);
  }
  .product-detail-trust-item{
    display:flex; align-items:center; gap:6px; font-size:11.5px; color:var(--text-secondary);
  }
  .product-detail-trust-item i{ font-size:16px; color:var(--text-accent); }
  .product-detail-specs{
    grid-area:specs; border-top:1px solid var(--border-soft); padding-top:14px;
  }
  .product-detail-specs h3{ font-size:14px; font-weight:700; margin:0 0 10px; }
  .product-detail-specs-list{ list-style:none; margin:0 0 12px; padding:0; display:flex; flex-direction:column; gap:7px; }
  .product-detail-specs-list li{
    font-size:12.5px; color:var(--text-secondary); display:flex; gap:6px; padding-bottom:7px;
    border-bottom:1px dashed var(--border-soft);
  }
  .product-detail-specs-list li strong{ color:var(--text-primary); font-weight:700; }
  .product-detail-description{ font-size:12.5px; color:var(--text-secondary); line-height:1.7; margin:0; }

  /* زر واتساب العائم (سوق الخامات، شاشة المحل، شاشة المورد) */
  #whatsappFloatBtn{
    position:fixed; bottom:90px; right:24px; z-index:9500;
    width:56px; height:56px; border-radius:50%; background:#25d366;
    display:flex; align-items:center; justify-content:center;
    color:#fff; font-size:28px; box-shadow:0 6px 20px rgba(37,211,102,.5);
    animation:whatsapp-pulse 2.2s infinite;
  }
  #whatsappFloatBtn:hover{ background:#20bd5a; }
  @keyframes whatsapp-pulse{
    0%{ box-shadow:0 6px 20px rgba(37,211,102,.5), 0 0 0 0 rgba(37,211,102,.55); }
    70%{ box-shadow:0 6px 20px rgba(37,211,102,.5), 0 0 0 14px rgba(37,211,102,0); }
    100%{ box-shadow:0 6px 20px rgba(37,211,102,.5), 0 0 0 0 rgba(37,211,102,0); }
  }
  @media (max-width:640px){
    #whatsappFloatBtn{ width:48px; height:48px; font-size:24px; bottom:70px; right:16px; }
  }

  /* شريط تقدّم رفع الصور العائم */
  .upload-progress-toast{
    position:fixed; bottom:24px; left:50%; transform:translateX(-50%) translateY(120%);
    z-index:9999; width:min(340px, calc(100vw - 32px));
    background:var(--surface-1); border:1px solid var(--border); border-radius:12px;
    padding:12px 14px; box-shadow:0 10px 30px rgba(0,0,0,.25);
    opacity:0; transition:transform .25s ease, opacity .25s ease;
    pointer-events:none;
  }
  .upload-progress-toast.show{ transform:translateX(-50%) translateY(0); opacity:1; }
  .upload-progress-row{ display:flex; align-items:center; gap:8px; margin-bottom:8px; }
  .upload-progress-row i{ color:var(--text-accent); font-size:16px; }
  .upload-progress-label{ font-size:12.5px; font-weight:700; color:var(--text-primary); flex:1; }
  .upload-progress-percent{ font-size:12px; font-weight:700; color:var(--text-accent); }
  .upload-progress-track{ height:7px; border-radius:4px; background:var(--surface-3); overflow:hidden; }
  .upload-progress-fill{ height:100%; background:var(--text-accent); border-radius:4px; width:0%; transition:width .15s ease; }
  .upload-progress-eta{ font-size:11px; color:var(--text-secondary); margin-top:6px; min-height:14px; }

  /* invoice / journal document styling */
  .doc-box{background:var(--surface-2); border:1px solid var(--border); border-radius:10px; padding:14px;}
  .doc-row{display:flex; justify-content:space-between; gap:10px; font-size:12.5px; padding:5px 0; border-bottom:1px dashed var(--border-soft);}
  .doc-row:last-child{border-bottom:none;}
  .doc-row .lbl{color:var(--text-secondary);}
  .doc-actions{display:flex; gap:8px; margin-top:12px; flex-wrap:wrap;}
  .doc-actions button{flex:1; min-width:110px;}
  .doc-input{width:100px; text-align:left;}
  .doc-badge-approved{background:var(--bg-success); color:var(--text-success); padding:3px 10px; border-radius:6px; font-size:11px; font-weight:700;}
  .doc-badge-draft{background:var(--bg-warning); color:var(--text-warning); padding:3px 10px; border-radius:6px; font-size:11px; font-weight:700;}

  /* print mechanism: only #printArea is shown when printing */
  #printArea{display:none;}
  @media print{
    /* ملاحظة: تعمّدنا عدم استخدام position:absolute هنا لأنها تُنتج صفحة فارغة أو محتوى مقصوصًا
       عند الطباعة من متصفحات الجوال (خاصة Safari على iOS)، إذ لا يُحتسب ارتفاع العنصر المُموضَع
       بشكل مطلق ضمن ارتفاع الصفحة المطبوعة. تركه ضمن التدفق الطبيعي للمستند يحل المشكلة على كل الأجهزة. */
    html, body{height:auto !important; min-height:0 !important; overflow:visible !important;}
    body.print-mode > *:not(#printArea){display:none !important;}
    #printArea{
      display:block !important; width:100%;
      background:#fff; color:#111; font-family:Arial, sans-serif; padding:24px; direction:rtl;
    }
    #printArea table{width:100%; border-collapse:collapse; margin-top:10px;}
    #printArea td, #printArea th{border:1px solid #999; padding:6px 8px; font-size:12px; text-align:right;}
    #printArea h1{font-size:17px; margin:0 0 4px;}
    #printArea h2{font-size:14px; margin:16px 0 6px;}

    /* قالب فاتورة ضريبية مبسطة موحّد لفواتير الشراء والبيع */
    .tax-inv-header{display:flex; justify-content:space-between; align-items:flex-start; gap:16px; border-bottom:2px solid #8a5a1e; padding-bottom:10px; margin-bottom:10px;}
    .tax-inv-company p{margin:2px 0; font-size:12px;}
    .tax-inv-company p:first-child{font-size:14px; font-weight:700; margin-bottom:4px;}
    .tax-inv-qr-box{width:100px; height:100px; border:1px solid #999; display:flex; align-items:center; justify-content:center; font-size:9px; color:#999; text-align:center; flex-shrink:0;}
    .tax-inv-banner{background:#8a5a1e; color:#fff; text-align:center; padding:7px; font-weight:700; font-size:13.5px; margin-bottom:6px; border-radius:2px;}
    .tax-inv-banner span{display:block; font-size:10.5px; font-weight:400; margin-top:2px;}
    .tax-inv-meta{display:flex; justify-content:space-between; gap:16px; margin:14px 0; font-size:12px; border:1px solid #999; padding:10px 12px;}
    .tax-inv-meta-col p{margin:3px 0;}
    .tax-inv-table{width:100%; border-collapse:collapse; margin-bottom:14px;}
    .tax-inv-table th, .tax-inv-table td{border:1px solid #999; padding:6px 8px; font-size:11px; text-align:center;}
    .tax-inv-table th{background:#f1ede4;}
    .tax-inv-totals{width:100%; font-size:12.5px; border:1px solid #999; border-bottom:none;}
    .tax-inv-totals-row{display:flex; justify-content:space-between; padding:6px 10px; border-bottom:1px solid #999;}
    .tax-inv-totals-final{font-weight:700; background:#f1ede4;}

    /* قالب كشف حساب الذهب المطبوع */
    .ledger-doc-header{border-bottom:2px solid #8a5a1e; padding-bottom:10px; margin-bottom:10px;}
    .ledger-doc-header p{margin:2px 0; font-size:12px;}
    .ledger-doc-header p:first-child{font-size:14px; font-weight:700; margin-bottom:4px;}
    .ledger-doc-banner{background:#8a5a1e; color:#fff; text-align:center; padding:7px; font-weight:700; font-size:13.5px; margin-bottom:10px; border-radius:2px;}
    .ledger-doc-banner span{display:block; font-size:10.5px; font-weight:400; margin-top:2px;}
    .ledger-doc-meta{display:flex; justify-content:space-between; gap:16px; margin-bottom:12px; font-size:12px; border:1px solid #999; padding:10px 12px;}
    .ledger-doc-table{width:100%; border-collapse:collapse; margin-bottom:14px;}
    .ledger-doc-table th, .ledger-doc-table td{border:1px solid #999; padding:6px 8px; font-size:11px; text-align:center;}
    .ledger-doc-table th{background:#f1ede4;}
    .ledger-doc-table td.desc-cell{text-align:right;}
    .ledger-doc-total-row td{background:#f1ede4; font-weight:700;}
    .ledger-doc-final{display:flex; justify-content:space-between; padding:8px 12px; border:1px solid #999; background:#f1ede4; font-weight:700; font-size:13px; margin-bottom:16px;}
    .ledger-doc-subtitle{font-weight:700; font-size:13px; margin:16px 0 6px;}
  }
